message-size-increase #3

Merged
sashakoshka merged 227 commits from message-size-increase into main 2025-09-07 19:27:38 -06:00
2 changed files with 12 additions and 10 deletions
Showing only changes of commit 8d5ba2fa39 - Show all commits

View File

@ -3,6 +3,8 @@ package tape
import "fmt" import "fmt"
// encoding and decoding functions must not make any allocations
const dataMaxSize = 0xFFFF const dataMaxSize = 0xFFFF
const uint16Max = 0xFFFF const uint16Max = 0xFFFF
@ -119,12 +121,12 @@ func DecodeGBEU[T UInt](data []byte) (T, error) {
} }
// EncodeGBEU encodes an 8 to 64 bit growing integer into a given buffer. // EncodeGBEU encodes an 8 to 64 bit growing integer into a given buffer.
func EncodeGBEU[T UInt] (buffer []byte, value T) (error) { func EncodeGBEU[T UInt] (buffer []byte, value T) (n int, err error) {
window := (GBEUSize(value) - 1) * 7 window := (GBEUSize(value) - 1) * 7
index := 0 index := 0
for window >= 0 { for window >= 0 {
if index >= len(buffer) { return fmt.Errorf("encoding GBEU: %w", ErrWrongBufferLength) } if index >= len(buffer) { return index, fmt.Errorf("encoding GBEU: %w", ErrWrongBufferLength) }
chunk := uint8(value >> window) & 0x7F chunk := uint8(value >> window) & 0x7F
if window > 0 { if window > 0 {