encoder

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package encoder provides a lower level encoding subsystem to translate Go struct-based Hermod units into their inter-compatible platform-agnostic binary forms.

You usually don't want to use any of the functions provided here directly. Instead, the code generated by the Hermod compiler creates convenient pre-typed wrappers that reference these functions, with support for encoding and decoding any of the units you've created. Furthermore, the service package will automatically handle encoding and decoding any units you specify as input/outputs in endpoints.

Index

Constants

View Source
const False = Boolean(0x00)
View Source
const True = Boolean(0xff)

Variables

This section is empty.

Functions

func Add16ToSlice added in v0.2.0

func Add16ToSlice(number uint16, slice *[]byte) *[]byte

func Add32ToSlice added in v0.2.0

func Add32ToSlice(number uint32, slice *[]byte) *[]byte

func Add64ToSlice added in v0.2.0

func Add64ToSlice(number uint64, slice *[]byte) *[]byte

func EncodeUnit

func EncodeUnit(unit *FilledUnit) (*[]byte, error)

EncodeUnit converts a Unit into a Hermod-encoded byte slice. [2 bytes transmission ID] then for each field value: [2 bytes field ID] [4 bytes content length in bytes (n)] [n bytes content]

func SliceToU16 added in v0.2.0

func SliceToU16(slice []byte) uint16

func SliceToU32 added in v0.2.0

func SliceToU32(slice []byte) uint32

func SliceToU64 added in v0.2.0

func SliceToU64(slice []byte) uint64

func UserEncode

func UserEncode(u UserFacingHermodUnit) (*[]byte, error)

Types

type BigInteger

type BigInteger uint64

type BigSignedInteger

type BigSignedInteger int64

type Boolean

type Boolean uint8

type Field

type Field struct {
	Name     string
	FieldId  uint16
	Type     reflect.Value
	Extended bool // if true, increases maximum value length to 2^64 bytes. otherwise, limit is 2^36 bytes.
	Repeated bool // if true, allows multiple values in the style of a list
}

Field is the full definition of a field contained within a unit, as contained inside the YAML file used to define Hermod units.

type FieldValue

type FieldValue struct {
	ParentUnit *FilledUnit
	Value      interface{}
}

FieldValue is used in FilledUnit to denote the specific user-provided value of a field.

type FilledUnit

type FilledUnit struct {
	*Unit
	Values map[Field]FieldValue
}

FilledUnit is like a unit but with the values for each of the fields also added.

func DecodeUnit

func DecodeUnit(_rawUnit *[]byte, unit Unit) (*FilledUnit, error)

DecodeUnit attempts (blindly) to decode a Hermod-encoded byte slice into a FilledUnit Errors are returned only for content issues. Structural issues may cause unexpected behaviour, panics, or even infinite loops!

func UserToFilledUnit

func UserToFilledUnit(u UserFacingHermodUnit) (*FilledUnit, error)

type Integer

type Integer uint32

type SignedInteger

type SignedInteger int32

type SmallInteger

type SmallInteger uint16

type SmallSignedInteger

type SmallSignedInteger int16

type String

type String string

type TinyInteger

type TinyInteger uint8

type TinySignedInteger

type TinySignedInteger int8

type Unit

type Unit struct {
	Name           string // a user-readable debug name for this Unit
	TransmissionId uint16 // a unique identifier for this Unit within scope
	Fields         []Field
}

Unit is essentially what's contained inside the YAML file used to defined Hermod units. It contains full definitions like the unit's name and all its fields.

type UserFacingHermodUnit

type UserFacingHermodUnit interface {
	GetDefinition() *Unit
	DecodeAbstract(data *[]byte) (UserFacingHermodUnit, error)
}

UserFacingHermodUnit is what the end user of generated Hermod code actually sees. It also contains some functions that are intended for the Hermod encoder.

func FilledUnitToUser

func FilledUnitToUser(filledUnit *FilledUnit, u UserFacingHermodUnit) (UserFacingHermodUnit, error)

func UserDecode

func UserDecode(u UserFacingHermodUnit, data *[]byte) (UserFacingHermodUnit, error)

Jump to

Keyboard shortcuts

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