How to translate the following C++ serialization code to golang equivalent

38 views
Skip to first unread message

Chan Lewis

unread,
Jul 17, 2020, 5:05:20 AM7/17/20
to Protocol Buffers
Let's say I have a message:

```
message Meta {
  string a = 1;
  int64 b= 2;
}
```

Somebody serializes the message with C++ like this:

```cpp
Meta meta;

char header_and_meta[meta_size];
::google::protobuf::io::ArrayOutputStream arr_out(header_and_meta, meta_size);
::google::protobuf::io::CodedOutputStream coded_out(&arr_out);
meta.SerializeWithCachedSizes(&coded_out);
 ```

Now I need to translate above code to golang equivalent code, but I don't see equivalent struct in golang. I use proto.Marshal(meta), but the result of type []byte, is not totally same as data within header_and_meta

Anything wrong ?

Chan Lewis

unread,
Jul 20, 2020, 2:57:59 AM7/20/20
to Protocol Buffers
It turns out that the output bytes for proto3 are different from those for proto2. I fix it now.
Reply all
Reply to author
Forward
0 new messages