Documentation ¶
Index ¶
- func ConsumeBytes(r Reader, bytes uint64) uint64
- func ReadInt(r Reader, bits int32) int64
- func ReadUint(r Reader, bits int32) uint64
- func Write(w Writer, v interface{})
- func WriteBytes(w Writer, v uint8, count int32)
- func WriteInt(w Writer, bits int32, v int64)
- func WriteUint(w Writer, bits int32, v uint64)
- type BitStream
- type Reader
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConsumeBytes ¶
ConsumeBytes reads and throws away a number of bytes from r, returning the number of bytes it consumed.
func ReadInt ¶
ReadInt reads a signed integer of either 8, 16, 32 or 64 bits from r, returning the result as a int64.
func ReadUint ¶
ReadUint reads an unsigned integer of either 8, 16, 32 or 64 bits from r, returning the result as a uint64.
func Write ¶
func Write(w Writer, v interface{})
Write writes v to the writer w. v must be an byte, integer, float, boolean, string, slice or array.
func WriteBytes ¶
WriteBytes writes the given v for count times to writer w.
Types ¶
type BitStream ¶
type BitStream struct { Data []byte // The byte slice containing the bits ReadPos uint32 // The current read offset from the start of the Data slice (in bits) WritePos uint32 // The current write offset from the start of the Data slice (in bits) }
BitStream provides methods for reading and writing bits to a slice of bytes. Bits are packed in a least-significant-bit to most-significant-bit order.
func (*BitStream) Read ¶
Read reads the specified number of bits from the BitStream, increamenting the ReadPos by the specified number of bits and returning the bits packed into a uint64. The bits are packed into the uint64 from LSB to MSB.
func (*BitStream) ReadBit ¶
ReadBit reads a single bit from the BitStream, incrementing ReadPos by one.
type Reader ¶
type Reader interface { io.Reader // Data reads the data bytes in their entirety. Data([]byte) // Bool decodes and returns a boolean value from the Reader. Bool() bool // Int8 decodes and returns a signed, 8 bit integer value from the Reader. Int8() int8 // Uint8 decodes and returns an unsigned, 8 bit integer value from the Reader. Uint8() uint8 // Int16 decodes and returns a signed, 16 bit integer value from the Reader. Int16() int16 // Uint16 decodes and returns an unsigned, 16 bit integer value from the Reader. Uint16() uint16 // Int32 decodes and returns a signed, 32 bit integer value from the Reader. Int32() int32 // Uint32 decodes and returns an unsigned, 32 bit integer value from the Reader. Uint32() uint32 // Float16 decodes and returns a 16 bit floating-point value from the Reader. Float16() f16.Number // Float32 decodes and returns a 32 bit floating-point value from the Reader. Float32() float32 // Int64 decodes and returns a signed, 64 bit integer value from the Reader. Int64() int64 // Uint64 decodes and returns an unsigned, 64 bit integer value from the Reader. Uint64() uint64 // Float64 decodes and returns a 64 bit floating-point value from the Reader. Float64() float64 // String decodes and returns a string from the Reader. String() string // Decode a collection count from the stream. Count() uint32 // If there is an error reading any input, all further reading returns the // zero value of the type read. Error() returns the error which stopped // reading from the stream. If reading has not stopped it returns nil. Error() error // Set the error state and stop reading from the stream. SetError(error) }
Reader provides methods for decoding values.
type Writer ¶
type Writer interface { // Data writes the data bytes in their entirety. Data([]byte) // Bool encodes a boolean value to the Writer. Bool(bool) // Int8 encodes a signed, 8 bit integer value to the Writer. Int8(int8) // Uint8 encodes an unsigned, 8 bit integer value to the Writer. Uint8(uint8) // Int16 encodes a signed, 16 bit integer value to the Writer. Int16(int16) // Uint16 encodes an unsigned, 16 bit integer value to the Writer. Uint16(uint16) // Int32 encodes a signed, 32 bit integer value to the Writer. Int32(int32) // Uint32 encodes an usigned, 32 bit integer value to the Writer. Uint32(uint32) // Float16 encodes a 16 bit floating-point value to the Writer. Float16(f16.Number) // Float32 encodes a 32 bit floating-point value to the Writer. Float32(float32) // Int64 encodes a signed, 64 bit integer value to the Writer. Int64(int64) // Uint64 encodes an unsigned, 64 bit integer value to the Encoders's io.Writer. Uint64(uint64) // Float64 encodes a 64 bit floating-point value to the Writer. Float64(float64) // String encodes a string to the Writer. String(string) // If there is an error writing any output, all further writing becomes // a no-op. Error() returns the error which stopped writing to the stream. // If writing has not stopped it returns nil. Error() error // Set the error state and stop writing to the stream. SetError(error) }
Writer provides methods for encoding values.