Binary encoding v0.1.0
Endian
pub enum Endian: int32 {
Little = 0,
Big = 1
}
A byte order: which end of a multi-byte value comes first.
Cases
| Name | Value | Description |
|---|---|---|
Little | 0 | The least significant byte first: x86-64, AArch64, and most formats born on them. |
Big | 1 | The most significant byte first: network order, and the older big machines. |
ReadWord
pub func ReadWord(
reader: &var Reader,
endian: Endian,
width: uint
) -> uint512 ! IoError
Reads a width-byte unsigned word in the given order, into the low bytes of the result.
The word functions are the one implementation the typed surface below stands on; call those unless the width
itself is a runtime quantity.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
width | uint | how many bytes the value occupies |
Returns: the value read, in the low bytes; IsEnd when the stream ended first
WriteWord
pub func WriteWord(
writer: &var Writer,
endian: Endian,
width: uint,
value: uint512
) -> ! IoError
Writes the low width bytes of value in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
width | uint | how many bytes the value occupies |
value | uint512 | the value to write |
Returns: success when the whole value was written
ReadUint8
pub func ReadUint8(
reader: &var Reader,
endian: Endian
) -> uint8 ! IoError
Reads a uint8 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteUint8
pub func WriteUint8(
writer: &var Writer,
endian: Endian,
value: uint8
) -> ! IoError
Writes a uint8 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | uint8 | the value to write |
Returns: success when the whole value was written
ReadInt8
pub func ReadInt8(
reader: &var Reader,
endian: Endian
) -> int8 ! IoError
Reads an int8: the unsigned bytes, reinterpreted in two's complement.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteInt8
pub func WriteInt8(
writer: &var Writer,
endian: Endian,
value: int8
) -> ! IoError
Writes an int8: its two's-complement bytes, unchanged.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | int8 | the value to write |
Returns: success when the whole value was written
ReadUint16
pub func ReadUint16(
reader: &var Reader,
endian: Endian
) -> uint16 ! IoError
Reads a uint16 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteUint16
pub func WriteUint16(
writer: &var Writer,
endian: Endian,
value: uint16
) -> ! IoError
Writes a uint16 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | uint16 | the value to write |
Returns: success when the whole value was written
ReadInt16
pub func ReadInt16(
reader: &var Reader,
endian: Endian
) -> int16 ! IoError
Reads an int16: the unsigned bytes, reinterpreted in two's complement.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteInt16
pub func WriteInt16(
writer: &var Writer,
endian: Endian,
value: int16
) -> ! IoError
Writes an int16: its two's-complement bytes, unchanged.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | int16 | the value to write |
Returns: success when the whole value was written
ReadUint32
pub func ReadUint32(
reader: &var Reader,
endian: Endian
) -> uint32 ! IoError
Reads a uint32 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteUint32
pub func WriteUint32(
writer: &var Writer,
endian: Endian,
value: uint32
) -> ! IoError
Writes a uint32 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | uint32 | the value to write |
Returns: success when the whole value was written
ReadInt32
pub func ReadInt32(
reader: &var Reader,
endian: Endian
) -> int32 ! IoError
Reads an int32: the unsigned bytes, reinterpreted in two's complement.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteInt32
pub func WriteInt32(
writer: &var Writer,
endian: Endian,
value: int32
) -> ! IoError
Writes an int32: its two's-complement bytes, unchanged.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | int32 | the value to write |
Returns: success when the whole value was written
ReadUint64
pub func ReadUint64(
reader: &var Reader,
endian: Endian
) -> uint64 ! IoError
Reads a uint64 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteUint64
pub func WriteUint64(
writer: &var Writer,
endian: Endian,
value: uint64
) -> ! IoError
Writes a uint64 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | uint64 | the value to write |
Returns: success when the whole value was written
ReadInt64
pub func ReadInt64(
reader: &var Reader,
endian: Endian
) -> int64 ! IoError
Reads an int64: the unsigned bytes, reinterpreted in two's complement.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteInt64
pub func WriteInt64(
writer: &var Writer,
endian: Endian,
value: int64
) -> ! IoError
Writes an int64: its two's-complement bytes, unchanged.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | int64 | the value to write |
Returns: success when the whole value was written
ReadUint128
pub func ReadUint128(
reader: &var Reader,
endian: Endian
) -> uint128 ! IoError
Reads a uint128 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteUint128
pub func WriteUint128(
writer: &var Writer,
endian: Endian,
value: uint128
) -> ! IoError
Writes a uint128 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | uint128 | the value to write |
Returns: success when the whole value was written
ReadInt128
pub func ReadInt128(
reader: &var Reader,
endian: Endian
) -> int128 ! IoError
Reads an int128: the unsigned bytes, reinterpreted in two's complement.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteInt128
pub func WriteInt128(
writer: &var Writer,
endian: Endian,
value: int128
) -> ! IoError
Writes an int128: its two's-complement bytes, unchanged.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | int128 | the value to write |
Returns: success when the whole value was written
ReadUint256
pub func ReadUint256(
reader: &var Reader,
endian: Endian
) -> uint256 ! IoError
Reads a uint256 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteUint256
pub func WriteUint256(
writer: &var Writer,
endian: Endian,
value: uint256
) -> ! IoError
Writes a uint256 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | uint256 | the value to write |
Returns: success when the whole value was written
ReadInt256
pub func ReadInt256(
reader: &var Reader,
endian: Endian
) -> int256 ! IoError
Reads an int256: the unsigned bytes, reinterpreted in two's complement.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteInt256
pub func WriteInt256(
writer: &var Writer,
endian: Endian,
value: int256
) -> ! IoError
Writes an int256: its two's-complement bytes, unchanged.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | int256 | the value to write |
Returns: success when the whole value was written
ReadUint512
pub func ReadUint512(
reader: &var Reader,
endian: Endian
) -> uint512 ! IoError
Reads a uint512 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteUint512
pub func WriteUint512(
writer: &var Writer,
endian: Endian,
value: uint512
) -> ! IoError
Writes a uint512 in the given order.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | uint512 | the value to write |
Returns: success when the whole value was written
ReadInt512
pub func ReadInt512(
reader: &var Reader,
endian: Endian
) -> int512 ! IoError
Reads an int512: the unsigned bytes, reinterpreted in two's complement.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteInt512
pub func WriteInt512(
writer: &var Writer,
endian: Endian,
value: int512
) -> ! IoError
Writes an int512: its two's-complement bytes, unchanged.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | int512 | the value to write |
Returns: success when the whole value was written
ReadFloat32
pub func ReadFloat32(
reader: &var Reader,
endian: Endian
) -> float32 ! IoError
Reads a float32 as the IEEE 754 bit pattern of its width.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteFloat32
pub func WriteFloat32(
writer: &var Writer,
endian: Endian,
value: float32
) -> ! IoError
Writes a float32 as the IEEE 754 bit pattern of its width.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | float32 | the value to write |
Returns: success when the whole value was written
ReadFloat64
pub func ReadFloat64(
reader: &var Reader,
endian: Endian
) -> float64 ! IoError
Reads a float64 as the IEEE 754 bit pattern of its width.
Parameters
| Name | Type | Description |
|---|---|---|
reader | &var Reader | where the bytes come from |
endian | Endian | which byte order the value is stored in |
Returns: the value read; IsEnd when the stream ended first
WriteFloat64
pub func WriteFloat64(
writer: &var Writer,
endian: Endian,
value: float64
) -> ! IoError
Writes a float64 as the IEEE 754 bit pattern of its width.
Parameters
| Name | Type | Description |
|---|---|---|
writer | &var Writer | the destination |
endian | Endian | which byte order the value is stored in |
value | float64 | the value to write |
Returns: success when the whole value was written