-
Notifications
You must be signed in to change notification settings - Fork 11
Description
We have some protobuf messages that contain fields of type map<string, bytes>. Both protobufjs and proto3-json-serializer's fromProto3JSON appears to work properly with those fields.
However, passing such messages through toProto3JSON results in incorrect behaviors while handling the bytes value.
- In proto3-json-serializer v2.0.0, there is no error, but the Buffer object is passed unmodified to the output object;
- In proto3-json-serializer v2.0.2, I get the following error message:
Error: toProto3JSON: don't know how to convert value my_buffer_content
at convertSingleValue (/.../node_modules/proto3-json-serializer/typescript/src/toproto3json.ts:50:11)
at toProto3JSON (/.../node_modules/proto3-json-serializer/typescript/src/toproto3json.ts:149:13)
at /.../node_modules/proto3-json-serializer/typescript/src/toproto3json.ts:137:22
at Array.map (<anonymous>)
at toProto3JSON (/.../node_modules/proto3-json-serializer/typescript/src/toproto3json.ts:134:27)
... truncated ...
The bytes values are Buffer objects. I would expect toProto3JSON to convert them to base64-encoded strings, just like it does for a simple bytes field.
I haven't tested, but from looking at the code, I believe that repeated bytes likely suffer from the same incorrect behavior.
Environment details
- Node.js version: 20.17.0
- npm version: 10.8.2
proto3-json-serializerversion: 2.0.0 - 2.0.2
Steps to reproduce
-
Start with the official proto3-json-serializer repo's main branch;
-
In
test-fixture/proto/test.proto, modify the messageMessageWithMapto:message MessageWithMap { map<string, MapValue> map_field = 3; map<string, string> string_map_field = 4; map<string, int64> long_map_field = 5; + map<string, bytes> bytes_map_field = 6; } -
In
typescript/test/unit/map.ts, add this to bothmessageandjson:'minus one': '-1', zero: '0', }, + bytesMapField: { + key1: 'dmFsdWUgMQo=', + key2: 'dmFsdWUgMgo=', + }, }; -
Run tests:
npm test -
Observe test failure