codec

package
v0.0.0-...-77dcbbd Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package codec implements serialization and deserialization defined in LIP-0027 and LIP-0064 and lisk32 representation of address defined in LIP-0018.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidData represents general invalid data.
	ErrInvalidData = errors.New("invalid data")
	// ErrOutOfRange represents logic accessing data in out of range.
	ErrOutOfRange = errors.New("out of range")
	// ErrNoTerminate represents invalid protobuf format.
	ErrNoTerminate = errors.New("no terminationg bit found")
	// ErrUnexpectedFieldNumber represents protobuf field number not matching expected value.
	ErrUnexpectedFieldNumber = errors.New("unexpected field number found")
	// ErrFieldNumberNotFound represents protobuf field number not matching expected value.
	ErrFieldNumberNotFound = errors.New("expected field number does not exist")
	// ErrUnreadBytes represents extra bytes not read.
	ErrUnreadBytes = errors.New("unread bytes exist")
	// ErrUnnecessaryLeadingBytes represents error for which varint has unnecessary 0x80 byte at the beginning.
	ErrUnnecessaryLeadingBytes = errors.New("unnecessary leading bytes for varint found")
)

Functions

func BytesToLisk32

func BytesToLisk32[T ~byte](val []T) (string, error)

func HexArrayToBytesArray

func HexArrayToBytesArray(val []Hex) [][]byte

func Lisk32ArrayToBytesArray

func Lisk32ArrayToBytesArray(val []Lisk32) [][]byte

func Lisk32ToBytes

func Lisk32ToBytes(val string) ([]byte, error)

func ValidateLisk32

func ValidateLisk32(val string) error

Types

type Decodable

type Decodable interface {
	Decode([]byte) error
}

Decodable is interface for struct which is decodable All generated struct code should have this method.

type DecodableReader

type DecodableReader interface {
	DecodeFromReader(*Reader) error
}

DecodableReader is interface for struct which is decodable All generated struct code should have this method.

type Encodable

type Encodable interface {
	Encode() []byte
}

Encodable is interface for struct which is encodable All generated struct code should have this method.

type EncodeDecodable

type EncodeDecodable interface {
	Encodable
	Decodable
	DecodableReader
}

EncodeDecodable can encode and decode.

type Hex

type Hex []byte

func BytesArrayToHexArray

func BytesArrayToHexArray(val [][]byte) []Hex

func (Hex) MarshalJSON

func (h Hex) MarshalJSON() ([]byte, error)

func (Hex) String

func (h Hex) String() string

func (*Hex) UnmarshalJSON

func (h *Hex) UnmarshalJSON(b []byte) error

type Lisk32

type Lisk32 []byte

func BytesArrayToLisk32Array

func BytesArrayToLisk32Array(val [][]byte) []Lisk32

func (Lisk32) MarshalJSON

func (h Lisk32) MarshalJSON() ([]byte, error)

func (Lisk32) String

func (h Lisk32) String() string

func (*Lisk32) UnmarshalJSON

func (h *Lisk32) UnmarshalJSON(b []byte) error

type Reader

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

Reader is responsible for reading data in protobuf protocol.

func NewReader

func NewReader(data []byte) *Reader

NewReader returns reader with the data given.

func (*Reader) HasUnreadBytes

func (r *Reader) HasUnreadBytes() bool

func (*Reader) ReadBool

func (r *Reader) ReadBool(fieldNumber int, strict bool) (bool, error)

ReadBool reads int if the field number matches.

func (*Reader) ReadBools

func (r *Reader) ReadBools(fieldNumber int) ([]bool, error)

ReadBools reads []bool if the field number matches.

func (*Reader) ReadBytes

func (r *Reader) ReadBytes(fieldNumber int, strict bool) ([]byte, error)

ReadBytes reads []byte if the field number matches.

func (*Reader) ReadBytesArray

func (r *Reader) ReadBytesArray(fieldNumber int) ([][]byte, error)

ReadBytesArray reads [][]byte if the field number matches.

func (*Reader) ReadDecodable

func (r *Reader) ReadDecodable(fieldNumber int, creator func() DecodableReader, strict bool) (DecodableReader, error)

ReadDecodable reads struct if the field number matches.

func (*Reader) ReadDecodables

func (r *Reader) ReadDecodables(fieldNumber int, creator func() DecodableReader) ([]interface{}, error)

ReadDecodables reads array of struct if the field number matches.

func (*Reader) ReadInt

func (r *Reader) ReadInt(fieldNumber int, strict bool) (int64, error)

ReadInt reads int if the field number matches.

func (*Reader) ReadInt32

func (r *Reader) ReadInt32(fieldNumber int, strict bool) (int32, error)

ReadInt reads int if the field number matches.

func (*Reader) ReadInts

func (r *Reader) ReadInts(fieldNumber int) ([]int64, error)

ReadInts reads []int if the field number matches.

func (*Reader) ReadString

func (r *Reader) ReadString(fieldNumber int, strict bool) (string, error)

ReadString reads string if the field number matches.

func (*Reader) ReadStrings

func (r *Reader) ReadStrings(fieldNumber int) ([]string, error)

ReadStrings reads []string if the field number matches.

func (*Reader) ReadUInt

func (r *Reader) ReadUInt(fieldNumber int, strict bool) (uint64, error)

ReadUInt reads uint if the field number matches.

func (*Reader) ReadUInt32

func (r *Reader) ReadUInt32(fieldNumber int, strict bool) (uint32, error)

ReadUInt32 reads uint32 if the field number matches.

func (*Reader) ReadUInt32s

func (r *Reader) ReadUInt32s(fieldNumber int) ([]uint32, error)

ReadUInt32s reads []uint32 if the field number matches.

func (*Reader) ReadUInts

func (r *Reader) ReadUInts(fieldNumber int) ([]uint64, error)

ReadUInts reads []uint if the field number matches.

type UInt64Str

type UInt64Str uint64

UInt64Str type for marshal and unmarshal uint64 json string.

func (UInt64Str) MarshalJSON

func (i UInt64Str) MarshalJSON() ([]byte, error)

func (*UInt64Str) UnmarshalJSON

func (i *UInt64Str) UnmarshalJSON(b []byte) error

type Writer

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

Writer is responsible for writing data in protobuf protocol.

func NewWriter

func NewWriter() *Writer

NewWriter returns a new instances of a writer.

func (*Writer) Result

func (w *Writer) Result() []byte

Result returns the written bytes.

func (*Writer) Size

func (w *Writer) Size() int

Size returns written size.

func (*Writer) WriteBool

func (w *Writer) WriteBool(fieldNumber int, data bool)

WriteBool writes a boolean to result.

func (*Writer) WriteBools

func (w *Writer) WriteBools(fieldNumber int, data []bool)

WriteBools writes booleans to result.

func (*Writer) WriteBytes

func (w *Writer) WriteBytes(fieldNumber int, data []byte)

WriteBytes writes a bytes to result.

func (*Writer) WriteBytesArray

func (w *Writer) WriteBytesArray(fieldNumber int, data [][]byte)

WriteBytesArray writes bytes array to result.

func (*Writer) WriteEncodable

func (w *Writer) WriteEncodable(fieldNumber int, data Encodable)

WriteEncodable writes encodable struct to result.

func (*Writer) WriteInt

func (w *Writer) WriteInt(fieldNumber int, data int64)

WriteInt writes int to result.

func (*Writer) WriteInt32

func (w *Writer) WriteInt32(fieldNumber int, data int32)

WriteInt32 writes int to result.

func (*Writer) WriteInt32s

func (w *Writer) WriteInt32s(fieldNumber int, data []int32)

WriteInt32s writes int to result.

func (*Writer) WriteInts

func (w *Writer) WriteInts(fieldNumber int, data []int64)

WriteInts writes int to result.

func (*Writer) WriteString

func (w *Writer) WriteString(fieldNumber int, data string)

WriteString writes a string to result.

func (*Writer) WriteStrings

func (w *Writer) WriteStrings(fieldNumber int, data []string)

WriteStrings writes strings to result.

func (*Writer) WriteUInt

func (w *Writer) WriteUInt(fieldNumber int, data uint64)

WriteUInt writes uint to result.

func (*Writer) WriteUInt32

func (w *Writer) WriteUInt32(fieldNumber int, data uint32)

WriteUInt32 writes uint to result.

func (*Writer) WriteUInt32s

func (w *Writer) WriteUInt32s(fieldNumber int, data []uint32)

WriteUInt32s writes uint to result.

func (*Writer) WriteUInts

func (w *Writer) WriteUInts(fieldNumber int, data []uint64)

WriteUInts writes uint to result.

Directories

Path Synopsis
gen
gen generates encoding/decoding codes for struct using "fieldNumber" tag.
gen generates encoding/decoding codes for struct using "fieldNumber" tag.
internal
Code generated for package internal by go-bindata DO NOT EDIT.
Code generated for package internal by go-bindata DO NOT EDIT.
internal
codec_test
Package codec_test is a test package for codec.
Package codec_test is a test package for codec.

Jump to

Keyboard shortcuts

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