Documentation ¶
Index ¶
- Variables
- func Decode(r io.Reader, v interface{}, order binary.ByteOrder) error
- func Encode(w io.Writer, v interface{}, order binary.ByteOrder) (int, error)
- func Read(r io.Reader, order binary.ByteOrder) ([]byte, error)
- func Write(w io.Writer, message io.Reader, order binary.ByteOrder) (i int, err error)
- type JSONDecoder
- type JSONEncoder
- type Reader
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidMessageSize unable to read message size ErrInvalidMessageSize = errors.New("Invalid message size") // ErrByteOrderNotSet byter order is set on the first read ErrByteOrderNotSet = errors.New("Byte order not set") )
var NativeEndian = binary.LittleEndian
NativeEndian system native byte order
Functions ¶
func Decode ¶
Decode parses the incoming JSON-encoded data and stores the result in the value pointed to by v. The leading first 4 bytes of the data is interpreted as a 32-bit unsigned integer encoded in the specified byte order
func Encode ¶
Encode writes to io.Writer the json encoded data of the given value The data is preceded with a 32-bit unsigned integer data length in the specified byte order
Types ¶
type JSONDecoder ¶
type JSONDecoder interface {
Decode(interface{}) error
}
JSONDecoder reads and decodes JSON values from an input stream.
func NewJSONDecoder ¶
func NewJSONDecoder(r io.Reader, bo binary.ByteOrder) JSONDecoder
NewJSONDecoder returns a new jsonDecoder that reads from the given io.Reader interpreting the first 4 bytes as 32-bit data length in the specified byte order
func NewNativeJSONDecoder ¶
func NewNativeJSONDecoder(r io.Reader) JSONDecoder
NewNativeJSONDecoder returns a new jsonDecoder that reads from the given io.Reader interpreting the first 4 bytes as 32-bit data length in native byte order
type JSONEncoder ¶
type JSONEncoder interface {
Encode(interface{}) error
}
JSONEncoder writes JSON values to an output stream.
func NewJSONEncoder ¶
func NewJSONEncoder(w io.Writer, bo binary.ByteOrder) JSONEncoder
NewJSONEncoder returns a new jsonEncoder that write to the given io.Writer The data is preceded with 32-bit data length in the specified byte order
func NewNativeJSONEncoder ¶
func NewNativeJSONEncoder(w io.Writer) JSONEncoder
NewNativeJSONEncoder returns a new jsonEncoder that writes to the given io.Writer The data is preceded with 32-bit data length in native byte order
type Reader ¶
type Reader interface { // Read reads bytes from an io.Reader. // It returns the bytes read and an error from the read operation. // Read may return io.EOF when the underlying stream reach the end or is closed Read() ([]byte, error) }
Reader is an interface that wraps the Read method.
func NewNativeReader ¶
NewNativeReader returns a new reader that reads from the given io.Reader interpreting the first 4 bytes as 32-bit data length in native byte order
type Writer ¶
type Writer interface { // Write writes bytes from the given io.Reader to the underlying io.Writer // It returns the number of bytes from io.Reader and any error from the write operation. Write(io.Reader) (int, error) }
Writer is an interface that wraps the Write method.
func NewNativeWriter ¶
NewNativeWriter returns a new writer that writes to the given io.Writer The data is preceded with 32-bit data length in native byte order