thrifty
Values
pub fn default_reader_options() -> types.ReaderOptions
Return the default types.ReaderOptions used by convenience constructors.
Outputs
- A
types.ReaderOptionsrecord populated with conservative defaults for maximum recursion depth, maximum container items, maximum string length, and the boolean element policy. These defaults are chosen to be safe for typical server workloads but can be overridden withwith_optionsfor more restrictive or permissive policies.
pub fn from_bit_array(data: BitArray) -> types.Reader
Construct a reader from a low-level BitArray containing a compact-encoded Thrift payload.
Inputs
data: theBitArraywhich contains the bytes of a compact-encoded Thrift message. The function does not copydata; the returned reader references it immutably.
Outputs
- Returns a
types.Readerpositioned at the start ofdatasuitable for subsequentread_*operations.
Error modes / guarantees
- This constructor does not perform parsing or validation beyond creating
the reader. Errors from malformed payloads appear when read operations
are invoked (for example
read_i32orread_string).
pub fn main() -> Nil
Convenience top-level API for small projects that import thrifty
This module exposes a tiny, curated surface so consumers that import
thrifty have quick access to common reader/writer helpers without
importing internal submodules. For advanced usage prefer importing
thrifty/reader or thrifty/writer directly.
CLI entry used for quick manual checks during development.
This module is primarily a library: consumers should import thrifty
and use the provided helpers (for example from_bit_array,
with_options, new_struct_writer). The main here is a small,
non-invasive convenience that prints a short message when the package
is run directly. It is intentionally minimal and not a replacement for
a proper CLI or integration in a production project.
pub fn new_struct_writer() -> writer_highlevel.StructWriter
Create a new high-level struct writer for building compact-encoded Thrift messages.
Outputs
- Returns a
high_writer.StructWriterinitially empty. The writer exposes composable helpers to append fields and then produce a compact-encodedBitArray.
Semantics
- The high-level writer is intended for small-to-medium sized payloads and convenience usage. For maximum performance consider using a lower-level writer if micro-optimizations are required.
pub fn read_bool_element(
r: types.Reader,
) -> Result(#(Bool, types.Reader), types.DecodeError)
Read a boolean value when encoded as a field element in the compact protocol.
Background
- In Thrift Compact, boolean fields may be encoded either inline in the
field header (canonical) or as a separate byte depending on the writer
and field position. The reader’s behavior may be controlled by the
bool_element_policyoption intypes.ReaderOptions.
Inputs
r: thetypes.Readerpositioned at a boolean field.
Outputs
- Returns
Ok((value, reader'))with the booleanvalueand an advanced reader on success. - Returns
Error(types.DecodeError)for malformed encodings or when the reader policy rejects non-canonical boolean encodings if the policy requires canonical-only booleans.
pub fn read_i32(
r: types.Reader,
) -> Result(#(Int, types.Reader), types.DecodeError)
Read a 32-bit signed integer encoded with Thrift compact varint/zigzag encoding.
Inputs
r: atypes.Readerpositioned at an integer field.
Outputs
- On success returns
Ok((value, reader'))wherevalueis the decoded integer andreader'is the reader advanced past the integer encoding. - On failure returns
Error(types.DecodeError), typically for truncated varint encodings or if the encoded value would cause an overflow.
pub fn read_string(
r: types.Reader,
) -> Result(#(String, types.Reader), types.DecodeError)
Read a compact-encoded string from the provided reader.
Inputs
r: thetypes.Readerpositioned at the start of a string field.
Outputs
- On success returns
Ok((value, reader'))wherevalueis the decoded UTF-8 string andreader'is the reader advanced past the string bytes. - On failure returns
Error(types.DecodeError)describing the problem (for example truncated data, invalid UTF-8, or exceeding configuredmax_string_bytes).
pub fn skip_value(
r: types.Reader,
t: types.FieldType,
) -> Result(types.Reader, types.DecodeError)
Skip over a value of the specified Thrift FieldType.
Inputs
r: thetypes.Readerpositioned at the start of a value.t: thetypes.FieldTypedescribing the encoded type to skip.
Outputs
- Returns
Ok(reader')withreader'advanced past the encoded value on success. - Returns
Error(types.DecodeError)when the encoded value is truncated, when a container exceeds configured limits, or on other decoding errors.
Notes
- This helper is useful when the caller is only interested in selected fields and wants to ignore others while still enforcing resource bounds.
pub fn with_options(
data: BitArray,
options: types.ReaderOptions,
) -> types.Reader
Construct a reader with explicit runtime limits and decoding options.
Inputs
data: theBitArraycontaining the compact-encoded payload.options: atypes.ReaderOptionsrecord controlling limits such as maximum container items, maximum recursion depth, maximum string bytes, and the boolean element policy.
Outputs
- Returns a
types.Readerconfigured with the providedoptions.
Semantics and safety
- Options are enforced during subsequent read operations; when a limit is
exceeded the reader will return a
types.DecodeErrorrather than crash. - Use this constructor when parsing untrusted data or when you need to enforce resource bounds in library consumers.