Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Neumenon/cowrie/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Cowrie Gen2 provides efficient binary encoding with dictionary-coded keys, optional compression, and forward-compatible extension types.Encoding Functions
Encode
The value to encode
Encoded binary data with Gen2 header and dictionary
Error if encoding fails (e.g., unsupported type)
EncodeAppend
Destination buffer to append to
Value to encode
Buffer with encoded data appended
EncodeTo
io.Writer.
Writer to output encoded data
Value to encode
EncodeWithOptions
Value to encode
Encoding options
Sorts object keys lexicographically for reproducible output. Essential for hashing, caching, and content addressing.
Excludes null values from encoded objects. Useful for sparse data and reducing payload size.
EncodeWithHints
Value to encode
Column hints for selective field access
Decoding Functions
Decode
Encoded binary data
Decoded Cowrie value
Error if decoding fails (invalid magic, version, or malformed data)
DecodeWithOptions
Encoded binary data
Security limits and options
Maximum nesting depth for arrays/objects
Maximum array element count (100M)
Maximum object field count (10M)
Maximum string byte length (500MB)
Maximum bytes length (1GB, also applies to tensor/image/audio data)
Maximum TagExt payload length (100MB)
Maximum dictionary entries (10M)
Maximum column hints (10K)
Maximum tensor rank/dimensions
Behavior for unknown TagExt extensions:
UnknownExtKeep: Preserve as UnknownExtData (default, enables round-tripping)UnknownExtSkipAsNull: Skip and return NullUnknownExtError: Return error in strict mode
DecodeFrom
io.Reader. Reads entire input into memory.
Example:
DecodeFromLimited
io.Reader with a size limit. Returns ErrInputTooLarge if input exceeds maxBytes.
Reader to decode from
Maximum input size in bytes
DecodeWithHints
Decoded value
Column hints (nil if none present)
Compression Functions
EncodeFramed
Value to encode
Compression type:
CompressionNone(0)CompressionGzip(1)CompressionZstd(2)
- Bit 0:
FlagCompressed(0x01) - data is compressed - Bits 1-2: Compression type (0=none, 1=gzip, 2=zstd)
- Bit 3:
FlagHasColumnHints(0x08) - column hints present
DecodeFramed
Encoded data (compressed or uncompressed)
DecodeFramedWithLimit
ErrDecompressedTooLarge if claimed decompressed size exceeds limit.
Encoded data
Maximum decompressed size (prevents decompression bombs)
Error Types
Decoding errors:ErrInvalidMagic- Magic bytes != ‘SJ’ErrInvalidVersion- Version != 0x02ErrUnexpectedEOF- Truncated dataErrInvalidTag- Unknown type tagErrInvalidFieldID- Field ID >= dictionary lengthErrInvalidVarint- Malformed or overflow varint
ErrMalformedLength- Length exceeds remaining dataErrDepthExceeded- Nesting depth > MaxDepthErrArrayTooLarge- Array length > MaxArrayLenErrObjectTooLarge- Object fields > MaxObjectLenErrStringTooLarge- String length > MaxStringLenErrBytesTooLarge- Bytes length > MaxBytesLenErrExtTooLarge- Extension payload > MaxExtLenErrDictTooLarge- Dictionary size > MaxDictLenErrInputTooLarge- Input exceeds size limitErrDecompressedTooLarge- Decompressed size exceeds limitErrUnknownExt- Unknown extension in strict mode
ErrInvalidDType- Invalid tensor dtypeErrInvalidImgFormat- Invalid image formatErrInvalidAudioEnc- Invalid audio encodingErrInvalidIDWidth- Invalid adjacency list ID widthErrInvalidDeltaOp- Invalid delta opcode
Dictionary Coding
Gen2 uses dictionary coding for object keys to reduce payload size:- Encoding: All unique keys are collected and stored in the header dictionary
- Objects: Reference keys by dictionary index (varint) instead of inline strings
- Graph types: Node/Edge property keys also use the shared dictionary
Best Practices
Performance
- Use
EncodeAppendwith pre-allocated buffers to avoid allocations - Enable
Deterministicmode only when needed (adds sorting overhead) - Use compression for payloads > 256 bytes (automatic threshold)
- Prefer zstd over gzip for better compression ratios
Security
- Always use
DecodeFromLimitedfor untrusted network input - Set appropriate
MaxBytesLenfor tensor/image data in your domain - Use
UnknownExtErrormode if forward compatibility isn’t needed - Validate decompressed size limits to prevent decompression bombs
Compatibility
- Use
OnUnknownExt = UnknownExtKeep(default) for round-tripping - Preserve unknown extensions when proxying/forwarding data
- Check magic bytes ‘SJ’ to distinguish Gen2 from Gen1 format
See Also
- Core Types - Type tags and value constructors
- Extended Types - ML and graph extensions
- Compression - Detailed compression formats
- ColumnReader - Selective field access