binutil

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2020 License: MIT Imports: 1 Imported by: 2

Documentation

Overview

Package binutil contains some helpful utilities for reading binary data from byte slices.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Duplicate

func Duplicate(in []byte) []byte

Duplicate creates a full copy of the input byte slice.

func IsOnlyZeroes

func IsOnlyZeroes(data []byte) bool

IsOnlyZeroes return true when the input data is all bytes of zero value and false if any of the bytes has a nonzero value.

Types

type BinReader

type BinReader struct {
	// contains filtered or unexported fields
}

BinReader helps to read data from a byte slice using an offset and a data length (instead two offsets when using a slice expression). For example b[2:4] yields the same as Read(2, 2) using a BinReader over b. Also some convenient methods are provided to read integer values using a binary.ByteOrder from the slice directly.

Note that methods that return a []byte may not necessarily copy the data, so modifying the returned slice may also affect the data in the BinReader.

Methods will panic when any offset or length is outside of the bounds of the original data.

func NewBigEndianReader

func NewBigEndianReader(data []byte, bo binary.ByteOrder) *BinReader

NewLittleEndianReader creates a BinReader over data using binary.BigEndian. The data slice is stored directly, no copy is made, so modifying the original slice will also affect the returned BinReader.

func NewBinReader

func NewBinReader(data []byte, bo binary.ByteOrder) *BinReader

NewBinReader creates a BinReader over data using the specified binary.ByteOrder. The data slice is stored directly, no copy is made, so modifying the original slice will also affect the returned BinReader.

func NewLittleEndianReader

func NewLittleEndianReader(data []byte) *BinReader

NewLittleEndianReader creates a BinReader over data using binary.LittleEndian. The data slice is stored directly, no copy is made, so modifying the original slice will also affect the returned BinReader.

func (*BinReader) Byte

func (r *BinReader) Byte(offset int) byte

Byte returns the byte at the position indicated by the offset.

func (*BinReader) ByteOrder

func (r *BinReader) ByteOrder() binary.ByteOrder

ByteOrder returns the ByteOrder for this BinReader.

func (*BinReader) Data

func (r *BinReader) Data() []byte

Data returns all data inside this BinReader.

func (*BinReader) Length

func (r *BinReader) Length() int

Length returns the length of the contained data.

func (*BinReader) Read

func (r *BinReader) Read(offset int, length int) []byte

Read reads an amount of bytes as specified by length from the provided offset. The returned slice's length is the same as the specified length.

func (*BinReader) ReadFrom

func (r *BinReader) ReadFrom(offset int) []byte

ReadFrom returns all data starting at the specified offset.

func (*BinReader) Reader

func (r *BinReader) Reader(offset int, length int) *BinReader

Reader returns a new BinReader over the data read by Read(offset, length) using the same ByteOrder as this reader. There is no guarantee a copy of the data is made, so modifying the new reader's data may affect the original.

func (*BinReader) ReaderFrom

func (r *BinReader) ReaderFrom(offset int) *BinReader

ReaderFrom returns a BinReader over the data read by ReadFrom(offset) using the same ByteOrder as this reader. There is no guarantee a copy of the data is made, so modifying the new reader's data may affect the original.

func (*BinReader) Uint16

func (r *BinReader) Uint16(offset int) uint16

Uint16 reads 2 bytes from the provided offset and parses them into a uint16 using the provided ByteOrder.

func (*BinReader) Uint32

func (r *BinReader) Uint32(offset int) uint32

Uint32 reads 4 bytes from the provided offset and parses them into a uint32 using the provided ByteOrder.

func (*BinReader) Uint64

func (r *BinReader) Uint64(offset int) uint64

Uint64 reads 8 bytes from the provided offset and parses them into a uint64 using the provided ByteOrder.

Jump to

Keyboard shortcuts

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