byteslice

package module
v0.0.0-...-cb68ae1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2017 License: MIT Imports: 2 Imported by: 0

README

= byteslice

image:https://travis-ci.org/rlespinasse/byteslice.svg?branch=master["Build Status", link="https://travis-ci.org/rlespinasse/byteslice"]
image:https://coveralls.io/repos/github/rlespinasse/byteslice/badge.svg?branch=master["Coverage Status", link="https://coveralls.io/github/rlespinasse/byteslice?branch=master"]

== How to

=== test it with coverage

[source,shell]
-----
$ go test -coverprofile=/tmp/byteslice-cover .
ok  	github.com/rlespinasse/byteslice	0.007s	coverage: 100.0% of statements
-----

=== launch the benchmark

[source,shell]
-----
$ go test -bench=. .
goos: ...
goarch: ...
pkg: github.com/rlespinasse/byteslice
BenchmarkRBitState/get_low_bit_of_high_nibble-8         	2000000000	         1.99 ns/op
BenchmarkRBitState/get_low_bit-8                        	2000000000	         1.96 ns/op
...
PASS
ok  	github.com/rlespinasse/byteslice	158.442s
-----

== Documentation Site

See https://godoc.org/github.com/rlespinasse/byteslice

Documentation

Overview

Package byteslice provides functions to manipulate byte slices with endianness support (little, and big endian order)

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Flip

func Flip(data []byte) []byte

Flip apply NOT operation to a byte slice to flip it.

func LPad

func LPad(data []byte, length int, filler byte) []byte

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

func LSet(data, setData []byte) []byte

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

func LShift(data []byte, shift uint64) []byte

LShift apply left shift operation to an byte slice.

func LSubset

func LSubset(data []byte, leastSignificantBit, mostSignificantBit uint64) []byte

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.

func LToggle

func LToggle(data, toggleData []byte) []byte

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

func LUnset(data, unsetData []byte) []byte

LUnset apply AND operation on a byte slice with an "unset" byte slice using big endian order.

func RBit

func RBit(data byte, bit uint8) byte

RBit get a specific bit of the little endian ordered data byte.

Example
fmt.Printf("%x\n", RBit(0x55, 6))
Output:

40

func RBitsSubset

func RBitsSubset(data byte, leastSignificantBit, mostSignificantBit uint8) byte

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

func RPad(data []byte, length int, filler byte) []byte

RPad pads the right-side of a byte slice with a filler byte.

func RSet

func RSet(data, setData []byte) []byte

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

func RShift(data []byte, shift uint64) []byte

RShift apply right shift operation to an byte slice.

func RSubset

func RSubset(data []byte, leastSignificantBit, mostSignificantBit uint64) []byte

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.

func RToggle

func RToggle(data, toggleData []byte) []byte

RToggle apply XOR operation on a byte slice with an "toggle" byte slice using little endian order.

func RUnset

func RUnset(data, unsetData []byte) []byte

RUnset apply AND operation on a byte slice with an "unset" byte slice using little endian order.

func Reverse

func Reverse(data []byte) []byte

Reverse change the order of the byte slice.

Example
data := []byte{0x55, 0xDA, 0xBA}

fmt.Printf("%x\n", Reverse(data))
Output:

bada55

func Set

func Set(data, setData []byte) ([]byte, error)

Set apply OR operation on a byte slice with an "set" byte slice (must have the same size).

func Toggle

func Toggle(data, toggleData []byte) ([]byte, error)

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

func Unset

func Unset(data, unsetData []byte) ([]byte, error)

Unset apply AND operation on a byte slice with an "unset" byte slice (must have the same size).

Types

This section is empty.

Jump to

Keyboard shortcuts

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