Class BigEndian

extends ByteOrder
Support for big endian byte order.
Reuse an instance for multiple accesses or use the singleton LITTLE-ENDIAN to avoid multiple unnecessary object allocations.

Class summary


read-int buffer/ByteArray size-in-bytes/int offset/int -> int
See super.
read-uint buffer/ByteArray size-in-bytes/int offset/int -> int
See super.
put-uint buffer/ByteArray size-in-bytes/int offset/int value/int -> none
See super.
operator == other/any -> bool
Whether this object is equal to the other.
stringify -> string
Stringifies this object.
uint8 buffer/ByteArray offset/int -> int
Reads an unsigned 8-bit integer from the buffer at the offset.
int8 buffer/ByteArray offset/int -> int
Reads an 8-bit integer from the buffer at the offset.
put-int8 buffer/ByteArray offset/int value/int -> none
Writes the value to the buffer at the offset.
put-uint8 buffer/ByteArray offset/int value/int -> none
Writes the value to the buffer at the offset.
uint16 buffer/ByteArray offset/int -> int
Reads a 16-bit unsigned integer from the buffer at the offset.
int16 buffer/ByteArray offset/int -> int
Reads a 16-bit signed integer from the buffer at the offset.
put-int16 buffer/ByteArray offset/int i16/int -> none
Writes the i16 to the buffer at the offset.
put-uint16 buffer/ByteArray offset/int u16/int -> none
Writes the u16 to the buffer at the offset.
uint24 buffer/ByteArray offset/int -> int
Reads a 24-bit unsigned integer from the buffer at the offset.
int24 buffer/ByteArray offset/int -> int
Reads a 24-bit signed integer from the buffer at the offset.
put-int24 buffer/ByteArray offset/int i24/int -> none
Writes the i24 to the buffer at the offset.
put-uint24 buffer/ByteArray offset/int u24/int -> none
Writes the u24 to the buffer at the offset.
uint32 buffer/ByteArray offset/int -> int
Reads a 32-bit unsigned integer from the buffer at the offset.
int32 buffer/ByteArray offset/int -> int
Reads a 32-bit signed integer from the buffer at the offset.
put-int32 buffer/ByteArray offset/int i32/int -> none
Writes the i32 to the buffer at the offset.
put-uint32 buffer/ByteArray offset/int u32/int -> none
Writes the u32 to the buffer at the offset.
int64 buffer/ByteArray offset/int -> int
Reads a 64-bit signed integer from the buffer at the offset.
put-int64 buffer/ByteArray offset/int i64/int -> none
Writes the i64 to the buffer at the offset.
float64 buffer/ByteArray offset/int -> float
Reads a 64-bit floating point number from the buffer at the offset.
put-float64 buffer/ByteArray offset/int f64/float -> none
Writes the f64 to the buffer at the offset.
float32 buffer/ByteArray offset/int -> float
Reads a 32-bit floating point number from the buffer at the offset.
put-float32 buffer/ByteArray offset/int f32/float -> none
Writes the f32 to the buffer at the offset.

Methods

float32 buffer/ByteArray offset/int -> float
Reads a 32-bit floating point number from the buffer at the offset.
The offset must satisfy: 0 <= offset <= buffer.size - 8, allowing to read 8 bytes at index offset.

float64 buffer/ByteArray offset/int -> float
Reads a 64-bit floating point number from the buffer at the offset.
The offset must satisfy: 0 <= offset <= buffer.size - 8, allowing to read 8 bytes at index offset.

int16 buffer/ByteArray offset/int -> int
Reads a 16-bit signed integer from the buffer at the offset.
The offsets offset and offset + 1 must be valid indexes into the buffer.

int24 buffer/ByteArray offset/int -> int
Reads a 24-bit signed integer from the buffer at the offset.
The offset must satisfy: 0 <= offset <= buffer.size - 3, allowing to read 3 bytes at index offset.

int32 buffer/ByteArray offset/int -> int
Reads a 32-bit signed integer from the buffer at the offset.
The offset must satisfy: 0 <= offset <= buffer.size - 4, allowing to read 4 bytes at index offset.

int64 buffer/ByteArray offset/int -> int
Reads a 64-bit signed integer from the buffer at the offset.
The offset must satisfy: 0 <= offset <= buffer.size - 8, allowing to read 8 bytes at index offset.

int8 buffer/ByteArray offset/int -> int
Reads an 8-bit integer from the buffer at the offset.
The offset must be a valid index into the buffer.

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

put-float32 buffer/ByteArray offset/int f32/float -> none
Writes the f32 to the buffer at the offset.
The f32 is written as a 32-bit floating point number.
The offset must satisfy: 0 <= offset <= buffer.size - 8, allowing to write 8 bytes at index offset.

put-float64 buffer/ByteArray offset/int f64/float -> none
Writes the f64 to the buffer at the offset.
The f64 is written as a 64-bit floating point number.
The offset must satisfy: 0 <= offset <= buffer.size - 8, allowing to write 8 bytes at index offset.

put-int16 buffer/ByteArray offset/int i16/int -> none
Writes the i16 to the buffer at the offset.
The i16 is written as a signed 16-bit integer.
Only the 16 least-significant bits of the i16 are used, as if truncated with a bit-and operation (& 0xFFFF). The given i16 is allowed to be outside the signed 16-bit integer range. As a consequence, this operation behaves the same as put-uint16. The distinction between those two operations is purely for readability and to convey intent when writing the values.
The offsets offset and offset + 1 must be valid indexes into the buffer.

put-int24 buffer/ByteArray offset/int i24/int -> none
Writes the i24 to the buffer at the offset.
The i24 is written as a signed 24-bit integer.
Only the 24 least-significant bits of the i24 are used, as if truncated with a bit-and operation (& 0xFFFFFF). The given i24 is allowed to be outside the signed 24-bit integer range. As a consequence, this operation behaves the same as put-uint24. The distinction between those two operations is purely for readability and to convey intent when writing the values.
The offset must satisfy: 0 <= offset <= buffer.size - 3, allowing to write 3 bytes at index offset.

put-int32 buffer/ByteArray offset/int i32/int -> none
Writes the i32 to the buffer at the offset.
The i32 is written as a signed 32-bit integer.
Only the 32 least-significant bits of the i32 are used, as if truncated with a bit-and operation (& 0xFFFF_FFFF). The given i32 is allowed to be outside the signed 32-bit integer range. As a consequence, this operation behaves the same as put-uint32. The distinction between those two operations is purely for readability and to convey intent when writing the values.
The offset must satisfy: 0 <= offset <= buffer.size - 4, allowing to write 4 bytes at index offset.

put-int64 buffer/ByteArray offset/int i64/int -> none
Writes the i64 to the buffer at the offset.
The i64 is written as a signed 64-bit integer.
The offset must satisfy: 0 <= offset <= buffer.size - 8, allowing to write 8 bytes at index offset.

put-int8 buffer/ByteArray offset/int value/int -> none
Writes the value to the buffer at the offset.
The value is written as a signed 8-bit integer.
Only the 8 least-significant bits of the value are used, as if truncated with a bit-and operation (& 0xFF). The given value is allowed to be outside the signed 8-bit integer range. As a consequence, this operation behaves the same as put-uint8. The distinction between those two operations is purely for readability and to convey intent when writing the values.
Since single bytes have no byte-order this operation behaves the same on LittleEndian and BigEndian instances.
The offset must be a valid index into the buffer.

put-uint buffer/ByteArray size-in-bytes/int offset/int value/int -> none
See super.

put-uint16 buffer/ByteArray offset/int u16/int -> none
Writes the u16 to the buffer at the offset.
The u16 is written as a unsigned 16-bit integer.
Only the 16 least-significant bits of the u16 are used, as if truncated with a bit-and operation (& 0xFFFF). The given u16 is allowed to be outside the unsigned 16-bit integer range. As a consequence, this operation behaves the same as put-int16. The distinction between those two operations is purely for readability and to convey intent when writing the values.
The offsets offset and offset + 1 must be valid indexes into the buffer.

put-uint24 buffer/ByteArray offset/int u24/int -> none
Writes the u24 to the buffer at the offset.
The u24 is written as a unsigned 24-bit integer.
Only the 24 least-significant bits of the u24 are used, as if truncated with a bit-and operation (& 0xFFFFFF). The given u24 is allowed to be outside the unsigned 24-bit integer range. As a consequence, this operation behaves the same as put-int24. The distinction between those two operations is purely for readability and to convey intent when writing the values.
The offset must satisfy: 0 <= offset <= buffer.size - 3, allowing to write 3 bytes at index offset.

put-uint32 buffer/ByteArray offset/int u32/int -> none
Writes the u32 to the buffer at the offset.
The u32 is written as a unsigned 32-bit integer.
Only the 32 least-significant bits of the u32 are used, as if truncated with a bit-and operation (& 0xFFFF_FFFF). The given u32 is allowed to be outside the unsigned 32-bit integer range. As a consequence, this operation behaves the same as put-int32. The distinction between those two operations is purely for readability and to convey intent when writing the values.
The offset must satisfy: 0 <= offset <= buffer.size - 4, allowing to write 4 bytes at index offset.

put-uint8 buffer/ByteArray offset/int value/int -> none
Writes the value to the buffer at the offset.
The value is written as an unsigned 8-bit integer.
Only the 8 least-significant bits of the value are used, as if truncated with a bit-and operation (& 0xFF). The given value is allowed to be outside the unsigned 8-bit integer range. As a consequence, this operation behaves the same as put-int8. The distinction between those two operations is purely for readability and to convey intent when writing the values.
Since single bytes have no byte-order this operation behaves the same on LittleEndian and BigEndian instances.
The offset must be a valid index into the buffer.

read-int buffer/ByteArray size-in-bytes/int offset/int -> int
See super.

read-uint buffer/ByteArray size-in-bytes/int offset/int -> int
See super.

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.

uint16 buffer/ByteArray offset/int -> int
Reads a 16-bit unsigned integer from the buffer at the offset.
The offsets offset and offset + 1 must be valid indexes into the buffer.

uint24 buffer/ByteArray offset/int -> int
Reads a 24-bit unsigned integer from the buffer at the offset.
The offset must satisfy: 0 <= offset <= buffer.size - 3, allowing to read 3 bytes at index offset.

uint32 buffer/ByteArray offset/int -> int
Reads a 32-bit unsigned integer from the buffer at the offset.
The offset must satisfy: 0 <= offset <= buffer.size - 4, allowing to read 4 bytes at index offset.

uint8 buffer/ByteArray offset/int -> int
Reads an unsigned 8-bit integer from the buffer at the offset.
The offset must be a valid index into the buffer.