Interface
interface BigEndianOrder<T>
public interface BigEndianOrder<T> {
func writeBigEndian(buffer: Array<Byte>): Int64
static func readBigEndian(buffer: Array<Byte>): T
}
Description: Specifies the big-endian byte sequence conversion interface.
static func readBigEndian(Array<Byte>)
static func readBigEndian(buffer: Array<Byte>): T
Description: Reads a T value from a byte array in big-endian mode.
Parameters:
Returns:
- T: T value
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the T value, this exception is thrown.
func writeBigEndian(Array<Byte>)
func writeBigEndian(buffer: Array<Byte>): Int64
Description: Writes the T value to a byte array in big-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the T value, this exception is thrown.
extend Bool <: BigEndianOrder<Bool>
extend Bool <: BigEndianOrder<Bool>
Description: Extends the BigEndianOrder interface for Bool to implement the conversion between Bool values and big-endian byte sequences.
Parent Type:
static func readBigEndian(Array<Byte>)
public static func readBigEndian(buffer: Array<Byte>): Bool
Description: Reads a Bool value from a byte array in big-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Bool value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x1]
let n = Bool.readBigEndian(buffer)
@Assert(n, true)
}
func writeBigEndian(Array<Byte>)
public func writeBigEndian(buffer: Array<Byte>): Int64
Description: Writes a Bool value to a byte array in big-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Bool value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = true.writeBigEndian(buffer)
@Assert(n, 1)
@Assert(buffer[..n], [0x01u8])
}
extend Float16 <: BigEndianOrder<Float16>
extend Float16 <: BigEndianOrder<Float16>
Description: Extends the BigEndianOrder interface for Float16 to implement the conversion between Float16 values and big-endian byte sequences.
Parent Type:
static func readBigEndian(Array<Byte>)
public static func readBigEndian(buffer: Array<Byte>): Float16
Description: Reads a Float16 value from a byte array in big-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Float16 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x4A, 0x40]
let n = Float16.readBigEndian(buffer)
@Assert(n, 12.5)
}
func writeBigEndian(Array<Byte>)
public func writeBigEndian(buffer: Array<Byte>): Int64
Description: Writes a Float16 value to a byte array in big-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Float16 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 12.5f16.writeBigEndian(buffer)
@Assert(n, 2)
@Assert(buffer[..n], [0x4A, 0x40])
}
extend Float32 <: BigEndianOrder<Float32>
extend Float32 <: BigEndianOrder<Float32>
Description: Extends the BigEndianOrder interface for Float32 to implement the conversion between Float32 values and big-endian byte sequences.
Parent Type:
static func readBigEndian(Array<Byte>)
public static func readBigEndian(buffer: Array<Byte>): Float32
Description: Reads a Float32 value from a byte array in big-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Float32 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x41, 0x48, 0x00, 0x00]
let n = Float32.readBigEndian(buffer)
@Assert(n, 12.5)
}
func writeBigEndian(Array<Byte>)
public func writeBigEndian(buffer: Array<Byte>): Int64
Description: Writes a Float32 value to a byte array in big-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Float32 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 12.5f32.writeBigEndian(buffer)
@Assert(n, 4)
@Assert(buffer[..n], [0x41, 0x48, 0x00, 0x00])
}
extend Float64 <: BigEndianOrder<Float64>
extend Float64 <: BigEndianOrder<Float64>
Description: Extends the BigEndianOrder interface for Float64 to implement the conversion between Float64 values and big-endian byte sequences.
Parent Type:
static func readBigEndian(Array<Byte>)
public static func readBigEndian(buffer: Array<Byte>): Float64
Description: Reads a Float64 value from a byte array in big-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Float64 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
let n = Float64.readBigEndian(buffer)
@Assert(n, 12.5)
}
func writeBigEndian(Array<Byte>)
public func writeBigEndian(buffer: Array<Byte>): Int64
Description: Writes a Float64 value to a byte array in big-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Float64 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 12.5f64.writeBigEndian(buffer)
@Assert(n, 8)
@Assert(buffer[..n], [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
}
extend Int16 <: BigEndianOrder<Int16>
extend Int16 <: BigEndianOrder<Int16>
Description: Extends the BigEndianOrder interface for Int16 to implement the conversion between Int16 values and big-endian byte sequences.
Parent Type:
static func readBigEndian(Array<Byte>)
public static func readBigEndian(buffer: Array<Byte>): Int16
Description: Reads an Int16 value from a byte array in big-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Int16 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x12, 0x34]
let n = Int16.readBigEndian(buffer)
@Assert(n, 0x1234)
}
func writeBigEndian(Array<Byte>)
public func writeBigEndian(buffer: Array<Byte>): Int64
Description: Writes an Int16 value to a byte array in big-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Int16 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x1234i16.writeBigEndian(buffer)
@Assert(n, 2)
@Assert(buffer[..n], [0x12, 0x34])
}
extend Int32 <: BigEndianOrder<Int32>
extend Int32 <: BigEndianOrder<Int32>
Description: Extends the BigEndianOrder interface for Int32 to implement the conversion between Int32 values and big-endian byte sequences.
Parent Type:
static func readBigEndian(Array<Byte>)
public static func readBigEndian(buffer: Array<Byte>): Int32
Description: Reads an Int32 value from a byte array in big-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Int32 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x12, 0x34, 0x56, 0x78]
let n = Int32.readBigEndian(buffer)
@Assert(n, 0x12345678)
}
func writeBigEndian(Array<Byte>)
public func writeBigEndian(buffer: Array<Byte>): Int64
Description: Writes an Int32 value to a byte array in big-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Int32 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x12345678i32.writeBigEndian(buffer)
@Assert(n, 4)
@Assert(buffer[..n], [0x12, 0x34, 0x56, 0x78])
}
extend Int64 <: BigEndianOrder<Int64>
extend Int64 <: BigEndianOrder<Int64>
Description: Extends the BigEndianOrder interface for Int64 to implement the conversion between Int64 values and big-endian byte sequences.
Parent Type:
static func readBigEndian(Array<Byte>)
public static func readBigEndian(buffer: Array<Byte>): Int64
Description: Reads an Int64 value from a byte array in big-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Int64 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]
let n = Int64.readBigEndian(buffer)
@Assert(n, 0x1234567890123456)
}
func writeBigEndian(Array<Byte>)
public func writeBigEndian(buffer: Array<Byte>): Int64
Description: Writes an Int64 value to a byte array in big-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Int64 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x1234567890123456i64.writeBigEndian(buffer)
@Assert(n, 8)
@Assert(buffer[..n], [0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56])
}
extend Int8 <: BigEndianOrder<Int8>
extend Int8 <: BigEndianOrder<Int8>
Description: Extends the BigEndianOrder interface for Int8 to implement the conversion between Int8 values and big-endian byte sequences.
Parent Type:
static func readBigEndian(Array<Byte>)
public static func readBigEndian(buffer: Array<Byte>): Int8
Description: Reads an Int8 value from a byte array in big-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Int8 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x12]
let n = Int8.readBigEndian(buffer)
@Assert(n, 0x12)
}
func writeBigEndian(Array<Byte>)
public func writeBigEndian(buffer: Array<Byte>): Int64
Description: Writes an Int8 value to a byte array in big-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Int8 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x12i8.writeBigEndian(buffer)
@Assert(n, 1)
@Assert(buffer[..n], [0x12])
}
extend UInt16 <: BigEndianOrder<UInt16>
extend UInt16 <: BigEndianOrder<UInt16>
Description: Extends the BigEndianOrder interface for UInt16 to implement the conversion between UInt16 values and big-endian byte sequences.
Parent Type:
static func readBigEndian(Array<Byte>)
public static func readBigEndian(buffer: Array<Byte>): UInt16
Description: Reads a UInt16 value from a byte array in big-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the UInt16 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x12, 0x34]
let n = UInt16.readBigEndian(buffer)
@Assert(n, 0x1234)
}
func writeBigEndian(Array<Byte>)
public func writeBigEndian(buffer: Array<Byte>): Int64
Description: Writes a UInt16 value to a byte array in big-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the UInt16 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x1234u16.writeBigEndian(buffer)
@Assert(n, 2)
@Assert(buffer[..n], [0x12, 0x34])
}
extend UInt32 <: BigEndianOrder<UInt32>
extend UInt32 <: BigEndianOrder<UInt32>
Description: Extends the BigEndianOrder interface for UInt32 to implement the conversion between UInt32 values and big-endian byte sequences.
Parent Type:
static func readBigEndian(Array<Byte>)
public static func readBigEndian(buffer: Array<Byte>): UInt32
Description: Reads a UInt32 value from a byte array in big-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the UInt32 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x12, 0x34, 0x56, 0x78]
let n = UInt32.readBigEndian(buffer)
@Assert(n, 0x12345678)
}
func writeBigEndian(Array<Byte>)
public func writeBigEndian(buffer: Array<Byte>): Int64
Description: Writes a UInt32 value to a byte array in big-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the UInt32 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x12345678u32.writeBigEndian(buffer)
@Assert(n, 4)
@Assert(buffer[..n], [0x12, 0x34, 0x56, 0x78])
}
extend UInt64 <: BigEndianOrder<UInt64>
extend UInt64 <: BigEndianOrder<UInt64>
Description: Extends the BigEndianOrder interface for UInt64 to implement the conversion between UInt64 values and big-endian byte sequences.
Parent Type:
static func readBigEndian(Array<Byte>)
public static func readBigEndian(buffer: Array<Byte>): UInt64
Description: Reads a UInt64 value from a byte array in big-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the UInt64 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]
let n = UInt64.readBigEndian(buffer)
@Assert(n, 0x1234567890123456)
}
func writeBigEndian(Array<Byte>)
public func writeBigEndian(buffer: Array<Byte>): Int64
Description: Writes a UInt64 value to a byte array in big-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the UInt64 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x1234567890123456u64.writeBigEndian(buffer)
@Assert(n, 8)
@Assert(buffer[..n], [0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56])
}
extend UInt8 <: BigEndianOrder<UInt8>
extend UInt8 <: BigEndianOrder<UInt8>
Description: Extends the BigEndianOrder interface for UInt8 to implement the conversion between UInt8 values and big-endian byte sequences.
Parent Type:
static func readBigEndian(Array<Byte>)
public static func readBigEndian(buffer: Array<Byte>): UInt8
Description: Reads a UInt8 value from a byte array in big-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the UInt8 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x12]
let n = UInt8.readBigEndian(buffer)
@Assert(n, 0x12)
}
func writeBigEndian(Array<Byte>)
public func writeBigEndian(buffer: Array<Byte>): Int64
Description: Writes a UInt8 value to a byte array in big-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the UInt8 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x12u8.writeBigEndian(buffer)
@Assert(n, 1)
@Assert(buffer[..n], [0x12])
}
interface LittleEndianOrder<T>
public interface LittleEndianOrder<T> {
func writeLittleEndian(buffer: Array<Byte>): Int64
static func readLittleEndian(buffer: Array<Byte>): T
}
Description: Specifies the little-endian byte sequence conversion interface.
static func readLittleEndian(Array<Byte>)
static func readLittleEndian(buffer: Array<Byte>): T
Description: Reads a T value from a byte array in little-endian mode.
Parameters:
Returns:
- T: T value
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the T value, this exception is thrown.
func writeLittleEndian(Array<Byte>)
func writeLittleEndian(buffer: Array<Byte>): Int64
Description: Writes the T value to a byte array in little-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the T value, this exception is thrown.
extend Bool <: LittleEndianOrder<Bool>
extend Bool <: LittleEndianOrder<Bool>
Description: Extends the LittleEndianOrder interface for Bool to implement the conversion between Bool values and little-endian byte sequences.
Parent Type:
static func readLittleEndian(Array<Byte>)
public static func readLittleEndian(buffer: Array<Byte>): Bool
Description: Reads a Bool value from a byte array in little-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Bool value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x1]
let n = Bool.readLittleEndian(buffer)
@Assert(n, true)
}
func writeLittleEndian(Array<Byte>)
public func writeLittleEndian(buffer: Array<Byte>): Int64
Description: Writes a Bool value to a byte array in little-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Bool value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = true.writeLittleEndian(buffer)
@Assert(n, 1)
@Assert(buffer[..n], [0x01])
}
extend Float16 <: LittleEndianOrder<Float16>
extend Float16 <: LittleEndianOrder<Float16>
Description: Extends the LittleEndianOrder interface for Float16 to implement the conversion between Float16 values and little-endian byte sequences.
Parent Type:
static func readLittleEndian(Array<Byte>)
public static func readLittleEndian(buffer: Array<Byte>): Float16
Description: Reads a Float16 value from a byte array in little-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Float16 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x40, 0x4A]
let n = Float16.readLittleEndian(buffer)
@Assert(n, 12.5)
}
func writeLittleEndian(Array<Byte>)
public func writeLittleEndian(buffer: Array<Byte>): Int64
Description: Writes a Float16 value to a byte array in little-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Float16 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 12.5f16.writeLittleEndian(buffer)
@Assert(n, 2)
@Assert(buffer[..n], [0x40, 0x4A])
}
extend Float32 <: LittleEndianOrder<Float32>
extend Float32 <: LittleEndianOrder<Float32>
Description: Extends the LittleEndianOrder interface for Float32 to implement the conversion between Float32 values and little-endian byte sequences.
Parent Type:
static func readLittleEndian(Array<Byte>)
public static func readLittleEndian(buffer: Array<Byte>): Float32
Description: Reads a Float32 value from a byte array in little-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Float32 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x00, 0x00, 0x48, 0x41]
let n = Float32.readLittleEndian(buffer)
@Assert(n, 12.5)
}
func writeLittleEndian(Array<Byte>)
public func writeLittleEndian(buffer: Array<Byte>): Int64
Description: Writes a Float32 value to a byte array in little-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Float32 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 12.5f32.writeLittleEndian(buffer)
@Assert(n, 4)
@Assert(buffer[..n], [0x00, 0x00, 0x48, 0x41])
}
extend Float64 <: LittleEndianOrder<Float64>
extend Float64 <: LittleEndianOrder<Float64>
Description: Extends the LittleEndianOrder interface for Float64 to implement the conversion between Float64 values and little-endian byte sequences.
Parent Type:
static func readLittleEndian(Array<Byte>)
public static func readLittleEndian(buffer: Array<Byte>): Float64
Description: Reads a Float64 value from a byte array in little-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Float64 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]
let n = Float64.readLittleEndian(buffer)
@Assert(n, 12.5)
}
func writeLittleEndian(Array<Byte>)
public func writeLittleEndian(buffer: Array<Byte>): Int64
Description: Writes a Float64 value to a byte array in little-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Float64 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 12.5f64.writeLittleEndian(buffer)
@Assert(n, 8)
@Assert(buffer[..n], [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40])
}
extend Int16 <: LittleEndianOrder<Int16>
extend Int16 <: LittleEndianOrder<Int16>
Description: Extends the LittleEndianOrder interface for Int16 to implement the conversion between Int16 values and little-endian byte sequences.
Parent Type:
static func readLittleEndian(Array<Byte>)
public static func readLittleEndian(buffer: Array<Byte>): Int16
Description: Reads an Int16 value from a byte array in little-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Int16 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x34, 0x12]
let n = Int16.readLittleEndian(buffer)
@Assert(n, 0x1234i16)
}
func writeLittleEndian(Array<Byte>)
public func writeLittleEndian(buffer: Array<Byte>): Int64
Description: Writes an Int16 value to a byte array in little-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Int16 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x1234i16.writeLittleEndian(buffer)
@Assert(n, 2)
@Assert(buffer[..n], [0x34, 0x12])
}
extend Int32 <: LittleEndianOrder<Int32>
extend Int32 <: LittleEndianOrder<Int32>
Description: Extends the LittleEndianOrder interface for Int32 to implement the conversion between Int32 values and little-endian byte sequences.
Parent Type:
static func readLittleEndian(Array<Byte>)
public static func readLittleEndian(buffer: Array<Byte>): Int32
Description: Reads an Int32 value from a byte array in little-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Int32 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x78, 0x56, 0x34, 0x12]
let n = Int32.readLittleEndian(buffer)
@Assert(n, 0x12345678i32)
}
func writeLittleEndian(Array<Byte>)
public func writeLittleEndian(buffer: Array<Byte>): Int64
Description: Writes an Int32 value to a byte array in little-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Int32 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x12345678i32.writeLittleEndian(buffer)
@Assert(n, 4)
@Assert(buffer[..n], [0x78, 0x56, 0x34, 0x12])
}
extend Int64 <: LittleEndianOrder<Int64>
extend Int64 <: LittleEndianOrder<Int64>
Description: Extends the LittleEndianOrder interface for Int64 to implement the conversion between Int64 values and little-endian byte sequences.
Parent Type:
static func readLittleEndian(Array<Byte>)
public static func readLittleEndian(buffer: Array<Byte>): Int64
Description: Reads an Int64 value from a byte array in little-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Int64 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]
let n = Int64.readLittleEndian(buffer)
@Assert(n, 0x1234567890123456i64)
}
func writeLittleEndian(Array<Byte>)
public func writeLittleEndian(buffer: Array<Byte>): Int64
Description: Writes an Int64 value to a byte array in little-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Int64 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x1234567890123456i64.writeLittleEndian(buffer)
@Assert(n, 8)
@Assert(buffer[..n], [0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12])
}
extend Int8 <: LittleEndianOrder<Int8>
extend Int8 <: LittleEndianOrder<Int8>
Description: Extends the LittleEndianOrder interface for Int8 to implement the conversion between Int8 values and little-endian byte sequences.
Parent Type:
static func readLittleEndian(Array<Byte>)
public static func readLittleEndian(buffer: Array<Byte>): Int8
Description: Reads an Int8 value from a byte array in little-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the Int8 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x12]
let n = Int8.readLittleEndian(buffer)
@Assert(n, 0x12)
}
func writeLittleEndian(Array<Byte>)
public func writeLittleEndian(buffer: Array<Byte>): Int64
Description: Writes an Int8 value to a byte array in little-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the Int8 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x12i8.writeLittleEndian(buffer)
@Assert(n, 1)
@Assert(buffer[..n], [0x12])
}
extend UInt16 <: LittleEndianOrder<UInt16>
extend UInt16 <: LittleEndianOrder<UInt16>
Description: Extends the LittleEndianOrder interface for UInt16 to implement the conversion between UInt16 values and little-endian byte sequences.
Parent Type:
static func readLittleEndian(Array<Byte>)
public static func readLittleEndian(buffer: Array<Byte>): UInt16
Description: Reads a UInt16 value from a byte array in little-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the UInt16 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x34, 0x12]
let n = UInt16.readLittleEndian(buffer)
@Assert(n, 0x1234u16)
}
func writeLittleEndian(Array<Byte>)
public func writeLittleEndian(buffer: Array<Byte>): Int64
Description: Writes a UInt16 value to a byte array in little-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the UInt16 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x1234u16.writeLittleEndian(buffer)
@Assert(n, 2)
@Assert(buffer[..n], [0x34, 0x12])
}
extend UInt32 <: LittleEndianOrder<UInt32>
extend UInt32 <: LittleEndianOrder<UInt32>
Description: Extends the LittleEndianOrder interface for UInt32 to implement the conversion between UInt32 values and little-endian byte sequences.
Parent Type:
static func readLittleEndian(Array<Byte>)
public static func readLittleEndian(buffer: Array<Byte>): UInt32
Description: Reads a UInt32 value from a byte array in little-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the UInt32 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x78, 0x56, 0x34, 0x12]
let n = UInt32.readLittleEndian(buffer)
@Assert(n, 0x12345678i32)
}
func writeLittleEndian(Array<Byte>)
public func writeLittleEndian(buffer: Array<Byte>): Int64
Description: Writes a UInt32 value to a byte array in little-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the UInt32 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x12345678u32.writeLittleEndian(buffer)
@Assert(n, 4)
@Assert(buffer[..n], [0x78, 0x56, 0x34, 0x12])
}
extend UInt64 <: LittleEndianOrder<UInt64>
extend UInt64 <: LittleEndianOrder<UInt64>
Description: Extends the LittleEndianOrder interface for UInt64 to implement the conversion between UInt64 values and little-endian byte sequences.
Parent Type:
static func readLittleEndian(Array<Byte>)
public static func readLittleEndian(buffer: Array<Byte>): UInt64
Description: Reads a UInt64 value from a byte array in little-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the UInt64 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]
let n = UInt64.readLittleEndian(buffer)
@Assert(n, 0x1234567890123456i64)
}
func writeLittleEndian(Array<Byte>)
public func writeLittleEndian(buffer: Array<Byte>): Int64
Description: Writes a UInt64 value to a byte array in little-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the UInt64 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x1234567890123456u64.writeLittleEndian(buffer)
@Assert(n, 8)
@Assert(buffer[..n], [0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12])
}
extend UInt8 <: LittleEndianOrder<UInt8>
extend UInt8 <: LittleEndianOrder<UInt8>
Description: Extends the LittleEndianOrder interface for UInt8 to implement the conversion between UInt8 values and little-endian byte sequences.
Parent Type:
static func readLittleEndian(Array<Byte>)
public static func readLittleEndian(buffer: Array<Byte>): UInt8
Description: Reads a UInt8 value from a byte array in little-endian mode.
Parameters:
Returns:
Throws:
- IllegalArgumentException: If buffer is insufficient for reading the UInt8 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer: Array<Byte> = [0x12]
let n = UInt8.readLittleEndian(buffer)
@Assert(n, 0x12)
}
func writeLittleEndian(Array<Byte>)
public func writeLittleEndian(buffer: Array<Byte>): Int64
Description: Writes a UInt8 value to a byte array in little-endian mode.
Parameters:
Returns:
- Int64: number of bytes of the written data
Throws:
- IllegalArgumentException: If buffer is insufficient for storing the UInt8 value, this exception is thrown.
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let buffer = Array<Byte>(8, item: 0)
let n = 0x12u8.writeLittleEndian(buffer)
@Assert(n, 1)
@Assert(buffer[..n], [0x12])
}
interface SwapEndianOrder<T>
public interface SwapEndianOrder<T> {
func swapBytes(): T
}
Description: Specifies the byte order reversion interface.
func swapBytes()
func swapBytes(): T
Description: Reverses the byte order of the T value.
Returns:
- T: T value
extend Int16 <: SwapEndianOrder<Int16>
extend Int16 <: SwapEndianOrder<Int16>
Description: Extends the SwapEndianOrder interface for Int16 to reverse the byte order of an Int16 value.
Parent Type:
func swapBytes()
public func swapBytes(): Int16
Description: Reverses the byte order of an Int16 value.
Returns:
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let n = 0x1234i16
let m = n.swapBytes()
@Assert(m, 0x3412)
}
extend Int32 <: SwapEndianOrder<Int32>
extend Int32 <: SwapEndianOrder<Int32>
Description: Extends the SwapEndianOrder interface for Int32 to reverse the byte order of an Int32 value.
Parent Type:
func swapBytes()
public func swapBytes(): Int32
Description: Reverses the byte order of an Int32 value.
Returns:
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let n = 0x12345678i32
let m = n.swapBytes()
@Assert(m, 0x78563412)
}
extend Int64 <: SwapEndianOrder<Int64>
extend Int64 <: SwapEndianOrder<Int64>
Description: Extends the SwapEndianOrder interface for Int64 to reverse the byte order of an Int64 value.
Parent Type:
func swapBytes()
public func swapBytes(): Int64
Description: Reverses the byte order of an Int64 value.
Returns:
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let n = 0x1234567890123456i64
let m = n.swapBytes()
@Assert(m, 0x5634129078563412)
}
extend Int8 <: SwapEndianOrder<Int8>
extend Int8 <: SwapEndianOrder<Int8>
Description: Extends the SwapEndianOrder interface for Int8 to reverse the byte order of an Int8 value.
Parent Type:
func swapBytes()
public func swapBytes(): Int8
Description: Reverses the byte order of an Int8 value.
Returns:
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let n = 0x12i8
let m = n.swapBytes()
@Assert(m, 0x12)
}
extend UInt16 <: SwapEndianOrder<UInt16>
extend UInt16 <: SwapEndianOrder<UInt16>
Description: Extends the SwapEndianOrder interface for UInt16 to reverse the byte order of a UInt16 value.
Parent Type:
func swapBytes()
public func swapBytes(): UInt16
Description: Reverses the byte order of a UInt16 value.
Returns:
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let n = 0x1234u16
let m = n.swapBytes()
@Assert(m, 0x3412)
}
extend UInt32 <: SwapEndianOrder<UInt32>
extend UInt32 <: SwapEndianOrder<UInt32>
Description: Extends the SwapEndianOrder interface for UInt32 to reverse the byte order of a UInt32 value.
Parent Type:
func swapBytes()
public func swapBytes(): UInt32
Description: Reverses the byte order of a UInt32 value.
Returns:
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let n = 0x12345678u32
let m = n.swapBytes()
@Assert(m, 0x78563412)
}
extend UInt64 <: SwapEndianOrder<UInt64>
extend UInt64 <: SwapEndianOrder<UInt64>
Description: Extends the SwapEndianOrder interface for UInt64 to reverse the byte order of a UInt64 value.
Parent Type:
func swapBytes()
public func swapBytes(): UInt64
Description: Reverses the byte order of a UInt64 value.
Returns:
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let n = 0x1234567890123456u64
let m = n.swapBytes()
@Assert(m, 0x5634129078563412)
}
extend UInt8 <: SwapEndianOrder<UInt8>
extend UInt8 <: SwapEndianOrder<UInt8>
Description: Extends the SwapEndianOrder interface for UInt8 to reverse the byte order of a UInt8 value.
Parent Type:
func swapBytes()
public func swapBytes(): UInt8
Description: Reverses the byte order of a UInt8 value.
Returns:
Example:
import std.binary.*
import std.unittest.*
import std.unittest.testmacro.*
main() {
let n = 0x12u8
let m = n.swapBytes()
@Assert(m, 0x12)
}