gbytebuffer

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 2 Imported by: 0

README

gbytebuffer

A byte buffer library to read/write simple variable types from/into byte slices. Conversions happen in little endian format by default but there is an big endian version of each function. Supported types are:

  • int8/byte
  • int16/uint16
  • int32/uint32
  • int64/uint64
  • float64

Usage

    package main

    import (
        "github.com/robotbey/gbytebuffer"
        "fmt"
    )

    func main(){

        // Write simple variable into byte slice
        buffer1 := NewByteBuffer()
        i8var := int8(42)
        buffer.WriteInt8(i8var)
        fmt.Println(buffer.Buffer())
        // output: [42]

        // Read from buffer into a variable
        buffer2 := ByteBufferFrom([]byte{0x69, 0xAB, 0xCD, 0xDE, 0xAD, 0xC0, 0xDE})   // 0xDEADC0DE = 3735929054
        i8var := buffer2.ReadInt8()
        i16var := uffer2.ReadInt16()
        i32var := uffer2.ReadInt32()

        fmt.Println(i8var)
        fmt.Println(i16var)
        fmt.Println(i32var)
        // output: 105
        //         43981
        //         3735929054

    }

Documentation

Index

Constants

View Source
const VERSION = "0.2.0"

VERSION is the version of the package.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteBuffer

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

ByteBuffer is used to read and write data to a byte array.

func ByteBufferFrom

func ByteBufferFrom(data []byte) *ByteBuffer

ByteBufferFrom creates a new ByteBuffer from a byte array.

func NewByteBuffer

func NewByteBuffer() *ByteBuffer

NewByteBuffer creates a new ByteBuffer.

func (*ByteBuffer) Advance

func (b *ByteBuffer) Advance(len int) int

Advance moves the index forward by the specified amount.

func (ByteBuffer) Buffer

func (b ByteBuffer) Buffer() []byte

Buffer returns the underlying byte array.

func (ByteBuffer) Data

func (b ByteBuffer) Data() []byte

Data returns a slice of the underlying byte array starting at the current index.

func (ByteBuffer) Index

func (b ByteBuffer) Index() int

Index returns the current index.

func (ByteBuffer) Length

func (b ByteBuffer) Length() int

Length returns the length of the buffer.

func (*ByteBuffer) ReadByte added in v0.2.0

func (b *ByteBuffer) ReadByte() byte

GetByte returns the byte at the current index.

func (*ByteBuffer) ReadBytes added in v0.2.0

func (b *ByteBuffer) ReadBytes(size int) []byte

func (*ByteBuffer) ReadFloat64 added in v0.2.0

func (b *ByteBuffer) ReadFloat64() float64

func (*ByteBuffer) ReadFloat64BE added in v0.2.0

func (b *ByteBuffer) ReadFloat64BE() float64

func (*ByteBuffer) ReadInt16 added in v0.2.0

func (b *ByteBuffer) ReadInt16() int16

ReadInt16 returns the int16 at the current index.

func (*ByteBuffer) ReadInt16BE added in v0.2.0

func (b *ByteBuffer) ReadInt16BE() int16

func (*ByteBuffer) ReadInt32 added in v0.2.0

func (b *ByteBuffer) ReadInt32() int32

func (*ByteBuffer) ReadInt32BE added in v0.2.0

func (b *ByteBuffer) ReadInt32BE() int32

func (*ByteBuffer) ReadInt64 added in v0.2.0

func (b *ByteBuffer) ReadInt64() int64

func (*ByteBuffer) ReadInt64BE added in v0.2.0

func (b *ByteBuffer) ReadInt64BE() int64

func (*ByteBuffer) ReadInt8 added in v0.2.0

func (b *ByteBuffer) ReadInt8() int8

ReadInt8 returns the int8 at the current index.

func (*ByteBuffer) ReadUInt16 added in v0.2.0

func (b *ByteBuffer) ReadUInt16() uint16

func (*ByteBuffer) ReadUInt16BE added in v0.2.0

func (b *ByteBuffer) ReadUInt16BE() uint16

func (*ByteBuffer) ReadUInt32 added in v0.2.0

func (b *ByteBuffer) ReadUInt32() uint32

func (*ByteBuffer) ReadUInt32BE added in v0.2.0

func (b *ByteBuffer) ReadUInt32BE() uint32

func (*ByteBuffer) ReadUInt64 added in v0.2.0

func (b *ByteBuffer) ReadUInt64() uint64

func (*ByteBuffer) ReadUInt64BE added in v0.2.0

func (b *ByteBuffer) ReadUInt64BE() uint64

func (*ByteBuffer) ReadUInt8 added in v0.2.0

func (b *ByteBuffer) ReadUInt8() uint8

ReadUInt8 returns the uint8 at the current index.

func (*ByteBuffer) Seek

func (b *ByteBuffer) Seek(pos int) int

Seek sets the current index to the specified value.

func (*ByteBuffer) UpdateLength

func (b *ByteBuffer) UpdateLength()

UpdateLength updates the length of the buffer.

func (*ByteBuffer) WriteByte added in v0.2.0

func (b *ByteBuffer) WriteByte(val byte)

SetByte sets the byte at the current index.

func (*ByteBuffer) WriteBytes added in v0.2.0

func (b *ByteBuffer) WriteBytes(data []byte)

func (*ByteBuffer) WriteFloat64 added in v0.2.0

func (b *ByteBuffer) WriteFloat64(val float64)

func (*ByteBuffer) WriteFloat64BE added in v0.2.0

func (b *ByteBuffer) WriteFloat64BE(val float64)

func (*ByteBuffer) WriteInt16 added in v0.2.0

func (b *ByteBuffer) WriteInt16(val int16)

func (*ByteBuffer) WriteInt16BE added in v0.2.0

func (b *ByteBuffer) WriteInt16BE(val int16)

func (*ByteBuffer) WriteInt32 added in v0.2.0

func (b *ByteBuffer) WriteInt32(val int32)

func (*ByteBuffer) WriteInt32BE added in v0.2.0

func (b *ByteBuffer) WriteInt32BE(val int32)

func (*ByteBuffer) WriteInt64 added in v0.2.0

func (b *ByteBuffer) WriteInt64(val int64)

func (*ByteBuffer) WriteInt64BE added in v0.2.0

func (b *ByteBuffer) WriteInt64BE(val int64)

func (*ByteBuffer) WriteInt8 added in v0.2.0

func (b *ByteBuffer) WriteInt8(val int8)

WriteInt8 sets the int8 at the current index.

func (*ByteBuffer) WriteUInt16 added in v0.2.0

func (b *ByteBuffer) WriteUInt16(val uint16)

func (*ByteBuffer) WriteUInt16BE added in v0.2.0

func (b *ByteBuffer) WriteUInt16BE(val uint16)

func (*ByteBuffer) WriteUInt32 added in v0.2.0

func (b *ByteBuffer) WriteUInt32(val uint32)

func (*ByteBuffer) WriteUInt32BE added in v0.2.0

func (b *ByteBuffer) WriteUInt32BE(val uint32)

func (*ByteBuffer) WriteUInt64 added in v0.2.0

func (b *ByteBuffer) WriteUInt64(val uint64)

func (*ByteBuffer) WriteUInt64BE added in v0.2.0

func (b *ByteBuffer) WriteUInt64BE(val uint64)

func (*ByteBuffer) WriteUInt8 added in v0.2.0

func (b *ByteBuffer) WriteUInt8(val uint8)

WriteUInt8 sets the uint8 at the current index.

Jump to

Keyboard shortcuts

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