Closed kjvalencik closed 3 weeks ago
This is not as simple as it may seem. A simple message serializes as expected with JSON.stringify, but bytes
(Uint8Array), int64
(BigInt) and several other types and constructs do not. To serialize or parse between the Protobuf JSON format and the generated class, schema information is required.
Protobuf-ES V2 supports JSON types. They match the Protobuf JSON format, which allows us to potentially provide clients that accept and return these JSON types, and do not require schema information.
In the upcoming version 2 of Connect-ES (see release candidate here), we are updating the Connect packages to support Protobuf-ES version 2, but we do not decouple from the Protobuf JSON and binary formats yet (more details in https://github.com/connectrpc/connect-es/issues/1233#issuecomment-2355138379).
I'm closing this to consolidate in #1030. Thanks for the issue!
Thanks for the quick reply! That makes perfect sense that it would need a pass to recursively transform all the typed arrays (plus any serialized i64
). It would still end up being much simpler without all of the varint
machinery, etc., but definitely not trivial! It makes sense to close in favor of that issue.
Thanks for the information on the RC. Cheers!
Is your feature request related to a problem? Please describe.
I would like a smaller package when not using protobuf serialization.
Both the
ConnectRPC
protocol andgrpc-web
(application/grpc-web+json
) support JSON encoding as an alternative to protobuf. In these schemes, most of the protobuf logic is not necessary. These libraries take up a significant portion of a package (67% of the 55kb in this example).Describe the solution you'd like
I would like to rely solely on
JSON.parse
andJSON.stringify
and eliminate protobuf from the dependency tree. Unfortunately, theprotobuf
package is scattered around the tree. This would likely require changes to the generated code.While this is relevant to both Node and Web client implementations, it is more important for web.
Describe alternatives you've considered
I have tried various tree shaking and deadcode elimination techniques but have not had much success. Snipping code (i.e., replacing with stubs) is effective but cumbersome and prone to regressions.
Additional context
This is very similar--and possibly identical--to https://github.com/connectrpc/connect-es/issues/1030.
Thanks!