aboutsummaryrefslogtreecommitdiff
path: root/vendor/go.opencensus.io/tag/map_codec.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/go.opencensus.io/tag/map_codec.go')
-rw-r--r--vendor/go.opencensus.io/tag/map_codec.go31
1 files changed, 22 insertions, 9 deletions
diff --git a/vendor/go.opencensus.io/tag/map_codec.go b/vendor/go.opencensus.io/tag/map_codec.go
index 33be1f0..3e99895 100644
--- a/vendor/go.opencensus.io/tag/map_codec.go
+++ b/vendor/go.opencensus.io/tag/map_codec.go
@@ -177,45 +177,58 @@ func Encode(m *Map) []byte {
// Decode decodes the given []byte into a tag map.
func Decode(bytes []byte) (*Map, error) {
ts := newMap()
+ err := DecodeEach(bytes, ts.upsert)
+ if err != nil {
+ // no partial failures
+ return nil, err
+ }
+ return ts, nil
+}
+// DecodeEach decodes the given serialized tag map, calling handler for each
+// tag key and value decoded.
+func DecodeEach(bytes []byte, fn func(key Key, val string)) error {
eg := &encoderGRPC{
buf: bytes,
}
if len(eg.buf) == 0 {
- return ts, nil
+ return nil
}
version := eg.readByte()
if version > tagsVersionID {
- return nil, fmt.Errorf("cannot decode: unsupported version: %q; supports only up to: %q", version, tagsVersionID)
+ return fmt.Errorf("cannot decode: unsupported version: %q; supports only up to: %q", version, tagsVersionID)
}
for !eg.readEnded() {
typ := keyType(eg.readByte())
if typ != keyTypeString {
- return nil, fmt.Errorf("cannot decode: invalid key type: %q", typ)
+ return fmt.Errorf("cannot decode: invalid key type: %q", typ)
}
k, err := eg.readBytesWithVarintLen()
if err != nil {
- return nil, err
+ return err
}
v, err := eg.readBytesWithVarintLen()
if err != nil {
- return nil, err
+ return err
}
key, err := NewKey(string(k))
if err != nil {
- return nil, err // no partial failures
+ return err
}
val := string(v)
if !checkValue(val) {
- return nil, errInvalidValue // no partial failures
+ return errInvalidValue
+ }
+ fn(key, val)
+ if err != nil {
+ return err
}
- ts.upsert(key, val)
}
- return ts, nil
+ return nil
}