mransan/ocaml-protoc

omit fields set to their default value in encoding?

Opened this issue · 0 comments

When encoding a value, it seems like it's wasteful to write a field whose value is the default one. That's especially true if there's many such fields.

Alternatively, could we even encode, not from a datatype (Foo_types.bar), but from its smart constructor? As in, why build a value of type Foo_types.bar just to encode it immediately, when we can have val write_bar : ?x:int -> ?y:bool -> ?z:string -> encoder -> unit. That should make it more clear which fields are set or not.

edit: of course I forget, but a cool aspect of writing directly from the function, is that one could potentially replace lists by _ Seq.t so they're generated on demand.