|
|
|
@ -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 {
|
|
|