encoding

package
v0.0.0-...-2a19a5d Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

v2 encoding, this will replace the reflect based one earlier

Index

Constants

View Source
const (
	Bits           = Size(1)
	Bytes          = Size(8)
	RemainingBytes = Size(-1)
)

Variables

View Source
var (
	Uint8  = &Unsigned{8 * Bits}
	Uint16 = &Unsigned{16 * Bits}
	Uint32 = &Unsigned{32 * Bits}
	Uint64 = &Unsigned{64 * Bits}
)

Functions

func Generate

func Generate(pkg string, imports []string, ts ...Type) ([]byte, error)

func ReadFrom

func ReadFrom(r io.Reader, f interface{}) (int64, error)

Reads a fibrechannel package annotated structure from the io.Reader If fed a structure that does not have any `fc` tags it will do nothing

func ReadFromAndPost

func ReadFromAndPost(r io.Reader, f postUnmarshaller) (int64, error)

func WriteTo

func WriteTo(w io.Writer, f interface{}) (int64, error)

Writes a fibrechannel package annotated structure to the io.Writer If fed a structure that does not have any `fc` tags it will do nothing

func WriteToAndPre

func WriteToAndPre(w io.Writer, f preMarshaller) (int64, error)

Types

type Array

type Array struct {
	Count int
	Type  Type
}

func (*Array) Consts

func (t *Array) Consts() []NamedConstant

func (*Array) Deser

func (t *Array) Deser(p Context, m string) ([]Statement, error)

func (*Array) FindReference

func (t *Array) FindReference(needle interface{}) string

func (*Array) Functions

func (t *Array) Functions() []Function

func (*Array) PreSer

func (t *Array) PreSer(p Context, m string) ([]Statement, error)

func (*Array) Ser

func (t *Array) Ser(p Context, m string) ([]Statement, error)

func (*Array) TypeDefs

func (t *Array) TypeDefs() []TypeDef

func (*Array) TypeName

func (t *Array) TypeName() string

type BitStruct

type BitStruct struct {
	Name string
	// contains filtered or unexported fields
}

func NewBitStruct

func NewBitStruct(n string) *BitStruct

func (*BitStruct) BoolBit

func (t *BitStruct) BoolBit(n string) *bitfield

func (*BitStruct) Consts

func (t *BitStruct) Consts() []NamedConstant

func (*BitStruct) Deser

func (t *BitStruct) Deser(p Context, m string) ([]Statement, error)

func (*BitStruct) FindReference

func (t *BitStruct) FindReference(needle interface{}) string

func (*BitStruct) Functions

func (t *BitStruct) Functions() []Function

func (*BitStruct) IntField

func (t *BitStruct) IntField(n string, bits int) *bitfield

func (*BitStruct) PreSer

func (t *BitStruct) PreSer(p Context, m string) ([]Statement, error)

func (*BitStruct) Ser

func (t *BitStruct) Ser(p Context, m string) ([]Statement, error)

func (*BitStruct) SkipBit

func (t *BitStruct) SkipBit(n int)

func (*BitStruct) TypeDefs

func (t *BitStruct) TypeDefs() []TypeDef

func (*BitStruct) TypeName

func (t *BitStruct) TypeName() string

type ByteArray

type ByteArray struct {
	Count int
}

func (*ByteArray) Consts

func (t *ByteArray) Consts() []NamedConstant

func (*ByteArray) Deser

func (t *ByteArray) Deser(p Context, m string) ([]Statement, error)

func (*ByteArray) FindReference

func (t *ByteArray) FindReference(interface{}) string

func (*ByteArray) Functions

func (t *ByteArray) Functions() []Function

func (*ByteArray) PreSer

func (t *ByteArray) PreSer(p Context, m string) ([]Statement, error)

func (*ByteArray) Ser

func (t *ByteArray) Ser(p Context, m string) ([]Statement, error)

func (*ByteArray) TypeDefs

func (t *ByteArray) TypeDefs() []TypeDef

func (*ByteArray) TypeName

func (t *ByteArray) TypeName() string

type Constant

type Constant struct {
	Value   int
	Comment string
}

type Context

type Context interface {
	FindReference(interface{}) string
}

Context is used to bind dependent parts of the structures together

type Enum

type Enum struct {
	Name   string
	Size   Size
	Values map[string]Constant
}

func (*Enum) Consts

func (t *Enum) Consts() []NamedConstant

func (*Enum) Deser

func (t *Enum) Deser(p Context, m string) ([]Statement, error)

func (*Enum) FindReference

func (t *Enum) FindReference(interface{}) string

func (*Enum) Functions

func (t *Enum) Functions() []Function

func (*Enum) PreSer

func (t *Enum) PreSer(p Context, m string) ([]Statement, error)

func (*Enum) Ser

func (t *Enum) Ser(p Context, m string) ([]Statement, error)

func (*Enum) TypeDefs

func (t *Enum) TypeDefs() []TypeDef

func (*Enum) TypeName

func (t *Enum) TypeName() string

type Field

type Field struct {
	Name   string
	Type   Type
	Parent *Struct
}

type Function

type Function string

type NamedConstant

type NamedConstant struct {
	Name   string
	Domain string
	Constant
}

type Object

type Object struct {
	Class string
}

func (*Object) Consts

func (t *Object) Consts() []NamedConstant

func (*Object) Deser

func (t *Object) Deser(p Context, m string) ([]Statement, error)

func (*Object) FindReference

func (t *Object) FindReference(interface{}) string

func (*Object) Functions

func (t *Object) Functions() []Function

func (*Object) PreSer

func (t *Object) PreSer(p Context, m string) ([]Statement, error)

func (*Object) Ser

func (t *Object) Ser(p Context, m string) ([]Statement, error)

func (*Object) TypeDefs

func (t *Object) TypeDefs() []TypeDef

func (*Object) TypeName

func (t *Object) TypeName() string

type Reader

type Reader struct {
	R     io.Reader
	Error error
	Pos   int64
}

func (*Reader) Read

func (r *Reader) Read(b []byte) (int, error)

func (*Reader) ReadObject

func (r *Reader) ReadObject(v interface{})

func (*Reader) Skip

func (r *Reader) Skip(n int)

type Size

type Size int

type Skip

type Skip struct {
	Size Size
}

func (*Skip) Consts

func (t *Skip) Consts() []NamedConstant

func (*Skip) Deser

func (t *Skip) Deser(p Context, m string) ([]Statement, error)

func (*Skip) FindReference

func (t *Skip) FindReference(interface{}) string

func (*Skip) Functions

func (t *Skip) Functions() []Function

func (*Skip) PreSer

func (t *Skip) PreSer(p Context, m string) ([]Statement, error)

func (*Skip) Ser

func (t *Skip) Ser(p Context, m string) ([]Statement, error)

func (*Skip) TypeDefs

func (t *Skip) TypeDefs() []TypeDef

func (*Skip) TypeName

func (t *Skip) TypeName() string

type Statement

type Statement string

type Struct

type Struct struct {
	Name   string
	Fields []*Field
}

func NewStruct

func NewStruct(n string) *Struct

func (*Struct) Consts

func (t *Struct) Consts() []NamedConstant

func (*Struct) Deser

func (t *Struct) Deser(p Context, m string) ([]Statement, error)

func (*Struct) Field

func (t *Struct) Field(n string, ty Type) *Field

func (*Struct) FindReference

func (t *Struct) FindReference(needle interface{}) string

func (*Struct) Functions

func (t *Struct) Functions() []Function

func (*Struct) PreSer

func (t *Struct) PreSer(p Context, m string) ([]Statement, error)

func (*Struct) Ser

func (t *Struct) Ser(p Context, m string) ([]Statement, error)

func (*Struct) TypeDefs

func (t *Struct) TypeDefs() []TypeDef

func (*Struct) TypeName

func (t *Struct) TypeName() string

type SwitchedType

type SwitchedType struct {
	Name       string
	Size       Size
	SwitchedOn interface{}
	Cases      map[string]Type
}

func (*SwitchedType) Consts

func (t *SwitchedType) Consts() []NamedConstant

func (*SwitchedType) Deser

func (t *SwitchedType) Deser(p Context, m string) ([]Statement, error)

func (*SwitchedType) FindReference

func (t *SwitchedType) FindReference(interface{}) string

func (*SwitchedType) Functions

func (t *SwitchedType) Functions() []Function

func (*SwitchedType) PreSer

func (t *SwitchedType) PreSer(p Context, m string) ([]Statement, error)

func (*SwitchedType) Ser

func (t *SwitchedType) Ser(p Context, m string) ([]Statement, error)

func (*SwitchedType) TypeDefs

func (t *SwitchedType) TypeDefs() []TypeDef

func (*SwitchedType) TypeName

func (t *SwitchedType) TypeName() string

type Type

type Type interface {
	TypeName() string
	Consts() []NamedConstant
	TypeDefs() []TypeDef
	Functions() []Function
	Deser(p Context, m string) ([]Statement, error)
	PreSer(p Context, m string) ([]Statement, error)
	Ser(p Context, m string) ([]Statement, error)
	Context
}

type TypeDef

type TypeDef string

type Unsigned

type Unsigned struct {
	Size Size
}

func (*Unsigned) Consts

func (t *Unsigned) Consts() []NamedConstant

func (*Unsigned) Deser

func (t *Unsigned) Deser(p Context, m string) ([]Statement, error)

func (*Unsigned) FindReference

func (t *Unsigned) FindReference(interface{}) string

func (*Unsigned) Functions

func (t *Unsigned) Functions() []Function

func (*Unsigned) PreSer

func (t *Unsigned) PreSer(p Context, m string) ([]Statement, error)

func (*Unsigned) Ser

func (t *Unsigned) Ser(p Context, m string) ([]Statement, error)

func (*Unsigned) TypeDefs

func (t *Unsigned) TypeDefs() []TypeDef

func (*Unsigned) TypeName

func (t *Unsigned) TypeName() string

type Writer

type Writer struct {
	W     io.Writer
	Error error
	Pos   int64
}

func (*Writer) Skip

func (w *Writer) Skip(n int)

func (*Writer) Write

func (w *Writer) Write(b []byte) (int, error)

func (*Writer) WriteObject

func (w *Writer) WriteObject(v interface{})

Jump to

Keyboard shortcuts

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