marshal

package
v0.0.0-...-9d3c4bc Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package marshal implements binary encoder and decoder for GQL values.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReleaseDecoder

func ReleaseDecoder(dec *Decoder)

ReleaseDecoder releases the decoder into the freepool.

func ReleaseEncoder

func ReleaseEncoder(enc *Encoder) []byte

ReleaseEncoder releases the encoder into the freepool. It returns value of enc.Bytes().

Types

type Decoder

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

Decoder is used to decode GQL values.

func NewDecoder

func NewDecoder(data []byte) *Decoder

NewDecoder creates a Decoder that reads from the given bytes. The caller should call ReleaseDecoder() after use. The ReleaseDecoder call is optional, but it will save memory allocation.

func (*Decoder) Bool

func (d *Decoder) Bool() bool

Bool reads a bool from the decoder. Crashes the process on error.

func (*Decoder) Byte

func (d *Decoder) Byte() byte

Byte reads a byte from the decoder. Crashes the process on error.

func (*Decoder) Bytes

func (d *Decoder) Bytes() []byte

Bytes reads data encoded by Encoder.PutBytes.

func (*Decoder) GOB

func (d *Decoder) GOB(val interface{})

GOB reads an arbitrary value using GOB. The val should be a pointer to an object.

func (*Decoder) Hash

func (d *Decoder) Hash() hash.Hash

Hash reads a Hash object from the decoder.

func (*Decoder) Len

func (d *Decoder) Len() int

Len returns the number of bytes that remains to be read.

func (*Decoder) RawBytes

func (d *Decoder) RawBytes(data []byte)

RawBytes reads a byte slice from the decoder. It crashes the process if the decoder stores less than len(data) bytes.

func (*Decoder) Reset

func (d *Decoder) Reset(data []byte)

func (*Decoder) String

func (d *Decoder) String() string

Bytes reads data encoded by Encoder.PutString.

func (*Decoder) Symbol

func (d *Decoder) Symbol() string

Symbol decodes a symbol encoded by Encoder.PutSymbol.

func (*Decoder) Uint64

func (d *Decoder) Uint64() uint64

Uint64 reads an uint64. Crashes the process on error.

func (*Decoder) Varint

func (d *Decoder) Varint() int64

Varint reads an int64. Crashes the process on error.

type Encoder

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

Encoder serializes GQL values.

func NewEncoder

func NewEncoder(buf []byte) *Encoder

NewEncoder creates a new empty encoder. If buf!=nil, the encoder takes ownership of the buffer and appends to the buffer (the buffer will be reallocated if it turns out to be too small for the encode data). If buf=nil, the encoder allocates a new buffer.

The caller should call ReleaseEncoder() after use. The ReleaseEncoder call is optional, but it will save memory allocation.

Example:

buf := make([]byte, 128)
for {
   enc := marshal.NewEncoder(buf[:0])
   enc.Write([]byte("foohah"))
   serialized := marshal.ReleaseDecoder(enc)
   ... use serialized ...
}

func (*Encoder) Bytes

func (e *Encoder) Bytes() []byte

Bytes returns the encoded data.

func (*Encoder) Len

func (e *Encoder) Len() int

Len returns the size of the encoded data.

func (*Encoder) PutBool

func (e *Encoder) PutBool(b bool)

PutBool adds a bool to the buffer.

func (*Encoder) PutByte

func (e *Encoder) PutByte(b byte)

PutByte adds a byte to the buffer.

func (*Encoder) PutBytes

func (e *Encoder) PutBytes(data []byte)

PutBytes adds data to the buffer. It encodes the data length.

func (*Encoder) PutGOB

func (e *Encoder) PutGOB(val interface{})

PutGOB encodes an arbitrary value using GOB.

func (*Encoder) PutHash

func (e *Encoder) PutHash(h hash.Hash)

PutHash adds a Hash object to the buffer.

func (*Encoder) PutRawBytes

func (e *Encoder) PutRawBytes(data []byte)

PutRawBytes adds the given data to the buffer. It does not encode the data length, so the reader must know the data size beforehand.

func (*Encoder) PutString

func (e *Encoder) PutString(data string)

PutString adds string to the buffer.

func (*Encoder) PutSymbol

func (e *Encoder) PutSymbol(id string)

PutSymbol adds a symbol to the stream. Symbols are expected to be repeated and are interned as integers into the stream. The encoder maintains a table of symbols.

func (*Encoder) PutUint64

func (e *Encoder) PutUint64(v uint64)

PutUint64 adds an uint64 to the buffer.

func (*Encoder) PutVarint

func (e *Encoder) PutVarint(v int64)

PutVarint adds an int64.

func (*Encoder) Reset

func (e *Encoder) Reset(buf []byte)

Reset resets the object so that it can be used for another round of encoding. If buf!=nil, the encoder takes ownership of the buffer and appends to the buffer (the buffer will be reallocated if it turns out to be too small for the encode data). If buf=nil, the encoder allocates a new buffer.

func (*Encoder) Write

func (e *Encoder) Write(data []byte) (int, error)

Write implements io.Writer interface

Jump to

Keyboard shortcuts

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