Documentation
¶
Index ¶
- Constants
- func Marshal(v any) ([]byte, error)
- func Unmarshal(data []byte, v any) error
- func Valid(data []byte) bool
- func Validate(data []byte) error
- type Decoder
- type Encoder
- func (e *Encoder) Bytes() []byte
- func (e *Encoder) RawWrite(data []byte)
- func (e *Encoder) RawWriteByte(data byte)
- func (e *Encoder) RawWriteUint16(v uint16)
- func (e *Encoder) RawWriteUint32(v uint32)
- func (e *Encoder) RawWriteUint64(v uint64)
- func (e *Encoder) Reset()
- func (e *Encoder) WriteBool(v bool)
- func (e *Encoder) WriteBoolVec(v []bool)
- func (e *Encoder) WriteBytes(v []byte)
- func (e *Encoder) WriteF32(v float32)
- func (e *Encoder) WriteF32Vec(v []float32)
- func (e *Encoder) WriteF64(v float64)
- func (e *Encoder) WriteF64Vec(v []float64)
- func (e *Encoder) WriteI8(v int8)
- func (e *Encoder) WriteI8Vec(v []int8)
- func (e *Encoder) WriteI16(v int16)
- func (e *Encoder) WriteI16Vec(v []int16)
- func (e *Encoder) WriteI32(v int32)
- func (e *Encoder) WriteI32Vec(v []int32)
- func (e *Encoder) WriteI64(v int64)
- func (e *Encoder) WriteI64Vec(v []int64)
- func (e *Encoder) WriteInt(v int64)
- func (e *Encoder) WriteListEnd()
- func (e *Encoder) WriteListStart()
- func (e *Encoder) WriteNil()
- func (e *Encoder) WriteNop()
- func (e *Encoder) WriteString(s string)
- func (e *Encoder) WriteStructEnd()
- func (e *Encoder) WriteStructStart()
- func (e *Encoder) WriteTag(t TypeCode, s SizeCode)
- func (e *Encoder) WriteU8(v uint8)
- func (e *Encoder) WriteU8Vec(v []uint8)
- func (e *Encoder) WriteU16(v uint16)
- func (e *Encoder) WriteU16Vec(v []uint16)
- func (e *Encoder) WriteU32(v uint32)
- func (e *Encoder) WriteU32Vec(v []uint32)
- func (e *Encoder) WriteU64(v uint64)
- func (e *Encoder) WriteU64Vec(v []uint64)
- func (e *Encoder) WriteUint(v uint64)
- func (e *Encoder) WriteVectorPrefix(t TypeCode, count int)
- type InvalidUnmarshalError
- type LtvDesc
- type LtvElementDesc
- type LtvElementRole
- type LtvEncoder
- type Marshaler
- type MarshalerError
- type SizeCode
- type StreamDecoder
- func (s *StreamDecoder) Next() (LtvElementDesc, error)
- func (s *StreamDecoder) Read(buf []byte) (int, error)
- func (s *StreamDecoder) ReadByte() (byte, error)
- func (s *StreamDecoder) ReadFull(buf []byte) error
- func (s *StreamDecoder) ReadValue(d LtvElementDesc) (any, error)
- func (s *StreamDecoder) Skip(d LtvElementDesc) error
- func (s *StreamDecoder) SkipValue(d LtvElementDesc) error
- func (s *StreamDecoder) ValidateAndSkip(d LtvElementDesc) error
- func (s *StreamDecoder) Value() (any, error)
- type StreamEncoder
- func (e *StreamEncoder) RawWrite(b []byte)
- func (e *StreamEncoder) RawWriteByte(v byte)
- func (e *StreamEncoder) RawWriteUint16(v uint16)
- func (e *StreamEncoder) RawWriteUint32(v uint32)
- func (e *StreamEncoder) RawWriteUint64(v uint64)
- func (e *StreamEncoder) Reset()
- func (e *StreamEncoder) SetOffset(offset int)
- func (e *StreamEncoder) WriteBool(v bool)
- func (e *StreamEncoder) WriteBoolVec(v []bool)
- func (e *StreamEncoder) WriteBytes(v []byte)
- func (e *StreamEncoder) WriteF32(v float32)
- func (e *StreamEncoder) WriteF32Vec(v []float32)
- func (e *StreamEncoder) WriteF64(v float64)
- func (e *StreamEncoder) WriteF64Vec(v []float64)
- func (e *StreamEncoder) WriteI8(v int8)
- func (e *StreamEncoder) WriteI8Vec(v []int8)
- func (e *StreamEncoder) WriteI16(v int16)
- func (e *StreamEncoder) WriteI16Vec(v []int16)
- func (e *StreamEncoder) WriteI32(v int32)
- func (e *StreamEncoder) WriteI32Vec(v []int32)
- func (e *StreamEncoder) WriteI64(v int64)
- func (e *StreamEncoder) WriteI64Vec(v []int64)
- func (e *StreamEncoder) WriteInt(v int64)
- func (e *StreamEncoder) WriteListEnd()
- func (e *StreamEncoder) WriteListStart()
- func (e *StreamEncoder) WriteNil()
- func (e *StreamEncoder) WriteNop()
- func (e *StreamEncoder) WriteString(s string)
- func (e *StreamEncoder) WriteStructEnd()
- func (e *StreamEncoder) WriteStructStart()
- func (e *StreamEncoder) WriteTag(t TypeCode, s SizeCode)
- func (e *StreamEncoder) WriteU8(v uint8)
- func (e *StreamEncoder) WriteU8Vec(v []uint8)
- func (e *StreamEncoder) WriteU16(v uint16)
- func (e *StreamEncoder) WriteU16Vec(v []uint16)
- func (e *StreamEncoder) WriteU32(v uint32)
- func (e *StreamEncoder) WriteU32Vec(v []uint32)
- func (e *StreamEncoder) WriteU64(v uint64)
- func (e *StreamEncoder) WriteU64Vec(v []uint64)
- func (e *StreamEncoder) WriteUint(v uint64)
- func (e *StreamEncoder) WriteVectorPrefix(t TypeCode, count int)
- type StructEncoder
- func (s StructEncoder) Bool(key string, v bool)
- func (s StructEncoder) BoolVec(key string, v []bool)
- func (s StructEncoder) Bytes(key string, v []byte)
- func (s StructEncoder) EndStruct()
- func (s StructEncoder) F32Vec(key string, v []float32)
- func (s StructEncoder) F64Vec(key string, v []float64)
- func (s StructEncoder) I8(key string, v int8)
- func (s StructEncoder) I8Vec(key string, v []int8)
- func (s StructEncoder) I16(key string, v int16)
- func (s StructEncoder) I16Vec(key string, v []int16)
- func (s StructEncoder) I32(key string, v int32)
- func (s StructEncoder) I32Vec(key string, v []int32)
- func (s StructEncoder) I64(key string, v int64)
- func (s StructEncoder) I64Vec(key string, v []int64)
- func (s StructEncoder) Int(key string, v int64)
- func (s StructEncoder) Nil(key string)
- func (s StructEncoder) StartStruct()
- func (s StructEncoder) String(key string, v string)
- func (s StructEncoder) U8(key string, v uint8)
- func (s StructEncoder) U8Vec(key string, v []uint8)
- func (s StructEncoder) U16(key string, v uint16)
- func (s StructEncoder) U16Vec(key string, v []uint16)
- func (s StructEncoder) U32(key string, v uint32)
- func (s StructEncoder) U32Vec(key string, v []uint32)
- func (s StructEncoder) U64(key string, v uint64)
- func (s StructEncoder) U64Vec(key string, v []uint64)
- func (s StructEncoder) Uint(key string, v uint64)
- type TypeCode
- type UnmarshalTypeError
- type Unmarshaler
- type UnsupportedTypeError
- type UnsupportedValueError
Examples ¶
Constants ¶
const MaxNestingDepth = 10000
Maximum that structs/arrays can be nested in this library.
const NopTag byte = 0xFF
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
Example ¶
type ColorGroup struct {
ID int
Name string
Colors []string
}
group := ColorGroup{
ID: 1,
Name: "Reds",
Colors: []string{"Crimson", "Red", "Ruby", "Maroon"},
}
b, err := Marshal(group)
if err != nil {
fmt.Println("error:", err)
}
fmt.Println(hex.EncodeToString(b))
Output: 1041024944a00141044e616d654104526564734106436f6c6f72732041074372696d736f6e410352656441045275627941064d61726f6f6e3030
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A LiteVector buffer decoder
func NewDecoder ¶
func (*Decoder) Next ¶
Read the next tag or tag and length prefix from the stream. On return, the scanner will be positioned over the value.
func (*Decoder) ReadValue ¶
Read a single (generic) value from a data stream based on the given descriptor.
func (*Decoder) ValidateAndSkip ¶
Skip the value currently under the scanner with additional validation checks.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
func NewEncoder ¶
func NewEncoder() *Encoder
func (*Encoder) Bytes ¶
Return the underlying buffer. This is only valid until the next buffer modification. Callers that want to hold onto this value should make a copy.
func (*Encoder) RawWriteByte ¶
func (*Encoder) RawWriteUint16 ¶
Passthrough write Uint16 endian corrected
func (*Encoder) RawWriteUint32 ¶
Passthrough write Uint32, endian corrected
func (*Encoder) RawWriteUint64 ¶
Passthrough write Uint64, endian corrected
func (*Encoder) WriteBoolVec ¶
func (*Encoder) WriteBytes ¶
func (*Encoder) WriteF32Vec ¶
func (*Encoder) WriteF64Vec ¶
func (*Encoder) WriteI8Vec ¶
func (*Encoder) WriteI16Vec ¶
func (*Encoder) WriteI32Vec ¶
func (*Encoder) WriteI64Vec ¶
func (*Encoder) WriteListEnd ¶
func (e *Encoder) WriteListEnd()
func (*Encoder) WriteListStart ¶
func (e *Encoder) WriteListStart()
func (*Encoder) WriteString ¶
func (*Encoder) WriteStructEnd ¶
func (e *Encoder) WriteStructEnd()
func (*Encoder) WriteStructStart ¶
func (e *Encoder) WriteStructStart()
func (*Encoder) WriteU8Vec ¶
func (*Encoder) WriteU16Vec ¶
func (*Encoder) WriteU32Vec ¶
func (*Encoder) WriteU64Vec ¶
func (*Encoder) WriteVectorPrefix ¶
Write the tag and length for a typed vector.
type InvalidUnmarshalError ¶
An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)
func (*InvalidUnmarshalError) Error ¶
func (e *InvalidUnmarshalError) Error() string
type LtvElementDesc ¶
type LtvElementDesc struct {
Tag byte
TypeCode TypeCode
SizeCode SizeCode
Length uint64
TagOffset int
ValueOffset int
Role LtvElementRole
FirstElement bool
Depth int
}
A LiteVector element descriptor
type LtvElementRole ¶
type LtvElementRole int
const ( RoleValue LtvElementRole = iota RoleListEnd RoleStructEnd RoleStructKey RoleStructValue )
type LtvEncoder ¶
type LtvEncoder interface {
WriteNop()
WriteNil()
WriteStructStart()
WriteStructEnd()
WriteListStart()
WriteListEnd()
WriteBool(bool)
WriteU8(uint8)
WriteU16(uint16)
WriteU32(uint32)
WriteU64(uint64)
WriteI8(int8)
WriteI16(int16)
WriteI32(int32)
WriteI64(int64)
WriteF32(float32)
WriteF64(float64)
WriteInt(int64)
WriteUint(uint64)
WriteString(string)
WriteBytes([]byte)
WriteBoolVec([]bool)
WriteU8Vec([]uint8)
WriteU16Vec([]uint16)
WriteU32Vec([]uint32)
WriteU64Vec([]uint64)
WriteI8Vec([]int8)
WriteI16Vec([]int16)
WriteI32Vec([]int32)
WriteI64Vec([]int64)
WriteF32Vec([]float32)
WriteF64Vec([]float64)
}
A interface for a generic LiteVector encoder
type MarshalerError ¶
type MarshalerError struct {
Type reflect.Type
Err error
// contains filtered or unexported fields
}
A MarshalerError represents an error from calling a MarshalLTV or MarshalText method.
func (*MarshalerError) Error ¶
func (e *MarshalerError) Error() string
func (*MarshalerError) Unwrap ¶
func (e *MarshalerError) Unwrap() error
Unwrap returns the underlying error.
type StreamDecoder ¶
type StreamDecoder struct {
// If set to true, will return NOP tags.
ReturnNops bool
// The maximum length supported by the ReadValue function
MaxValueLength uint64
// contains filtered or unexported fields
}
func NewStreamDecoder ¶
func NewStreamDecoder(r io.Reader) *StreamDecoder
func (*StreamDecoder) Next ¶
func (s *StreamDecoder) Next() (LtvElementDesc, error)
Read the next tag or tag and length prefix from the stream. On return, the scanner will be positioned over the value.
func (*StreamDecoder) Read ¶
func (s *StreamDecoder) Read(buf []byte) (int, error)
Read into buffer from the underlying stream.
func (*StreamDecoder) ReadByte ¶
func (s *StreamDecoder) ReadByte() (byte, error)
Read a byte from the underlying stream and return the byte or error.
func (*StreamDecoder) ReadFull ¶
func (s *StreamDecoder) ReadFull(buf []byte) error
Read the full size of the buffer from the underlying stream.
func (*StreamDecoder) ReadValue ¶
func (s *StreamDecoder) ReadValue(d LtvElementDesc) (any, error)
Read a single (generic) value from a data stream based on the passed descriptor.
func (*StreamDecoder) Skip ¶
func (s *StreamDecoder) Skip(d LtvElementDesc) error
Skip the value currently under the scanner
func (*StreamDecoder) SkipValue ¶
func (s *StreamDecoder) SkipValue(d LtvElementDesc) error
Skip the value of a tag
func (*StreamDecoder) ValidateAndSkip ¶
func (s *StreamDecoder) ValidateAndSkip(d LtvElementDesc) error
Skip the value currently under the scanner with additional validation checks. Current implementation is inefficient to the point of being an abomination. It should be refactored with fire...
func (*StreamDecoder) Value ¶
func (s *StreamDecoder) Value() (any, error)
Read the next value from a data stream.
type StreamEncoder ¶
type StreamEncoder struct {
Werr error
// contains filtered or unexported fields
}
func NewStreamEncoder ¶
func NewStreamEncoder(w io.Writer) *StreamEncoder
func (*StreamEncoder) RawWrite ¶
func (e *StreamEncoder) RawWrite(b []byte)
Passthrough write a byte array to the underlying writer with error caching and offset tracking.
func (*StreamEncoder) RawWriteByte ¶
func (e *StreamEncoder) RawWriteByte(v byte)
Passthrough write byte
func (*StreamEncoder) RawWriteUint16 ¶
func (e *StreamEncoder) RawWriteUint16(v uint16)
Passthrough write Uint16 endian corrected
func (*StreamEncoder) RawWriteUint32 ¶
func (e *StreamEncoder) RawWriteUint32(v uint32)
Passthrough write Uint32, endian corrected
func (*StreamEncoder) RawWriteUint64 ¶
func (e *StreamEncoder) RawWriteUint64(v uint64)
Passthrough write Uint64, endian corrected
func (*StreamEncoder) Reset ¶
func (e *StreamEncoder) Reset()
Reset the error state and offset of the encoder.
func (*StreamEncoder) SetOffset ¶
func (e *StreamEncoder) SetOffset(offset int)
Manually set the "offset" of the stream encoder.
func (*StreamEncoder) WriteBool ¶
func (e *StreamEncoder) WriteBool(v bool)
func (*StreamEncoder) WriteBoolVec ¶
func (e *StreamEncoder) WriteBoolVec(v []bool)
func (*StreamEncoder) WriteBytes ¶
func (e *StreamEncoder) WriteBytes(v []byte)
func (*StreamEncoder) WriteF32 ¶
func (e *StreamEncoder) WriteF32(v float32)
func (*StreamEncoder) WriteF32Vec ¶
func (e *StreamEncoder) WriteF32Vec(v []float32)
func (*StreamEncoder) WriteF64 ¶
func (e *StreamEncoder) WriteF64(v float64)
func (*StreamEncoder) WriteF64Vec ¶
func (e *StreamEncoder) WriteF64Vec(v []float64)
func (*StreamEncoder) WriteI8 ¶
func (e *StreamEncoder) WriteI8(v int8)
func (*StreamEncoder) WriteI8Vec ¶
func (e *StreamEncoder) WriteI8Vec(v []int8)
func (*StreamEncoder) WriteI16 ¶
func (e *StreamEncoder) WriteI16(v int16)
func (*StreamEncoder) WriteI16Vec ¶
func (e *StreamEncoder) WriteI16Vec(v []int16)
func (*StreamEncoder) WriteI32 ¶
func (e *StreamEncoder) WriteI32(v int32)
func (*StreamEncoder) WriteI32Vec ¶
func (e *StreamEncoder) WriteI32Vec(v []int32)
func (*StreamEncoder) WriteI64 ¶
func (e *StreamEncoder) WriteI64(v int64)
func (*StreamEncoder) WriteI64Vec ¶
func (e *StreamEncoder) WriteI64Vec(v []int64)
func (*StreamEncoder) WriteInt ¶
func (e *StreamEncoder) WriteInt(v int64)
Write int with Goldilocks fitting
func (*StreamEncoder) WriteListEnd ¶
func (e *StreamEncoder) WriteListEnd()
func (*StreamEncoder) WriteListStart ¶
func (e *StreamEncoder) WriteListStart()
func (*StreamEncoder) WriteNil ¶
func (e *StreamEncoder) WriteNil()
func (*StreamEncoder) WriteNop ¶
func (e *StreamEncoder) WriteNop()
func (*StreamEncoder) WriteString ¶
func (e *StreamEncoder) WriteString(s string)
func (*StreamEncoder) WriteStructEnd ¶
func (e *StreamEncoder) WriteStructEnd()
func (*StreamEncoder) WriteStructStart ¶
func (e *StreamEncoder) WriteStructStart()
func (*StreamEncoder) WriteTag ¶
func (e *StreamEncoder) WriteTag(t TypeCode, s SizeCode)
func (*StreamEncoder) WriteU8 ¶
func (e *StreamEncoder) WriteU8(v uint8)
func (*StreamEncoder) WriteU8Vec ¶
func (e *StreamEncoder) WriteU8Vec(v []uint8)
func (*StreamEncoder) WriteU16 ¶
func (e *StreamEncoder) WriteU16(v uint16)
func (*StreamEncoder) WriteU16Vec ¶
func (e *StreamEncoder) WriteU16Vec(v []uint16)
func (*StreamEncoder) WriteU32 ¶
func (e *StreamEncoder) WriteU32(v uint32)
func (*StreamEncoder) WriteU32Vec ¶
func (e *StreamEncoder) WriteU32Vec(v []uint32)
func (*StreamEncoder) WriteU64 ¶
func (e *StreamEncoder) WriteU64(v uint64)
func (*StreamEncoder) WriteU64Vec ¶
func (e *StreamEncoder) WriteU64Vec(v []uint64)
func (*StreamEncoder) WriteUint ¶
func (e *StreamEncoder) WriteUint(v uint64)
Write uint with Goldilocks fitting
func (*StreamEncoder) WriteVectorPrefix ¶
func (e *StreamEncoder) WriteVectorPrefix(t TypeCode, count int)
Write the tag and length for a typed vector.
type StructEncoder ¶
type StructEncoder struct {
// contains filtered or unexported fields
}
func NewStructEncoder ¶
func NewStructEncoder(enc LtvEncoder) StructEncoder
func (StructEncoder) Bool ¶
func (s StructEncoder) Bool(key string, v bool)
func (StructEncoder) BoolVec ¶
func (s StructEncoder) BoolVec(key string, v []bool)
func (StructEncoder) Bytes ¶
func (s StructEncoder) Bytes(key string, v []byte)
func (StructEncoder) EndStruct ¶
func (s StructEncoder) EndStruct()
func (StructEncoder) F32Vec ¶
func (s StructEncoder) F32Vec(key string, v []float32)
func (StructEncoder) F64Vec ¶
func (s StructEncoder) F64Vec(key string, v []float64)
func (StructEncoder) I8 ¶
func (s StructEncoder) I8(key string, v int8)
func (StructEncoder) I8Vec ¶
func (s StructEncoder) I8Vec(key string, v []int8)
func (StructEncoder) I16 ¶
func (s StructEncoder) I16(key string, v int16)
func (StructEncoder) I16Vec ¶
func (s StructEncoder) I16Vec(key string, v []int16)
func (StructEncoder) I32 ¶
func (s StructEncoder) I32(key string, v int32)
func (StructEncoder) I32Vec ¶
func (s StructEncoder) I32Vec(key string, v []int32)
func (StructEncoder) I64 ¶
func (s StructEncoder) I64(key string, v int64)
func (StructEncoder) I64Vec ¶
func (s StructEncoder) I64Vec(key string, v []int64)
func (StructEncoder) Int ¶
func (s StructEncoder) Int(key string, v int64)
func (StructEncoder) Nil ¶
func (s StructEncoder) Nil(key string)
func (StructEncoder) StartStruct ¶
func (s StructEncoder) StartStruct()
func (StructEncoder) String ¶
func (s StructEncoder) String(key string, v string)
func (StructEncoder) U8 ¶
func (s StructEncoder) U8(key string, v uint8)
func (StructEncoder) U8Vec ¶
func (s StructEncoder) U8Vec(key string, v []uint8)
func (StructEncoder) U16 ¶
func (s StructEncoder) U16(key string, v uint16)
func (StructEncoder) U16Vec ¶
func (s StructEncoder) U16Vec(key string, v []uint16)
func (StructEncoder) U32 ¶
func (s StructEncoder) U32(key string, v uint32)
func (StructEncoder) U32Vec ¶
func (s StructEncoder) U32Vec(key string, v []uint32)
func (StructEncoder) U64 ¶
func (s StructEncoder) U64(key string, v uint64)
func (StructEncoder) U64Vec ¶
func (s StructEncoder) U64Vec(key string, v []uint64)
func (StructEncoder) Uint ¶
func (s StructEncoder) Uint(key string, v uint64)
type UnmarshalTypeError ¶
type UnmarshalTypeError struct {
Desc LtvDesc // LiteVector descriptor
GoType reflect.Type // Go value type it could not be assigned to
Struct string // name of the struct type containing the field
Field string // the full path from root node to the field
}
An UnmarshalTypeError describes a LiteVector value that was not appropriate for a value of a specific Go type.
func (*UnmarshalTypeError) Error ¶
func (e *UnmarshalTypeError) Error() string
type Unmarshaler ¶
Unmarshaler is the interface implemented by types that can unmarshal a LiteVector description of themselves. UnmarshalLTV must copy whatever it wishes to retain after returning.
type UnsupportedTypeError ¶
An UnsupportedTypeError is returned by Marshal when attempting to encode an unsupported value type.
func (*UnsupportedTypeError) Error ¶
func (e *UnsupportedTypeError) Error() string
type UnsupportedValueError ¶
An UnsupportedValueError is returned by Marshal when attempting to encode an unsupported value.
func (*UnsupportedValueError) Error ¶
func (e *UnsupportedValueError) Error() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
json2ltv
command
Utility that converts JSON to it's LiteVector representation.
|
Utility that converts JSON to it's LiteVector representation. |
|
ltv2dict
command
|
|
|
ltv2json
command
Utility that converts LiteVector data to it's JSON representation.
|
Utility that converts LiteVector data to it's JSON representation. |
|
ltvdump
command
|
|