thrift_runtime_record (thrift_runtime v0.7.0)
View SourceRepresentation engine: converts struct values between the wire representation (maps keyed by binary field names) and the in-process representations — driven purely by type descriptors.
A struct descriptor's {ref, Module, Name} target declares its
representation through Module:record_fields(Name):
{Tag, [FieldAtoms]}— tuple records;Tagand the field atoms are the definitions generated into<mod>_types.erl;{map, KeyType}— maps withKeyType(atom|binary) keys, theerl.struct_type = "map"representation;{sum, [FieldAtoms]}— sum unions (erl.union_type = "sum"):{FieldAtom, Value}tagged tuples, exactly one variant by construction;none, or norecord_fieldsexport at all — hand-written descriptors: values pass through unchanged, assumed already wire.
Input values are auto-detected in to_wire/2: a native record (EEP-79,
OTP 29+, see thrift_runtime_native), a tuple record, a plain map with
atom keys (the generated record field atoms), a plain map with binary
keys (already the wire shape) or an Elixir-style tagged map
(#{__struct__ => Tag, ...}) all normalize to the wire map.
from_wire/2 produces the struct's default representation;
from_wire/3 produces the requested one (see thrift_runtime:repr/0).
Field atoms are only ever taken from generated definitions or minted from IDL-controlled field names — never from wire data.
A struct value that matches no representation (neither the declared
record tag nor a map) raises value_does_not_match_type; the facade
turns it into the tagged {error, {value_does_not_match_type, Value}}
the codecs answer with.
Summary
Functions
Converts wire call arguments to the handler representation.
Converts call arguments to wire representation, in order.
Converts a call result to the handler representation.
Converts a wire value to the struct's default representation.
Converts a wire value to the given representation.
The fallback identity tag for a struct whose definition declares no
record tag of its own: the snake-cased wire name (__struct__ tags
of map-mode structs, hand-written descriptor targets).
The representation of a struct descriptor's values: record for
tuple records, {map, KeyType} for map-representation structs, sum
for tagged-tuple unions, {native, Tag} for native-record structs,
wire when values pass through unchanged (inline descriptors and
hand-written modules without record_fields/1).
Converts a handler result to wire representation.
Converts any representation (record, atom- or binary-keyed map, struct-map) to the wire representation.
Types
-type call_result() :: thrift_runtime_client:call_result().
-type exception_field() :: field_desc().
-type field_desc() :: thrift_runtime_binary:field_desc().
-type struct_desc() :: thrift_runtime_binary:struct_desc().
-type type_desc() :: thrift_runtime_binary:type_desc().
Functions
-spec args_from_wire({struct, struct_desc()}, [term()]) -> [term()].
Converts wire call arguments to the handler representation.
-spec args_to_wire({struct, struct_desc()}, [term()]) -> [term()].
Converts call arguments to wire representation, in order.
-spec call_result_from_wire(type_desc() | undefined, [exception_field()], call_result()) -> term().
Converts a call result to the handler representation.
CallResult is what thrift_runtime_client:call/4 returned. Declared
exceptions answer {error, {exception, Value}}: the value's
representation — record tag, __struct__ map or native record —
identifies the exception.
Converts a wire value to the struct's default representation.
-spec from_wire(type_desc(), term(), thrift_runtime:repr()) -> term().
Converts a wire value to the given representation.
The fallback identity tag for a struct whose definition declares no
record tag of its own: the snake-cased wire name (__struct__ tags
of map-mode structs, hand-written descriptor targets).
-spec repr_mode(type_desc()) -> record | {map, atom | binary} | {native, atom} | sum | wire.
The representation of a struct descriptor's values: record for
tuple records, {map, KeyType} for map-representation structs, sum
for tagged-tuple unions, {native, Tag} for native-record structs,
wire when values pass through unchanged (inline descriptors and
hand-written modules without record_fields/1).
-spec result_to_wire(type_desc() | undefined, [exception_field()], term()) -> term().
Converts a handler result to wire representation.
Result is {ok, Value}, {error, {exception, Value}} — the declared
exception identified by its representation tag — or
{error, {exception, Name, Value}} with an explicit wire name (the
form hand-written descriptors and map-representation exceptions need);
anything else passes through.
Converts any representation (record, atom- or binary-keyed map, struct-map) to the wire representation.