diff options
| author | Shulhan <ms@kilabit.info> | 2025-01-22 23:27:48 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-01-23 00:00:38 +0700 |
| commit | 7f52c92fab6a49149643feeb9b3e5c06ef249ec1 (patch) | |
| tree | da5afba93e5a74bc89bee33a2eff4159a1323768 /lib/bytes/bytes.go | |
| parent | 8ad0d7cc01c08f60402d3d18df5dea13bfd94ece (diff) | |
| download | pakakeh.go-7f52c92fab6a49149643feeb9b3e5c06ef249ec1.tar.xz | |
all: replace "lib/bytes.ReadXxx" with standard library
Package "encoding/binary" from standard library support reading integer
from bytes using BigEndian, LittleEndian variables.
Diffstat (limited to 'lib/bytes/bytes.go')
| -rw-r--r-- | lib/bytes/bytes.go | 48 |
1 files changed, 0 insertions, 48 deletions
diff --git a/lib/bytes/bytes.go b/lib/bytes/bytes.go index 94e7d402..ce15e30a 100644 --- a/lib/bytes/bytes.go +++ b/lib/bytes/bytes.go @@ -267,54 +267,6 @@ func ReadHexByte(data []byte, x int) (b byte, ok bool) { return b, true } -// ReadInt16 read int16 value from "data" start at index "x". -// It will return 0 if "x" is out of range. -func ReadInt16(data []byte, x uint) (v int16) { - if x+1 >= uint(len(data)) { - return 0 - } - v = int16(data[x]) << 8 - v |= int16(data[x+1]) - return v -} - -// ReadInt32 read int32 value from "data" start at index "x". -// It will return 0 if "x" is out of range. -func ReadInt32(data []byte, x uint) (v int32) { - if x+3 >= uint(len(data)) { - return 0 - } - v = int32(data[x]) << 24 - v |= int32(data[x+1]) << 16 - v |= int32(data[x+2]) << 8 - v |= int32(data[x+3]) - return v -} - -// ReadUint16 read uint16 value from "data" start at index "x". -// If x is out of range, it will return 0. -func ReadUint16(data []byte, x uint) (v uint16) { - if x+1 >= uint(len(data)) { - return 0 - } - v = uint16(data[x]) << 8 - v |= uint16(data[x+1]) - return v -} - -// ReadUint32 read uint32 value from "data" start at index "x". -// If x is out of range, it will return 0. -func ReadUint32(data []byte, x uint) (v uint32) { - if x+3 >= uint(len(data)) { - return 0 - } - v = uint32(data[x]) << 24 - v |= uint32(data[x+1]) << 16 - v |= uint32(data[x+2]) << 8 - v |= uint32(data[x+3]) - return v -} - // RemoveSpaces remove all spaces from input in. func RemoveSpaces(in []byte) (out []byte) { var c byte |
