tape: Fix capitalization of Uint
This commit is contained in:
parent
134daacc03
commit
717754644c
@ -1,9 +1,6 @@
|
|||||||
// Package tape implements Table Pair Encoding.
|
// Package tape implements Table Pair Encoding.
|
||||||
package tape
|
package tape
|
||||||
|
|
||||||
// TODO: in math/rand: uint is capitalized like Uint, we need to replicate that
|
|
||||||
// here
|
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
// encoding and decoding functions must not make any allocations
|
// encoding and decoding functions must not make any allocations
|
||||||
@ -31,8 +28,8 @@ type Int16 interface { ~uint16 | ~int16 }
|
|||||||
type Int32 interface { ~uint32 | ~int32 }
|
type Int32 interface { ~uint32 | ~int32 }
|
||||||
// Int64 is any 64-bit integer.
|
// Int64 is any 64-bit integer.
|
||||||
type Int64 interface { ~uint64 | ~int64 }
|
type Int64 interface { ~uint64 | ~int64 }
|
||||||
// UInt is any unsigned integer.
|
// Uint is any unsigned integer.
|
||||||
type UInt interface { ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 }
|
type Uint interface { ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 }
|
||||||
// String is any string.
|
// String is any string.
|
||||||
type String interface { ~string | ~[]uint8 }
|
type String interface { ~string | ~[]uint8 }
|
||||||
|
|
||||||
@ -110,7 +107,7 @@ func EncodeI64[T Int64](buffer []byte, value T) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DecodeGBEU decodes an 8 to 64 bit growing integer into the given buffer.
|
// DecodeGBEU decodes an 8 to 64 bit growing integer into the given buffer.
|
||||||
func DecodeGBEU[T UInt](data []byte) (value T, n int, err error) {
|
func DecodeGBEU[T Uint](data []byte) (value T, n int, err error) {
|
||||||
var fullValue uint64
|
var fullValue uint64
|
||||||
for _, chunk := range data {
|
for _, chunk := range data {
|
||||||
fullValue *= 0x80
|
fullValue *= 0x80
|
||||||
@ -125,7 +122,7 @@ func DecodeGBEU[T UInt](data []byte) (value T, n int, err 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) (n int, err 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
|
||||||
@ -145,7 +142,7 @@ func EncodeGBEU[T UInt] (buffer []byte, value T) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GBEUSize returns the size (in octets) of a GBEU integer.
|
// GBEUSize returns the size (in octets) of a GBEU integer.
|
||||||
func GBEUSize[T UInt] (value T) int {
|
func GBEUSize[T Uint] (value T) int {
|
||||||
length := 0
|
length := 0
|
||||||
for {
|
for {
|
||||||
value >>= 7
|
value >>= 7
|
||||||
|
Loading…
Reference in New Issue
Block a user