|
| 1 | +From c4660f5f1a5c38902c374f002174848aff2f1739 Sat Aug 18 00:00:00 2018 |
| 2 | +From: Jipanyang < [email protected]> |
| 3 | +Date: Sat, 18 Aug 2018 00:00:00 +0000 |
| 4 | +Subject: [PATCH] Used local gnmi client update to avoid json (value.ToScalar()) parsing issue |
| 5 | + |
| 6 | +--- |
| 7 | + vendor/github.com/openconfig/gnmi/client/gnmi/client.go | 13 +++- |
| 8 | + vendor/github.com/openconfig/gnmi/value/value.go | 2 + |
| 9 | + 2 files changed, 49 insertions(+), 2 deletions(-) |
| 10 | + |
| 11 | +diff --git a/vendor/github.com/openconfig/gnmi/client/gnmi/client.go b/vendor/github.com/openconfig/gnmi/client/gnmi/client.go |
| 12 | +index 81a8704..ca0a383 100644 |
| 13 | +--- a/vendor/github.com//openconfig/gnmi/client/gnmi/client.go 2018-8-17 14:03:29.839103602 -0800 |
| 14 | ++++ b/vendor/github.com//openconfig/gnmi/client/gnmi/client.go 2018-8-18 13:48:49.226145599 -0700 |
| 15 | +@@ -37,7 +37,6 @@ |
| 16 | + "github.com/openconfig/gnmi/client" |
| 17 | + "github.com/openconfig/gnmi/client/grpcutil" |
| 18 | + "github.com/openconfig/gnmi/path" |
| 19 | +- "github.com/openconfig/gnmi/value" |
| 20 | + |
| 21 | + gpb "github.com/openconfig/gnmi/proto/gnmi" |
| 22 | + ) |
| 23 | +@@ -257,11 +256,58 @@ |
| 24 | + if err != nil { |
| 25 | + return nil, fmt.Errorf("invalid query path %q: %v", qq, err) |
| 26 | + } |
| 27 | + s.Subscribe.Subscription = append(s.Subscribe.Subscription, &gpb.Subscription{Path: pp, Mode: q.Streaming_type, SampleInterval: q.Streaming_sample_int, HeartbeatInterval: q.Heartbeat_int, SuppressRedundant: q.Suppress_redundant}) |
| 28 | + } |
| 29 | + return &gpb.SubscribeRequest{Request: s}, nil |
| 30 | + } |
| 31 | + |
| 32 | ++// decimalToFloat converts a *gnmi_proto.Decimal64 to a float32. Downcasting to float32 is performed as the |
| 33 | ++// precision of a float64 is not required. |
| 34 | ++func decimalToFloat(d *gpb.Decimal64) float32 { |
| 35 | ++ return float32(float64(d.Digits) / math.Pow(10, float64(d.Precision))) |
| 36 | ++} |
| 37 | ++ |
| 38 | ++// ToScalar will convert TypedValue scalar types to a Go native type. It will |
| 39 | ++// return an error if the TypedValue does not contain a scalar type. |
| 40 | ++func toScalar(tv *gpb.TypedValue) (interface{}, error) { |
| 41 | ++ var i interface{} |
| 42 | ++ switch tv.Value.(type) { |
| 43 | ++ case *gpb.TypedValue_DecimalVal: |
| 44 | ++ i = decimalToFloat(tv.GetDecimalVal()) |
| 45 | ++ case *gpb.TypedValue_StringVal: |
| 46 | ++ i = tv.GetStringVal() |
| 47 | ++ case *gpb.TypedValue_IntVal: |
| 48 | ++ i = tv.GetIntVal() |
| 49 | ++ case *gpb.TypedValue_UintVal: |
| 50 | ++ i = tv.GetUintVal() |
| 51 | ++ case *gpb.TypedValue_BoolVal: |
| 52 | ++ i = tv.GetBoolVal() |
| 53 | ++ case *gpb.TypedValue_FloatVal: |
| 54 | ++ i = tv.GetFloatVal() |
| 55 | ++ case *gpb.TypedValue_LeaflistVal: |
| 56 | ++ elems := tv.GetLeaflistVal().GetElement() |
| 57 | ++ ss := make([]interface{}, len(elems)) |
| 58 | ++ for x, e := range elems { |
| 59 | ++ v, err := toScalar(e) |
| 60 | ++ if err != nil { |
| 61 | ++ return nil, fmt.Errorf("ToScalar for ScalarArray %+v: %v", e.Value, err) |
| 62 | ++ } |
| 63 | ++ ss[x] = v |
| 64 | ++ } |
| 65 | ++ i = ss |
| 66 | ++ case *gpb.TypedValue_BytesVal: |
| 67 | ++ i = tv.GetBytesVal() |
| 68 | ++ case *gpb.TypedValue_JsonIetfVal: |
| 69 | ++ var val interface{} |
| 70 | ++ val = tv.GetJsonIetfVal() |
| 71 | ++ json.Unmarshal(val.([]byte), &i) |
| 72 | ++ //i = tv.GetJsonIetfVal() |
| 73 | ++ default: |
| 74 | ++ return nil, fmt.Errorf("non-scalar type %+v", tv.Value) |
| 75 | ++ } |
| 76 | ++ return i, nil |
| 77 | ++} |
| 78 | ++ |
| 79 | + func noti(prefix []string, pp *gpb.Path, ts time.Time, u *gpb.Update) (client.Notification, error) { |
| 80 | + sp := path.ToStrings(pp, false) |
| 81 | + // Make a full new copy of prefix + u.Path to avoid any reuse of underlying |
| 82 | +@@ -274,7 +320,7 @@ |
| 83 | + return client.Delete{Path: p, TS: ts}, nil |
| 84 | + } |
| 85 | + if u.Val != nil { |
| 86 | +- val, err := value.ToScalar(u.Val) |
| 87 | ++ val, err := toScalar(u.Val) |
| 88 | + if err != nil { |
| 89 | + return nil, err |
| 90 | + } |
| 91 | + |
| 92 | +diff --git a/vendor/github.com/openconfig/gnmi/value/value.go b/vendor/github.com/openconfig/gnmi/value/value.go |
| 93 | +index e851a4b..6e79264 100644 |
| 94 | +--- a/vendor/github.com/openconfig/gnmi/value/value.go 2018-8-17 14:03:29.847103498 -0800 |
| 95 | ++++ b/vendor/github.com/openconfig/gnmi/value/value.go 2018-8-18 13:48:49.234145530 -0700 |
| 96 | +@@ -117,6 +117,8 @@ |
| 97 | + i = ss |
| 98 | + case *pb.TypedValue_BytesVal: |
| 99 | + i = tv.GetBytesVal() |
| 100 | ++ case *pb.TypedValue_JsonIetfVal: |
| 101 | ++ i = string(tv.GetJsonIetfVal()) |
| 102 | + default: |
| 103 | + return nil, fmt.Errorf("non-scalar type %+v", tv.Value) |
| 104 | + } |
0 commit comments