ocaml-protoc icon indicating copy to clipboard operation
ocaml-protoc copied to clipboard

Overriding individual printers

Open ELLIOTTCABLE opened this issue 2 years ago • 1 comments

I'm using this via ocaml-opentelemetry; but when dumping, this unhelpfully prints Bytes types as opaque blob:

send spans { scope_spans =
               [{ scope =
                    ...
                  spans =
                    [{ trace_id = <bytes len=16>;
                       span_id = <bytes len=8>;
                       trace_state = "";
                       parent_span_id = <bytes len=8>;
                       name = "alloc";
                       ...
           }

What's the least fragile way to replace the printer for spans..trace_id et al. with one that prints the ID as hexadecimal, instead of treating it as opaque? (Or, perhaps, that should perhaps be the default for short-ish Bytes?)

ELLIOTTCABLE avatar Jun 13 '23 23:06 ELLIOTTCABLE

Sounds like a good idea. I'd say, by default, small bytes should be printed in hex, and large bytes should be like "deadbeef[...2415151 more bytes]". This should probably be configured at the level of the code generator (with an option to control if ellipsis occurs, and after how many bytes).

c-cube avatar Jun 14 '23 15:06 c-cube