Documentation ¶
Index ¶
- func ConsumeBytes(r Reader, bytes uint64) uint64
- func ReadInt(r Reader, bits int32) int64
- func ReadUint(r Reader, bits int32) uint64
- 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 Readable
- type Reader
- type Writable
- 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 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) CanRead ¶ added in v0.6.2
CanRead returns true if there's enough data to call Read(count).
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 Readable ¶
type Readable interface { // ReadSimple is invoked by a Reader to read the POD. ReadSimple(Reader) }
Readable is the interface to things that readable as Plain Old Data.
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 // Simple decodes a Readable type from the Writer. Simple(Readable) // 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 Writable ¶
type Writable interface { // WriteSimple is invoked by a Writer to write the POD. WriteSimple(Writer) }
Writable is the interface to things that are writable as Plain Old Data.
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) // Simple encodes a Writable type to the Writer. Simple(Writable) // 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.