Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proto: ignore unknown fields in map entries #561

Merged
merged 1 commit into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions proto/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,36 @@ package proto_test

import (
"fmt"
"reflect"
"testing"

"github.com/golang/protobuf/proto"
ppb "github.com/golang/protobuf/proto/proto3_proto"
)

func TestMap(t *testing.T) {
var b []byte
fmt.Sscanf("a2010c0a044b657931120456616c31a201130a044b657932120556616c3261120456616c32a201240a044b6579330d05000000120556616c33621a0556616c3361120456616c331505000000a20100a201260a044b657934130a07536f6d6555524c1209536f6d655469746c651a08536e69707065743114", "%x", &b)

var m ppb.Message
if err := proto.Unmarshal(b, &m); err != nil {
t.Fatalf("proto.Unmarshal error: %v", err)
}

got := m.StringMap
want := map[string]string{
"": "",
"Key1": "Val1",
"Key2": "Val2",
"Key3": "Val3",
"Key4": "",
}

if !reflect.DeepEqual(got, want) {
t.Errorf("maps differ:\ngot %#v\nwant %#v", got, want)
}
}

func marshalled() []byte {
m := &ppb.IntMaps{}
for i := 0; i < 1000; i++ {
Expand Down
124 changes: 68 additions & 56 deletions proto/proto3_proto/proto3.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions proto/proto3_proto/proto3.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ message Message {

Message submessage = 17;
repeated Message children = 18;

map<string, string> string_map = 20;
}

message Nested {
Expand Down
Loading