Documentation ¶
Overview ¶
Package tlv implements Type-Length-Value (TLV) Encoding.
Index ¶
- Constants
- Variables
- func CacheType(v interface{}) error
- func Copy(dst ReadFrom, src WriteTo) error
- func Hash(f func() hash.Hash, v interface{}) ([]byte, error)
- func Marshal(v interface{}, t uint64) ([]byte, error)
- func Unmarshal(b []byte, v interface{}, t uint64) error
- type ReadFrom
- type Reader
- type WriteTo
- type Writer
Constants ¶
View Source
const ( // MaxSize is the upper limit for tlv buffers. // 1. One "common" size of Ethernet jumbo packets is 9000 octets // 2. It is generally sufficient to carry an 8192 byte payload in a content object // 3. 8800 bytes was a message size limit in ONC-RPC over UDP // 4. Some OSs have a limited default UDP packet size (MacOS: net.inet.udp.maxdgram: 9216) and/or a limited space for receive buffers (MacOS: net.inet.udp.recvspace: 42080) // 5. When a ContentObject is signed it is not known whether the transmission path will be UDP / TCP / .. MaxSize = 8800 )
Variables ¶
View Source
var ( ErrPacketTooLarge = errors.New("exceed max size") ErrNotSupported = errors.New("feature not supported") ErrUnexpectedType = errors.New("type not match") ErrInvalidPtr = errors.New("invalid pointer") )
Errors introduced by encoding and decoding.
View Source
var (
ErrMissingType = errors.New("type not specified")
)
Errors introduced by parsing struct tags.
Functions ¶
func CacheType ¶
func CacheType(v interface{}) error
CacheType caches struct tags to prevent allocation on common types.
func Copy ¶
Copy copies from src to dst. If src and dst have the same type, it will perform direct copying with reflection. Otherwise copying will happen with tlv representation.
func Hash ¶
Hash returns the digest of tlv-encoded data.
See Marshal.
'*' after type number indicates this tlv is signature, and should be omitted in digest calculation.
Types ¶
type Reader ¶
type Reader interface { // Peek returns the tlv type without advancing. // // If the buffer is invalid, it will be filled with the next tlv block. Peek() uint64 // Read reads current tlv block into v. // // If the buffer is invalid, it will be filled with the next tlv block. Read(interface{}, uint64) error }
Reader decodes tlv-encoded data.
Click to show internal directories.
Click to hide internal directories.