Documentation ¶
Overview ¶
Package marshal implements binary encoder and decoder for GQL values.
Index ¶
- func ReleaseDecoder(dec *Decoder)
- func ReleaseEncoder(enc *Encoder) []byte
- type Decoder
- func (d *Decoder) Bool() bool
- func (d *Decoder) Byte() byte
- func (d *Decoder) Bytes() []byte
- func (d *Decoder) GOB(val interface{})
- func (d *Decoder) Hash() hash.Hash
- func (d *Decoder) Len() int
- func (d *Decoder) RawBytes(data []byte)
- func (d *Decoder) Reset(data []byte)
- func (d *Decoder) String() string
- func (d *Decoder) Symbol() string
- func (d *Decoder) Uint64() uint64
- func (d *Decoder) Varint() int64
- type Encoder
- func (e *Encoder) Bytes() []byte
- func (e *Encoder) Len() int
- func (e *Encoder) PutBool(b bool)
- func (e *Encoder) PutByte(b byte)
- func (e *Encoder) PutBytes(data []byte)
- func (e *Encoder) PutGOB(val interface{})
- func (e *Encoder) PutHash(h hash.Hash)
- func (e *Encoder) PutRawBytes(data []byte)
- func (e *Encoder) PutString(data string)
- func (e *Encoder) PutSymbol(id string)
- func (e *Encoder) PutUint64(v uint64)
- func (e *Encoder) PutVarint(v int64)
- func (e *Encoder) Reset(buf []byte)
- func (e *Encoder) Write(data []byte) (int, error)
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 ¶
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 ¶
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) 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) RawBytes ¶
RawBytes reads a byte slice from the decoder. It crashes the process if the decoder stores less than len(data) bytes.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder serializes GQL values.
func NewEncoder ¶
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) PutGOB ¶
func (e *Encoder) PutGOB(val interface{})
PutGOB encodes an arbitrary value using GOB.
func (*Encoder) PutRawBytes ¶
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) PutSymbol ¶
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) Reset ¶
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.