Add "FromIP" helper for addresses
[govpp.git] / binapi / vpe_types / vpe_types.ba.go
index 6a93afd..779cbdb 100644 (file)
@@ -1,7 +1,8 @@
 // Code generated by GoVPP's binapi-generator. DO NOT EDIT.
 // versions:
 //  binapi-generator: v0.4.0-dev
-//  VPP:              20.05-release
+//  VPP:              21.06-release
+// source: /usr/share/vpp/api/core/vpe_types.api.json
 
 // Package vpe_types contains generated bindings for API file vpe_types.api.
 //
@@ -14,6 +15,7 @@ package vpe_types
 
 import (
        "strconv"
+       "time"
 
        api "git.fd.io/govpp.git/api"
 )
@@ -78,6 +80,37 @@ type Timedelta float64
 // Timestamp defines alias 'timestamp'.
 type Timestamp float64
 
+func NewTimestamp(t time.Time) Timestamp {
+       sec := int64(t.Unix())
+       nsec := int32(t.Nanosecond())
+       ns := float64(sec) + float64(nsec/1e9)
+       return Timestamp(ns)
+}
+
+func (x Timestamp) ToTime() time.Time {
+       ns := int64(x * 1e9)
+       sec := ns / 1e9
+       nsec := ns % 1e9
+       return time.Unix(sec, nsec)
+}
+
+func (x Timestamp) String() string {
+       return x.ToTime().String()
+}
+
+func (x *Timestamp) MarshalText() ([]byte, error) {
+       return []byte(x.ToTime().Format(time.RFC3339Nano)), nil
+}
+
+func (x *Timestamp) UnmarshalText(text []byte) error {
+       t, err := time.Parse(time.RFC3339Nano, string(text))
+       if err != nil {
+               return err
+       }
+       *x = NewTimestamp(t)
+       return nil
+}
+
 // Version defines type 'version'.
 type Version struct {
        Major         uint32 `binapi:"u32,name=major" json:"major,omitempty"`