package bytebuffer

import "github.com/performancecopilot/speed/bytebuffer"

Package bytebuffer implements a java like bytebuffer for go

initially tried to use bytes.Buffer but the main restriction with that is that it does not allow the freedom to move around in the buffer. Further, it always writes at the end of the buffer

another attempt was to maintain a position identifier that was always passed to any function that wrote anything and the function *had* to return the next writable location, which resulted in calls like

pos = writeString(buffer, pos, "mmv")

which became unmaintainable after a while, and along with all the side maintenance looked extremely ugly

this (tries) to implement a minimal buffer wrapper that gives the freedom to move around and write anywhere you want

Index

Types

type Buffer

type Buffer interface {
	io.Writer
	Bytes() []byte
	Pos() int
	SetPos(int) error
	Len() int
	WriteVal(val interface{}) error
	WriteString(string) error
	WriteInt32(int32) error
	WriteInt64(int64) error
	WriteUint32(uint32) error
	WriteUint64(uint64) error
	WriteFloat32(float32) error
	WriteFloat64(float64) error
}

Buffer defines an abstraction for an object that allows writing of binary values anywhere within a fixed range

type ByteBuffer

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

ByteBuffer is a simple wrapper over a byte slice that supports writing anywhere

func NewByteBuffer

func NewByteBuffer(n int) *ByteBuffer

NewByteBuffer creates a new ByteBuffer of the specified size

func NewByteBufferSlice

func NewByteBufferSlice(buffer []byte) *ByteBuffer

NewByteBufferSlice creates a new ByteBuffer using the passed slice

func (*ByteBuffer) Bytes

func (b *ByteBuffer) Bytes() []byte

Bytes returns the internal byte array of the ByteBuffer

func (*ByteBuffer) Len

func (b *ByteBuffer) Len() int

Len returns the maximum size of the ByteBuffer

func (*ByteBuffer) Pos

func (b *ByteBuffer) Pos() int

Pos returns the current write position of the ByteBuffer

func (*ByteBuffer) SetPos

func (b *ByteBuffer) SetPos(position int) error

SetPos sets the write position of the ByteBuffer to the specified position

func (*ByteBuffer) Write

func (b *ByteBuffer) Write(data []byte) (int, error)

func (*ByteBuffer) WriteFloat32

func (b *ByteBuffer) WriteFloat32(val float32) error

WriteFloat32 writes an float32 to the buffer

func (*ByteBuffer) WriteFloat64

func (b *ByteBuffer) WriteFloat64(val float64) error

WriteFloat64 writes an float64 to the buffer

func (*ByteBuffer) WriteInt32

func (b *ByteBuffer) WriteInt32(val int32) error

WriteInt32 writes an int32 to the buffer

func (*ByteBuffer) WriteInt64

func (b *ByteBuffer) WriteInt64(val int64) error

WriteInt64 writes an int64 to the buffer

func (*ByteBuffer) WriteString

func (b *ByteBuffer) WriteString(val string) error

WriteString writes a string to the buffer

func (*ByteBuffer) WriteUint32

func (b *ByteBuffer) WriteUint32(val uint32) error

WriteUint32 writes an uint32 to the buffer

func (*ByteBuffer) WriteUint64

func (b *ByteBuffer) WriteUint64(val uint64) error

WriteUint64 writes an uint64 to the buffer

func (*ByteBuffer) WriteVal

func (b *ByteBuffer) WriteVal(val interface{}) error

WriteVal writes an arbitrary value to the buffer

type MemoryMappedBuffer

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

MemoryMappedBuffer is a ByteBuffer that is also mapped into memory

func NewMemoryMappedBuffer

func NewMemoryMappedBuffer(loc string, size int) (*MemoryMappedBuffer, error)

NewMemoryMappedBuffer will create and return a new instance of a MemoryMappedBuffer

func (*MemoryMappedBuffer) Unmap

func (b *MemoryMappedBuffer) Unmap(removefile bool) error

Unmap will manually delete the memory mapping of a mapped buffer

Source Files

buffer.go bytebuffer.go memorymappedbuffer.go

Version
v1.0.0-alpha
Published
Jul 11, 2016
Platform
js/wasm
Imports
7 packages
Last checked
3 weeks ago

Tools for package owners.