ocaml-protoc
ocaml-protoc copied to clipboard
Incorrect generated encoder/decoder for empty message in RPC endpoints
With a simple .proto file like this:
syntax = "proto3";
message Empty {}
service Test {
rpc Ping (Empty) returns (Empty);
}
the generated .ml file contains these functions for the Empty
message:
let rec encode_pb_empty (v:empty) encoder =
()
let rec decode_pb_empty d =
match Pbrt.Decoder.key d with
| None -> ();
| Some (_, pk) ->
Pbrt.Decoder.unexpected_payload "Unexpected fields in empty message(empty)" pk
however, the encoder/decoder functions for the Ping
endpoint in the Server
and Client
modules are incorrectly(?) defined as
fun () enc -> Pbrt.Encoder.empty_nested enc
fun d -> Pbrt.Decoder.empty_nested d
which produce an error when given a value encoded/decoded with the functions for the empty message type:
# let e = Pbrt.Encoder.create ();;
val e : Pbrt.Encoder.t = <abstr>
# encode_pb_empty () e;;
- : empty = ()
# let b = Pbrt.Encoder.to_bytes e;;
val b : bytes = Bytes.of_string ""
# Pbrt.Decoder.of_bytes b |> Pbrt.Decoder.empty_nested;;
Exception: Pbrt.Decoder.Failure(Incomplete)