Support JSON
https://protobuf.dev/programming-guides/proto3/#json
To add JSON support, I think we would want to generate two more functions for each message named MyMessage.
putJsonMyMessage :: MyMessage -> StringparseJsonMyMessage :: parseJsonMyMessage :: forall m. Monad m => ParserT String m MyMessage
I'm really not sure about those types, but that's approximately what we would want. Probably we would want to depend on argonaut-core or json and use their types.
To be able to generate those two functions, we would need to:
- Write a JSON version of
Encode - Write a JSON version of
Decode - Write a JSON version of
genFieldPutnamedgenFieldPutJsonand add it to the generated code here. - Write a JSON version of
genFieldParsernamedgenFieldParseJsonand add it to the generated code here. - Write a JSON version of
Runtime - Write a
putJsonmessage-name code generator here. - Write a
parseJsonmessage-name code generator here.
To turn on conformance tests for JSON:
This reply function needs a case for proto3 JSON:
https://github.com/rowtype-yoga/purescript-protobuf/blob/48ba4bcdfba9a113ccd9ed152bf4d84e25a98ffe/conformance/src/Main.purs#L67
So add a pattern matching case like:
reply (ConformanceRequest
{ requested_output_format: Just C.WireFormat_JSON -- for JSON
, message_type: _
, test_category: Just C.TestCategory_JSON_Test -- for JSON
This is some spec:
https://protobuf.dev/programming-guides/json/