thrifty/zigzag

Types

Error type returned by checked ZigZag encoders when a value exceeds the allowed range.

pub type ZigzagRangeError {
  ZigzagRangeError(value: Int, bits: Int)
}

Constructors

  • ZigzagRangeError(value: Int, bits: Int)

Values

pub fn decode_i32(z: Int) -> Int

Decode a ZigZag-encoded unsigned integer back to signed i32.

Inputs

  • z: ZigZag-encoded unsigned integer.

Outputs

  • Returns the decoded signed integer.
pub fn decode_i64(z: Int) -> Int

Decode a ZigZag-encoded unsigned integer back to signed i64.

Inputs

  • z: ZigZag-encoded unsigned integer.

Outputs

  • Returns the decoded signed integer.
pub fn encode_i32(n: Int) -> Int

Encode a signed 32-bit integer into an unsigned integer using ZigZag.

Inputs

  • n: signed integer expected to fit in 32-bit signed range.

Outputs

  • Returns the ZigZag-encoded unsigned integer.

Error modes

  • Panics when n is outside the supported i32 range. Use encode_i32_checked/1 to receive an explicit error instead of panicking.
pub fn encode_i32_checked(
  n: Int,
) -> Result(Int, ZigzagRangeError)

Checked version of encode_i32/1 returning an explicit error for out-of-range inputs.

Inputs

  • n: signed integer to encode.

Outputs

  • Ok(Int) with the ZigZag-encoded unsigned integer when n fits in i32.
  • Error(ZigzagRangeError) when n is outside the i32 representable range.
pub fn encode_i64(n: Int) -> Int

Encode a signed 64-bit integer into an unsigned integer using ZigZag.

Inputs

  • n: signed integer expected to fit in 64-bit signed range.

Outputs

  • Returns the ZigZag-encoded unsigned integer.

Error modes

  • Panics when n is outside the supported i64 range. Use encode_i64_checked/1 to receive an explicit error instead of panicking.
pub fn encode_i64_checked(
  n: Int,
) -> Result(Int, ZigzagRangeError)

Checked version of encode_i64/1 returning an explicit error for out-of-range inputs.

Inputs

  • n: signed integer to encode.

Outputs

  • Ok(Int) with the ZigZag-encoded unsigned integer when n fits in i64.
  • Error(ZigzagRangeError) when n is outside the i64 representable range.
Search Document