7e9e3e43
json: M.encode(desc, t, opts) for use_proto_names / emit_defaults / indent
Canonical protojson options were silently ignored. Plumb a single opts
table through encode_message via a CURRENT_ENCODE_OPTS state (mirroring
the decode-side CURRENT_OPTS):
* use_proto_names — emit snake_case field names (proto wire
names) instead of the spec-default
lowerCamelCase.
* emit_defaults — emit zero-valued implicit-presence scalars,
(alias: always_emit_zero_value) empty repeated lists, and empty
maps. Explicit-presence fields (optional /
oneof) and singular message fields remain
absent — matches protobuf-go's behavior.
* indent — pretty-print with the given indent string;
empty arrays/objects stay compact.
Tests parameterize over both codegen modes (descriptor-table contract is
shared between full and runtime) plus a dedicated parity group that
asserts byte-identical JSON across modes for each option.
Eugene Blikh <bigbes@gmail.com> — 2026-05-17 03:36:17 UTC
Commit 7e9e3e43ae121408deeb9a55e6cef220215c37d2 —
view raw patch
Parent(s):
06b2978a
| File | Status | + | − |
|---|---|---|---|
runtime/pb/json.lua
|
M | +125 | -6 |
test/json_test.lua
|
M | +145 |