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

proto3 map empty bytes #20

Closed
awalterschulze opened this issue Mar 16, 2015 · 1 comment
Closed

proto3 map empty bytes #20

awalterschulze opened this issue Mar 16, 2015 · 1 comment
Assignees

Comments

@awalterschulze
Copy link

Add this to proto3.proto in proto/proto3_proto

message MessageWithMappy {
  map<bool, bytes> byte_mapping = 3;
}

and run the Makefile in proto/proto3_proto

Then add this to size_test.go

{"map field with zero bytes", &proto3pb.MessageWithMappy{
        ByteMapping: map[bool][]byte{
            false: []byte{},
            true:  []byte{0x84, 0x78, 0x8e, 0x33, 0xcd, 0x12, 0x65, 0xa0, 0xd2, 0xca, 0xc4, 0xcd, 0x12, 0xe2, 0xcf, 0xf1, 0xbf, 0xfa, 0xf7, 0x5a, 0x3c, 0x6d, 0xdc, 0xcf, 0x9c, 0x92, 0x94, 0x3f, 0x4f, 0xb6, 0x31, 0x77, 0xe3, 0xda, 0x3f, 0x1b, 0x8e, 0x39, 0xe6, 0xa, 0x81, 0x61, 0xf0, 0xba, 0x74, 0x6},
        },
    }},

This gives the following failure

size_test.go:138: map field with zero bytes: Size(byte_mapping:<key:false value:"" > byte_mapping:<key:true value:"\204x\2163\315\022e\240\322\312\304\315\022\342\317\361\277\372\367Z<m\334\317\234\222\224?O\2661w\343\332?\033\2169\346\n\201a\360\272t\006" > ) = 56, want 7
size_test.go:139: map field with zero bytes: bytes: []byte{0x1a, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0}

The error only happens with an empty byte slice.

This is probably a mistake in the way the map values try to reuse the setEncAndDec function with a combination of the proto3 syntax

case reflect.Uint8:
            p.enc = (*Buffer).enc_slice_byte
            p.dec = (*Buffer).dec_slice_byte
            p.size = size_slice_byte
            if p.proto3 {
                p.enc = (*Buffer).enc_proto3_slice_byte
                p.size = size_proto3_slice_byte
            }

Maybe this should be

case reflect.Uint8:
            p.enc = (*Buffer).enc_slice_byte
            p.dec = (*Buffer).dec_slice_byte
            p.size = size_slice_byte
            if p.proto3 && notamapvalue {
                p.enc = (*Buffer).enc_proto3_slice_byte
                p.size = size_proto3_slice_byte
            }
@awalterschulze
Copy link
Author

This seems to work

case reflect.Uint8:
            p.enc = (*Buffer).enc_slice_byte
            p.dec = (*Buffer).dec_slice_byte
            p.size = size_slice_byte
            if p.proto3 && f != nil {
                p.enc = (*Buffer).enc_proto3_slice_byte
                p.size = size_proto3_slice_byte
            }

@dsymonds dsymonds self-assigned this Mar 19, 2015
@golang golang locked as resolved and limited conversation to collaborators Jun 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants