# module IO::ByteFormat

##
Overview

Defines a byte format to encode integers and floats from/to `Bytes` and `IO`.

###
Decode from bytes

    bytes = Bytes[0x34, 0x12]
    int16 = IO::ByteFormat::LittleEndian.decode(Int16, bytes)
    int16 # => 0x1234_i16

###
Decode from an IO

    io = IO::Memory.new(Bytes[0x34, 0x12])
    int16 = io.read_bytes(Int16, IO::ByteFormat::LittleEndian)
    int16 # => 0x1234_i16

###
Encode to bytes

    raw = uninitialized UInt8[2]
    IO::ByteFormat::LittleEndian.encode(0x1234_i16, raw.to_slice)
    raw # => StaticArray[0x34, 0x12]

###
Encode to IO

    io = IO::Memory.new
    io.write_bytes(0x1234_i16, IO::ByteFormat::LittleEndian)
    io.to_slice # => Bytes[0x34, 0x12]

##
Defined in:

io/byte_format.cr

##
Instance Method Summary

- #decode(int : Int8.class, io : IO)
- #decode(int : UInt8.class, io : IO)
- #decode(int : Int16.class, io : IO)
- #decode(int : UInt16.class, io : IO)
- #decode(int : Int32.class, io : IO)
- #decode(int : UInt32.class, io : IO)
- #decode(int : Int64.class, io : IO)
- #decode(int : UInt64.class, io : IO)
- #decode(int : Int128.class, io : IO)
- #decode(int : UInt128.class, io : IO)
- #decode(int : Int8.class, bytes : Bytes)
- #decode(int : UInt8.class, bytes : Bytes)
- #decode(int : Int16.class, bytes : Bytes)
- #decode(int : UInt16.class, bytes : Bytes)
- #decode(int : Int32.class, bytes : Bytes)
- #decode(int : UInt32.class, bytes : Bytes)
- #decode(int : Int64.class, bytes : Bytes)
- #decode(int : UInt64.class, bytes : Bytes)
- #decode(int : Int128.class, bytes : Bytes)
- #decode(int : UInt128.class, bytes : Bytes)
- #decode(type : Float32.class, io : IO) : Float32
- #decode(type : Float32.class, bytes : Bytes) : Float32
- #decode(type : Float64.class, io : IO) : Float64
- #decode(type : Float64.class, bytes : Bytes) : Float64
- #encode(int : Int8, io : IO)
- #encode(int : UInt8, io : IO)
- #encode(int : Int16, io : IO)
- #encode(int : UInt16, io : IO)
- #encode(int : Int32, io : IO)
- #encode(int : UInt32, io : IO)
- #encode(int : Int64, io : IO)
- #encode(int : UInt64, io : IO)
- #encode(int : Int128, io : IO)
- #encode(int : UInt128, io : IO)
- #encode(int : Int8, bytes : Bytes)
- #encode(int : UInt8, bytes : Bytes)
- #encode(int : Int16, bytes : Bytes)
- #encode(int : UInt16, bytes : Bytes)
- #encode(int : Int32, bytes : Bytes)
- #encode(int : UInt32, bytes : Bytes)
- #encode(int : Int64, bytes : Bytes)
- #encode(int : UInt64, bytes : Bytes)
- #encode(int : Int128, bytes : Bytes)
- #encode(int : UInt128, bytes : Bytes)
- #encode(float : Float32, io : IO) : Nil
- #encode(float : Float32, bytes : Bytes)
- #encode(float : Float64, io : IO) : Nil
- #encode(float : Float64, bytes : Bytes)

##
Instance Method Detail

abstract def decode(int : Int8.class, io : IO) #
abstract def decode(int : UInt8.class, io : IO) #
abstract def decode(int : Int16.class, io : IO) #
abstract def decode(int : UInt16.class, io : IO) #
abstract def decode(int : Int32.class, io : IO) #
abstract def decode(int : UInt32.class, io : IO) #
abstract def decode(int : Int64.class, io : IO) #
abstract def decode(int : UInt64.class, io : IO) #
abstract def decode(int : Int128.class, io : IO) #
abstract def decode(int : UInt128.class, io : IO) #
abstract def decode(int : Int8.class, bytes : Bytes) #
abstract def decode(int : UInt8.class, bytes : Bytes) #
abstract def decode(int : Int16.class, bytes : Bytes) #
abstract def decode(int : UInt16.class, bytes : Bytes) #
abstract def decode(int : Int32.class, bytes : Bytes) #
abstract def decode(int : UInt32.class, bytes : Bytes) #
abstract def decode(int : Int64.class, bytes : Bytes) #
abstract def decode(int : UInt64.class, bytes : Bytes) #
abstract def decode(int : Int128.class, bytes : Bytes) #
abstract def decode(int : UInt128.class, bytes : Bytes) #
def decode(type : Float32.class, io : IO) : Float32 #
def decode(type : Float32.class, bytes : Bytes) : Float32 #
def decode(type : Float64.class, io : IO) : Float64 #
def decode(type : Float64.class, bytes : Bytes) : Float64 #
abstract def encode(int : Int8, io : IO) #
abstract def encode(int : UInt8, io : IO) #
abstract def encode(int : Int16, io : IO) #
abstract def encode(int : UInt16, io : IO) #
abstract def encode(int : Int32, io : IO) #
abstract def encode(int : UInt32, io : IO) #
abstract def encode(int : Int64, io : IO) #
abstract def encode(int : UInt64, io : IO) #
abstract def encode(int : Int128, io : IO) #
abstract def encode(int : UInt128, io : IO) #
abstract def encode(int : Int8, bytes : Bytes) #
abstract def encode(int : UInt8, bytes : Bytes) #
abstract def encode(int : Int16, bytes : Bytes) #
abstract def encode(int : UInt16, bytes : Bytes) #
abstract def encode(int : Int32, bytes : Bytes) #
abstract def encode(int : UInt32, bytes : Bytes) #
abstract def encode(int : Int64, bytes : Bytes) #
abstract def encode(int : UInt64, bytes : Bytes) #
abstract def encode(int : Int128, bytes : Bytes) #
abstract def encode(int : UInt128, bytes : Bytes) #
def encode(float : Float32, io : IO) : Nil #
def encode(float : Float32, bytes : Bytes) #
def encode(float : Float64, io : IO) : Nil #
def encode(float : Float64, bytes : Bytes) #