Documentation ¶
Overview ¶
Package byteslice provides functions to manipulate byte slices with endianness support (little, and big endian order)
Index ¶
- func Flip(data []byte) []byte
- func LPad(data []byte, length int, filler byte) []byte
- func LSet(data, setData []byte) []byte
- func LShift(data []byte, shift uint64) []byte
- func LSubset(data []byte, leastSignificantBit, mostSignificantBit uint64) []byte
- func LToggle(data, toggleData []byte) []byte
- func LUnset(data, unsetData []byte) []byte
- func RBit(data byte, bit uint8) byte
- func RBitsSubset(data byte, leastSignificantBit, mostSignificantBit uint8) byte
- func RPad(data []byte, length int, filler byte) []byte
- func RSet(data, setData []byte) []byte
- func RShift(data []byte, shift uint64) []byte
- func RSubset(data []byte, leastSignificantBit, mostSignificantBit uint64) []byte
- func RToggle(data, toggleData []byte) []byte
- func RUnset(data, unsetData []byte) []byte
- func Reverse(data []byte) []byte
- func Set(data, setData []byte) ([]byte, error)
- func Toggle(data, toggleData []byte) ([]byte, error)
- func Unset(data, unsetData []byte) ([]byte, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Flip ¶
Flip apply NOT operation to a byte slice to flip it.
Example ¶
data := []byte{0xDA, 0x99, 0xBA} output := Flip(data) fmt.Printf("%x\n", output)
Output: 256645
func LPad ¶
LPad pads the left-side of a byte slice with a filler byte.
Example ¶
data := []byte{0x55, 0xDA, 0xBA} fmt.Printf("%x\n", LPad(data, 5, 0x22))
Output: 222255daba
func LSet ¶
LSet apply OR operation on a byte slice with an "set" byte slice using big endian order.
Example ¶
data := []byte{0xAA, 0xCA, 0x55} setData := []byte{0x10, 0x12} fmt.Printf("%x\n", LSet(data, setData))
Output: bada55
func LShift ¶
LShift apply left shift operation to an byte slice.
Example ¶
data := []byte{0xDA, 0x99, 0xBA} output := LShift(data, 8) fmt.Printf("%x\n", output)
Output: 99ba00
func LSubset ¶
LSubset get the byte slice of a subset of the big endian ordered data byte defined by the least significant bit and the most significant bit.
Example ¶
data := []byte{0xDA, 0x99, 0xBA} output := LSubset(data, 6, 17) fmt.Printf("%x\n", output)
Output: a660
func LToggle ¶
LToggle apply XOR operation on a byte slice with an "toggle" byte slice using big endian order.
Example ¶
data := []byte{0xAB, 0xCB, 0x44} setData := []byte{0x11, 0x11, 0x11} fmt.Printf("%x\n", LToggle(data, setData))
Output: bada55
func LUnset ¶
LUnset apply AND operation on a byte slice with an "unset" byte slice using big endian order.
Example ¶
data := []byte{0x11, 0x11, 0x10} unsetData := []byte{0x01, 0x01} output := LUnset(data, unsetData) fmt.Printf("%x\n", output)
Output: 010110
func RBit ¶
RBit get a specific bit of the little endian ordered data byte.
Example ¶
fmt.Printf("%x\n", RBit(0x55, 6))
Output: 40
func RBitsSubset ¶
RBitsSubset get the byte value of a subset of the little endian ordered data byte defined by the least significant bit and the most significant bit.
Example ¶
fmt.Printf("%x\n", RBitsSubset(0x55, 2, 6))
Output: 15
func RPad ¶
RPad pads the right-side of a byte slice with a filler byte.
Example ¶
data := []byte{0x55, 0xDA, 0xBA} fmt.Printf("%x\n", RPad(data, 5, 0x22))
Output: 55daba2222
func RSet ¶
RSet apply OR operation on a byte slice with an "set" byte slice using little endian order.
Example ¶
data := []byte{0xBA, 0xCA, 0x44} setData := []byte{0x12, 0x11} fmt.Printf("%x\n", RSet(data, setData))
Output: bada55
func RShift ¶
RShift apply right shift operation to an byte slice.
Example ¶
data := []byte{0xDA, 0x99, 0xBA} output := RShift(data, 8) fmt.Printf("%x\n", output)
Output: 00da99
func RSubset ¶
RSubset get the byte slice of a subset of the little endian ordered data byte defined by the least significant bit and the most significant bit.
Example ¶
data := []byte{0xDA, 0x99, 0xBA} output := RSubset(data, 6, 17) fmt.Printf("%x\n", output)
Output: 0a66
func RToggle ¶
RToggle apply XOR operation on a byte slice with an "toggle" byte slice using little endian order.
Example ¶
data := []byte{0xDA, 0x99, 0xBA} toogleData := []byte{0x77, 0x88, 0x11, 0xAD, 0x11, 0xAB} output := RToggle(data, toogleData) fmt.Printf("%x\n", output)
Output: 778811778811
func RUnset ¶
RUnset apply AND operation on a byte slice with an "unset" byte slice using little endian order.
Example ¶
data := []byte{0x11, 0x11, 0x00} unsetData := []byte{0x01, 0x01} output := RUnset(data, unsetData) fmt.Printf("%x\n", output)
Output: 110100
func Reverse ¶
Reverse change the order of the byte slice.
Example ¶
data := []byte{0x55, 0xDA, 0xBA} fmt.Printf("%x\n", Reverse(data))
Output: bada55
func Set ¶
Set apply OR operation on a byte slice with an "set" byte slice (must have the same size).
Example ¶
data := []byte{0xDA, 0x99, 0xBA} setData := []byte{0x11, 0x22, 0x33} output, _ := Set(data, setData) fmt.Printf("%x\n", output)
Output: dbbbbb
func Toggle ¶
Toggle apply XOR operation on a byte slice with an "toggle" byte slice (must have the same size).
Example ¶
data := []byte{0xbb, 0xdb, 0x54} toggle := []byte{0x01, 0x01, 0x01} output, _ := Toggle(data, toggle) fmt.Printf("%x\n", output)
Output: bada55
Example (Simple) ¶
data := []byte{0x00, 0x01, 0x00} toggle := []byte{0x01, 0x00, 0x01} output, _ := Toggle(data, toggle) fmt.Printf("%x\n", output)
Output: 010101
Types ¶
This section is empty.