Skip to main content

TupleOutput

Struct TupleOutput 

Source
pub struct TupleOutput { /* private fields */ }
Expand description

A writer for tuple-encoded byte data.

Writes primitive values to a growable byte buffer using the same encoding formats as TupleOutput. Signed integers use big-endian with the sign bit flipped for sortable ordering. Floats use IEEE 754 with bit manipulation for sortable ordering.

Implementations§

Source§

impl TupleOutput

Source

pub fn new() -> Self

Creates a new empty TupleOutput.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new TupleOutput with the given initial capacity.

Source

pub fn to_vec(&self) -> Vec<u8>

Returns the written bytes as a vector.

Source

pub fn into_vec(self) -> Vec<u8>

Consumes self and returns the written bytes.

Source

pub fn len(&self) -> usize

Returns the current length of written data.

Source

pub fn is_empty(&self) -> bool

Returns true if no data has been written.

Source

pub fn to_database_entry(&self) -> DatabaseEntry

Converts the written data to a DatabaseEntry.

Source

pub fn as_bytes(&self) -> &[u8]

Returns a reference to the internal buffer.

Source

pub fn write_bool(&mut self, val: bool)

Writes a boolean (one byte) value. True is stored as 1, false as 0.

Values can be read using TupleInput::read_bool.

Source

pub fn write_u8(&mut self, val: u8)

Writes an unsigned byte value directly.

Values can be read using TupleInput::read_u8.

Source

pub fn write_i8(&mut self, val: i8)

Writes a signed byte value with sign bit flipped for sort order.

Values can be read using TupleInput::read_i8.

Source

pub fn write_u16(&mut self, val: u16)

Writes an unsigned short (two byte, big-endian) value.

Values can be read using TupleInput::read_u16.

Source

pub fn write_i16(&mut self, val: i16)

Writes a signed short (two byte) value with sign bit flipped for sort order.

Values can be read using TupleInput::read_i16.

Source

pub fn write_u32(&mut self, val: u32)

Writes an unsigned int (four byte, big-endian) value.

Values can be read using TupleInput::read_u32.

Source

pub fn write_i32(&mut self, val: i32)

Writes a signed int (four byte) value with sign bit flipped for sort order.

Values can be read using TupleInput::read_i32.

Source

pub fn write_u64(&mut self, val: u64)

Writes an unsigned long (eight byte, big-endian) value.

Values can be read using TupleInput::read_u64.

Source

pub fn write_i64(&mut self, val: i64)

Writes a signed long (eight byte) value with sign bit flipped for sort order.

Values can be read using TupleInput::read_i64.

Source

pub fn write_float(&mut self, val: f32)

Writes an unsorted float (four byte) value as raw IEEE 754 big-endian bits.

This does NOT produce sortable byte ordering. Use write_sorted_float for keys that need to sort correctly.

Values can be read using TupleInput::read_float.

Source

pub fn write_double(&mut self, val: f64)

Writes an unsorted double (eight byte) value as raw IEEE 754 big-endian bits.

This does NOT produce sortable byte ordering. Use write_sorted_double for keys that need to sort correctly.

Values can be read using TupleInput::read_double.

Source

pub fn write_sorted_float(&mut self, val: f32)

Writes a sorted float (four byte) value using sign-bit manipulation.

The encoding ensures that the byte representation sorts in the same order as the float values:

  • If negative (sign bit set): XOR all bits
  • If positive (sign bit clear): XOR only the sign bit

Values can be read using TupleInput::read_sorted_float.

Source

pub fn write_sorted_double(&mut self, val: f64)

Writes a sorted double (eight byte) value using sign-bit manipulation.

The encoding ensures that the byte representation sorts in the same order as the double values:

  • If negative (sign bit set): XOR all bits
  • If positive (sign bit clear): XOR only the sign bit

Values can be read using TupleInput::read_sorted_double.

Source

pub fn write_packed_int(&mut self, value: i32)

Writes a packed (variable-length) i32 value.

Values in [-119, 119] are stored in a single byte. Larger values use 2-5 bytes with the first byte encoding the sign and byte count.

This is an unsorted encoding - it is compact but the byte representation does NOT sort in the same order as the integer values.

Values can be read using TupleInput::read_packed_int.

Source

pub fn write_packed_long(&mut self, value: i64)

Writes a packed (variable-length) i64 value.

Values in [-119, 119] are stored in a single byte. Larger values use 2-9 bytes with the first byte encoding the sign and byte count.

This is an unsorted encoding - it is compact but the byte representation does NOT sort in the same order as the integer values.

Values can be read using TupleInput::read_packed_long.

Source

pub fn write_string(&mut self, val: &str)

Writes a null-escaped UTF-8 string using null-byte escape format.

Each 0x00 byte in the string is escaped as the two-byte sequence [0x00, 0x01], and the string is terminated with [0x00, 0x00]. This allows strings containing embedded null bytes to round-trip correctly and preserves lexicographic sort order.

Values can be read using TupleInput::read_string.

Source

pub fn write_bytes(&mut self, data: &[u8])

Writes raw bytes to the buffer without any framing.

The caller must know the length when reading back.

Values can be read using TupleInput::read_bytes.

Source

pub fn write_sorted_packed_int(&mut self, val: i32)

Writes a sorted packed (variable-length, order-preserving) i32 value.

Values in [-119, 120] are stored in a single byte as (value + 127). Larger positive values use 2-5 bytes with first byte 0xF7 + N. Smaller negative values use 2-5 bytes with first byte 0x08 - N.

The byte representation sorts in the same order as the integer values, making this suitable for database keys. This is distinct from write_packed_int, which is compact but NOT sortable.

/ TupleOutput.writeSortedPackedInt().

Values can be read using TupleInput::read_sorted_packed_int.

Source

pub fn write_sorted_packed_long(&mut self, val: i64)

Writes a sorted packed (variable-length, order-preserving) i64 value.

Values in [-119, 120] are stored in a single byte as (value + 127). Larger positive values use 2-9 bytes with first byte 0xF7 + N. Smaller negative values use 2-9 bytes with first byte 0x08 - N.

The byte representation sorts in the same order as the integer values, making this suitable for database keys. This is distinct from write_packed_long, which is compact but NOT sortable.

/ TupleOutput.writeSortedPackedLong().

Values can be read using TupleInput::read_sorted_packed_long.

Source

pub fn write_char(&mut self, val: u16)

Writes a Java char (16-bit Unicode code point) as two big-endian bytes.

The encoding is identical to an unsigned big-endian u16: the high byte first, then the low byte. This matches Java’s DataOutputStream.writeChar.

Values can be read using TupleInput::read_char.

Source

pub fn reset(&mut self)

Resets the output, clearing all written data.

Trait Implementations§

Source§

impl Clone for TupleOutput

Source§

fn clone(&self) -> TupleOutput

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TupleOutput

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TupleOutput

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.