rawbin

package module
v0.0.0-...-c13886e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2017 License: MIT Imports: 8 Imported by: 0

README

rawbin

rawbin is a library for encoding and decoding Go structs and valyes to raw binary data.

Supported Types

  • Anything implementing rawbin.Umarshaller (decoding) and rawbin.Marshaller (encoding)
  • Anything implementing encoding.BinaryMarshaler (encoding)
  • Most integer types (int8, int16, int32, int64, uint8, uint16, uint32, uint64) (int and uint are not supported because they are not size-fixed)
  • string as length(int16) + data([]byte)
  • floating point types (float32, float64)
  • bool (true - 1, false - 0)

There are also some basic types which implements the rawbin.Umarshaller and rawbin.Marshaller

  • rawbin.Varint and rawbin.Varlong
  • rawbin.String (string which uses rawbin.Varlong for the length instead of int16)
Todos
  • Support encoding.BinaryUnmarshaler

License

MIT

Free Software, Hell Yeah!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotPointer = errors.New("given value is not a pointer")

ErrNotPointer ...

Functions

func Decode

func Decode(value interface{}, r io.Reader) error

Decode is used to decode data from a reader

func DecodeBytes

func DecodeBytes(value interface{}, data []byte) error

DecodeBytes is used for decoding data which is stored in a byte array

func Encode

func Encode(value interface{}, w io.Writer) error

Encode will encode the given struct value and will write it to the given writer

func EncodeBytes

func EncodeBytes(value interface{}) ([]byte, error)

EncodeBytes will encode the given struct or value and return it in the bytes array

Types

type Marshaller

type Marshaller interface {
	RawMarshal(writer *Writer) error
}

Marshaller ...

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader for wrapping any io.Reader and implementing io.ByteReader for it

func (Reader) Read

func (r Reader) Read(p []byte) (n int, err error)

Read implements io.Reader

func (Reader) ReadByte

func (r Reader) ReadByte() (byte, error)

ReadByte implements io.ByteReader

type String

type String string

String is a sequence of Unicode scalar values UTF-8 string prefixed with its size in bytes as a VarInt. Maximum length of n characters, which varies by context; up to n × 4 bytes can be used to encode n characters and both of those limits are checked. Maximum n value is 32767. The + 3 is due to the max size of a valid length VarInt.

func (String) RawMarshal

func (v String) RawMarshal(writer *Writer) error

RawMarshal is used by rawbin to encode the data

func (*String) RawUnmarshal

func (v *String) RawUnmarshal(reader *Reader) error

RawUnmarshal is used by rawbin to decode the data

type Unmarshaller

type Unmarshaller interface {
	RawUnmarshal(reader *Reader) error
}

Unmarshaller ...

type Varint

type Varint int32

Varint is an integer between -2147483648 and 2147483647 Variable-length data encoding a two's complement signed 32-bit integer

func (Varint) RawMarshal

func (v Varint) RawMarshal(Writer *Writer) error

RawMarshal is used by rawbin to encode the data

func (*Varint) RawUnmarshal

func (v *Varint) RawUnmarshal(reader *Reader) error

RawUnmarshal is used by rawbin to decode the data TODO: Might need to write the reader because binary.ReadVarint is meant to read int64 and not int32 so it might read more then needed

type Varlong

type Varlong int64

Varlong is an integer between -9223372036854775808 and 9223372036854775807 Variable-length data encoding a two's complement signed 64-bit integer

func (Varlong) RawMarshal

func (v Varlong) RawMarshal(writer *Writer) error

RawMarshal is used by rawbin to encode the data

func (*Varlong) RawUnmarshal

func (v *Varlong) RawUnmarshal(reader *Reader) error

RawUnmarshal is used by rawbin to decode the data

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer wraps io.Writer and implements io.ByteWriter for it

func (Writer) Write

func (w Writer) Write(p []byte) (n int, err error)

Write for implementing io.Writer

func (Writer) WriteByte

func (w Writer) WriteByte(c byte) error

WriteByte for implementing io.ByteWriter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL