Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Optional field with default is encoded even if the value is the default value #131

@prashantv

Description

@prashantv

When an optional field with a default is read, the struct is expected to have the default value set. However, when reencoding this struct, the field should not be sent over the wire as it is the default value. In the following example, a bool field has a default value of true, and is not set in the input payload, but when the payload is deserialized and serialized again, the resulting payload contains the bool set to true.

Thrift struct:

struct BoolTest {
  1: optional bool b = true;
  2: optional string s = "true";
}

Doing a roundtrip of binary -> struct -> binary modifies the following payload:

TStruct({2: TBinary([])})

to the following:

TStruct({1: TBool(true), 2: TBinary([])})

The binary for the input payload is:

> hexdump node_bool_encode.bin
0000000 0b 00 02 00 00 00 00 00
0000008

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions