Bug: field-name associated with dynamic size field will mismatch actual field-name when encoding uses `def`
The description of the encoding of an obj1
(or obj2
, etc.) with a named field whose encoding would require a dynamic size field to precede it will under certain conditions ignore the actual name of the field, and instead impute a different name if the encoding of the field is wrapped in a def
combinator (may be reproducible under other conditions as well):
Example: (See !50 )
open Data_encoding
let print e =
let desc =
Data_encoding.(
Json.(
to_string
(construct Binary_schema.encoding (Binary.describe e))))
in
print_endline desc;
print_newline ();
flush_all ()
let bugged_encoding = def "actual_name" string
let encoding = obj1 (req "expected_name" bugged_encoding)
let () =
print encoding
produces
{ "toplevel":
{ "fields":
[ { "kind": "dyn", "name": "actual_name", "num_fields": 1,
"size": "Uint30" },
{ "name": "expected_name", "layout": { "kind": "String" },
"data_kind": { "kind": "Variable" }, "kind": "named" } ] },
"fields": [] }
In which the field name "actual_name"
is used for the dynamic size-field, rather than "expected_name"
, which is what it ought to produce.