Varint Frame Decoder
Varint Frame Decoder
Decode a length‑prefixed frame from a byte buffer using unsigned varint length encoding.
Function signature
func DecodeFrame(buf []byte, maxLen int) (payload []byte, consumed int, err error)
Requirements
- Length is encoded as unsigned varint (7 bits per byte, continuation bit 0x80).
- If the varint is incomplete, return
ErrNeedMoreand consume nothing. - If the varint is malformed or overflows 64 bits, return
ErrMalformedVarint. - If length >
maxLen, returnErrFrameTooLarge. - If the payload is incomplete, return
ErrNeedMoreand consume nothing. - On success, return a slice of the input buffer (zero‑copy) and the number of bytes consumed.
Constraints
maxLen >= 0.- Do not allocate on the hot path (tests enforce zero allocations).
Notes
- Do not convert to string.
consumedmust bevarintBytes + length.
Run tests to see results
No issues detected