Use the zero value when decoding a map element that is missing its key or value.
Signed-off-by: David Symonds <dsymonds@golang.org>
diff --git a/proto/decode.go b/proto/decode.go
index 5810782..f94b9f4 100644
--- a/proto/decode.go
+++ b/proto/decode.go
@@ -768,10 +768,11 @@
}
}
keyelem, valelem := keyptr.Elem(), valptr.Elem()
- if !keyelem.IsValid() || !valelem.IsValid() {
- // We did not decode the key or the value in the map entry.
- // Either way, it's an invalid map entry.
- return fmt.Errorf("proto: bad map data: missing key/val")
+ if !keyelem.IsValid() {
+ keyelem = reflect.Zero(p.mtype.Key())
+ }
+ if !valelem.IsValid() {
+ valelem = reflect.Zero(p.mtype.Elem())
}
v.SetMapIndex(keyelem, valelem)