mransan / ocaml-protoc

A Protobuf Compiler for OCaml
https://mransan.github.io/ocaml-protoc/
MIT License
179 stars 33 forks source link

Crash compiling Yojson use of empty messages #160

Closed vphantom closed 1 year ago

vphantom commented 2 years ago

Hi! Thank you for your work. :smile: When compiling the use of an empty message, i.e.:

message Empty {}  // This line is fine
message Test {
  Empty empty = 1;  // This crashes
}

…I get a crash in Yojson mode:

$ ocaml-protoc -binary -yojson -ml_out . test.proto
Generating ./test_types.mli
Generating ./test_types.ml
File "src/compilerlib/pb_codegen_decode_yojson.ml", line 31, characters 18-24: Assertion failed

Indeed, that's https://github.com/mransan/ocaml-protoc/blob/master/src/compilerlib/pb_codegen_decode_yojson.ml#L31

I know that the JSON representation should be an empty object (i.e. `Assoc []) but not to the point of knowing how to contribute this. 😕

Lupus commented 1 year ago

message Empty {} also seems to omit the type from generated files with types, so support for empty protobuf messages is not really present in the library...

c-cube commented 1 year ago

If I remember correctly, such empty messages become unit when compiled. For json it's probably a bug, and a PR would be very helpful.

Lupus commented 1 year ago

I believe https://github.com/mransan/ocaml-protoc/pull/198 should address this issue.