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
Gen1 provides simple, high-performance functions for encoding Go data to binary format and decoding back to Go values. All functions are safe for concurrent use.Encode
Encodes arbitrary Go data into Gen1 Cowrie binary format.The value to encode. Supports all JSON-compatible types plus typed arrays (
[]int64, []float64, []float32, []string) and graph types.[]byte
Binary-encoded data in Gen1 Cowrie format
error
Error if encoding fails (e.g., unsupported type)
Example
Supported Types
| Go Type | Gen1 Tag | Notes |
|---|---|---|
nil | 0x00 | Null value |
bool | 0x01, 0x02 | False = 0x01, True = 0x02 |
int, int8-int64, uint, uint8-uint64 | 0x03 | All encode as varint |
float32, float64 | 0x04 | Scalar floats |
string | 0x05 | UTF-8 strings |
[]byte | 0x06 | Binary data |
[]any | 0x07 | Heterogeneous arrays |
map[string]any | 0x08 | Objects (sorted keys) |
[]int64 | 0x09 | Homogeneous int64 arrays (8 bytes/element) |
[]float64 | 0x0A or 0x0C | Proto-tensor (precision controlled by options) |
[]float32 | 0x0C | Float32 arrays (4 bytes/element) |
[]string | 0x0B | Homogeneous string arrays |
EncodeWithOptions
Encodes with explicit control over precision and behavior.The value to encode
Encoding options controlling precision and behavior
When
true (default), preserves float64 precision (8 bytes/float, tag 0x0A).
When false, uses float32 for ~50% size reduction (4 bytes/float, tag 0x0C).Use HighPrecision: true for:- Cross-language compatibility (recommended default)
- Financial data requiring exact decimal representation
- Scientific constants with many significant digits
- Cryptographic values where bit-exactness matters
- ML embeddings and features
- Sensor data and measurements
- Graphics and game data
- Go-only workloads prioritizing size
Example
Decode
Decodes Gen1 Cowrie binary data back into a Go value.Binary data in Gen1 Cowrie format
any
Decoded Go value. Types:
- Primitives:
nil,bool,int64,float64,string,[]byte - Containers:
map[string]any,[]any - Typed arrays:
[]int64,[]float64,[]string - Graph types:
Node,Edge,AdjList,NodeBatch,EdgeBatch,GraphShard
error
Error if data is malformed or exceeds security limits
Example
DecodeWithOptions
Decodes with custom security limits to protect against malicious input.Binary data to decode
Security limits for decoding
Maximum nesting depth for objects/arrays (default: 1000). Prevents stack overflow from deeply nested structures.
Maximum array element count (default: 100,000,000). Prevents memory exhaustion from malicious array size declarations.
Maximum object field count (default: 10,000,000)
Maximum string byte length (default: 500,000,000)
Maximum bytes length (default: 1,000,000,000)
Security Errors
Example
JSON Conversion
EncodeJSON
Converts raw JSON bytes to Gen1 Cowrie format.JSON-encoded data
[]byte
Gen1 Cowrie binary data
DecodeJSON
Converts Gen1 Cowrie data back to JSON bytes.Gen1 Cowrie binary data
[]byte
JSON-encoded bytes
Example
Advanced Functions
EncodeAppend
Appends encoded data to an existing buffer, avoiding allocations.Existing buffer to append to
Value to encode
[]byte
Buffer with encoded data appended
Example
EncodeTo
Writes encoded data directly to anio.Writer.
Writer to output encoded data
Value to encode
error
Error if encoding or writing fails