fields

package
v0.0.0-...-738e6fc Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package fields implements wire format decoding and encoding.

This package does bitwise wire format decoding and encoding with reflection and struct tag of golang.

Encoder.Encode() and Decoder.Decode() recognize "field" struct tags. the "field" struct tags are in the form of `field:"spec:value,spec,spec"`. All structs used must be byte-aligned.

Specs currently are:

bits

"bits" spec can only be used on integer fields, specifying the length of this field, in bits. This spec must come with a integer value.

limit

"limit" spec can only be used on unsigned integer fields. There can only be at most one field in a struct tagged by "limit". The value of the field tagged by "limit" is the length of content in the struct after this field, in “bytes”. This spec must come with no value.

lenbits

"lenbits" spec can only be used on slice and string fields, specifying the bit length of the length. Slices and strings are encoded as "length followed by content". This spec must come with a integer value.

zlib

"zlib" spec specifying this field is compressed by zlib. It can only be used on the last slice field of a struct, which must have a "limit" field before "zlib" field. Empty "zlib" slice field is omitted completely. This spec must come with no value.

-

"-" spec marks a field as omitted explictly.

Data types supported are:

  1. All integer types(int, int16, uint, etc.)
  2. string
  3. slice of 4
  4. struct contains unomitted fileds of type 1 2 3 4

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DecodeFunc

type DecodeFunc func(*Decoder, reflect.Value, *fieldInfo) error

type Decoder

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

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) (err error)

func (*Decoder) IsClean

func (d *Decoder) IsClean() bool

func (*Decoder) Read

func (d *Decoder) Read(data []byte) (int, error)

func (*Decoder) ReadBits

func (d *Decoder) ReadBits(count int) (n uint32, err error)

func (*Decoder) SetZlibDict

func (d *Decoder) SetZlibDict(dict []byte)

type EncodeFunc

type EncodeFunc func(*Encoder, reflect.Value, *fieldInfo) error

type Encoder

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

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) (err error)

func (*Encoder) IsClean

func (e *Encoder) IsClean() bool

func (*Encoder) SetZlibDict

func (e *Encoder) SetZlibDict(dict []byte)

func (*Encoder) Write

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

func (*Encoder) WriteBits

func (e *Encoder) WriteBits(count int, n uint32) (err error)

type SpecError

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

func (SpecError) Error

func (e SpecError) Error() string

Jump to

Keyboard shortcuts

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