byteUtil

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UTF8    = Charset("UTF-8")
	GB18030 = Charset("GB18030")
)

Variables

View Source
var MbTable = []uint16{}/* 256 elements not displayed */

Functions

func AppendVarint

func AppendVarint(b []byte, v uint64) ([]byte, int)

func BitGet

func BitGet(frame byte, position int) byte

BitGet 获取指定位的值 (是从最右边开始计算)

func BitSet0

func BitSet0(frame *byte, position int)

func BitSet1

func BitSet1(frame *byte, position int)

最右边的 position = 0

func Bytes2Hex

func Bytes2Hex(d []byte) string

Bytes2Hex returns the hexadecimal encoding of d.

func Bytes2Int

func Bytes2Int(b []byte) int

Bytes2Int 字节转换成整形

func Bytes2IntBigEndian

func Bytes2IntBigEndian(b []byte) (int, error)

Bytes2IntBigEndian (大端) []byte 转 int

func Bytes2IntByOrder

func Bytes2IntByOrder(b []byte, order binary.ByteOrder) int

func Bytes2IntLittleEndian

func Bytes2IntLittleEndian(b []byte) (int, error)

Bytes2IntLittleEndian 小端[]byte 转 int

func Bytes2String

func Bytes2String(frame []byte) string

func Bytes2StringByCharset

func Bytes2StringByCharset(byte []byte, charset Charset) string

func Bytes2UIntBigEndian

func Bytes2UIntBigEndian(b []byte) (int, error)

Bytes2UIntBigEndian (大端) []byte 转 uint

func Bytes2UIntLittleEndian

func Bytes2UIntLittleEndian(b []byte) (int, error)

Bytes2UIntLittleEndian (小端) []byte 转 uint

func CheckSum

func CheckSum(data []byte) uint16

func CheckSum2Byte

func CheckSum2Byte(data []byte, order binary.ByteOrder) []byte

func CopyBytes

func CopyBytes(b []byte) (copiedBytes []byte)

CopyBytes returns an exact copy of the provided bytes.

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func Hex2BytesFixed

func Hex2BytesFixed(str string, flen int) []byte

Hex2BytesFixed returns bytes of a specified fixed length flen.

func Int2Byte

func Int2Byte(n int) byte

func Int2Byte2

func Int2Byte2(curr int) []byte

int 转成 [2]byte uint16

func Int2Bytes

func Int2Bytes(n int) []byte

Int2Bytes 整形转换成字节

func Int2BytesBigEndian

func Int2BytesBigEndian(n int64, bytesLength byte) ([]byte, error)

Int2BytesBigEndian int 转大端 []byte

func Int2BytesByOrder

func Int2BytesByOrder(n int, order binary.ByteOrder) []byte

func Int2BytesLittleEndian

func Int2BytesLittleEndian(n int64, bytesLength byte) ([]byte, error)

Int2BytesLittleEndian int 转小端 []byte

func Join

func Join(prefix, context []byte) []byte

func LeftPadBytes

func LeftPadBytes(slice []byte, l int) []byte

LeftPadBytes zero-pads slice to the left up to length l.

func Poll2Byte

func Poll2Byte(frame *[]byte) int16

func Poll4Byte

func Poll4Byte(frame *[]byte) int32

func RightPadBytes

func RightPadBytes(slice []byte, l int) []byte

RightPadBytes zero-pads slice to the right up to length l.

func ShowBin

func ShowBin(a byte) string

a输出结果:00011110 a = 30

func TrimLeftZeroes

func TrimLeftZeroes(s []byte) []byte

TrimLeftZeroes returns a subslice of s without leading zeroes

func TrimRightZeroes

func TrimRightZeroes(s []byte) []byte

TrimRightZeroes returns a subslice of s without trailing zeroes

Types

type Charset

type Charset string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL