Skip to content

pxf: write an Any as a body only when the body gives back the same bytes (protowire#501) #168

Open

Description

@bfrancojr

trendvidia/protowire#501 (decided by the owner): a PXF encoder must write an Any as a type entry and body only when decoding that body gives exactly the stored value bytes. Otherwise it writes type_url and value. How it checks is the port's choice, and writing every Any raw conforms. Draft -01 § Any Blocks.

Why. A reader compares an Any by its bytes. A body that decodes to other bytes changes the message with no error. protowire-go's encoder changed 159,728 of 300,000 fuzzed Any values before protowire-go#232.

Cases that differ (measured on protowire-go): unknown fields at any level, field or map order, explicitly written zeros, a Timestamp no literal holds, and an unset @default or @required field. A chain of Anys past MaxNestingDepth should also come out raw rather than unreadable.

Not measured in this port, in either tier.

Done when: a test writes an Any holding each case above and reads the PXF back to the same value bytes.

Activity

  1. bfrancojr commented on Nov 3, 2026

    @bfrancojr
    CollaboratorAuthor

    Duplicate of #150 (filed earlier, same rule). This one adds the spec's wording from trendvidia/protowire#516. Either can be kept.

  2. bfrancojr commented on Nov 3, 2026

    @bfrancojr
    CollaboratorAuthor

    Status, 2026-11-03.

    Full tier: done-when met. AnyBodyReadBackTest (from #151, which fixed #150) writes an Any for each case listed here and reads the PXF back, with both decoders, to the same message:

    • unknown fields at the top, in a submessage, a list element, a wrapper and a Timestamp;
    • fields out of order and a map out of order;
    • an explicit zero, a long varint, an unpacked list and a repeated singular field;
    • a Timestamp past year 9999;
    • an unset @default and an unset @required field.

    aChainStopsAtTheDepthLimit and aChainPastTheLimitIsNotWalked cover a chain of Anys past MaxNestingDepth. #174 adds a test that an Any whose body would go past the limit stays as type_url and value.

    Lite tier: can't be tested yet. The lite tier has no type resolver, so it writes every Any raw, which the rule allows. But I tried to add a lite test, and a lite schema with a google.protobuf.Any field does not compile: the plugin references com.google.protobuf.AnyPxfMeta, which is never generated. Filed as trendvidia/protowire#539.

    Leaving this open until #539 lets the lite test run. Or close it as a duplicate of #150 if you'd rather track the lite half on #539 alone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions