{"modulePath":"github.com/performancecopilot/speed","version":"v1.0.0-alpha","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package bytebuffer\n\nPackage bytebuffer implements a java like bytebuffer for go\n\ninitially 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\n\nanother 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\n\n\tpos = writeString(buffer, pos, \"mmv\")\n\nwhich became unmaintainable after a while, and along with all the side maintenance looked extremely ugly\n\nthis (tries) to implement a minimal buffer wrapper that gives the freedom to move around and write anywhere you want\n\n## Types\n\n```go\ntype Buffer interface {\n\tio.Writer\n\tBytes() []byte\n\tPos() int\n\tSetPos(int) error\n\tLen() int\n\tWriteVal(val interface{}) error\n\tWriteString(string) error\n\tWriteInt32(int32) error\n\tWriteInt64(int64) error\n\tWriteUint32(uint32) error\n\tWriteUint64(uint64) error\n\tWriteFloat32(float32) error\n\tWriteFloat64(float64) error\n}\n```\nBuffer defines an abstraction for an object that allows writing of binary values anywhere within a fixed range\n\n```go\ntype ByteBuffer struct {\n\t// contains filtered or unexported fields\n}\n```\nByteBuffer is a simple wrapper over a byte slice that supports writing anywhere\n\n```go\nfunc NewByteBuffer(n int) *ByteBuffer\n```\nNewByteBuffer creates a new ByteBuffer of the specified size\n\n```go\nfunc NewByteBufferSlice(buffer []byte) *ByteBuffer\n```\nNewByteBufferSlice creates a new ByteBuffer using the passed slice\n\n```go\nfunc (b *ByteBuffer) Bytes() []byte\n```\nBytes returns the internal byte array of the ByteBuffer\n\n```go\nfunc (b *ByteBuffer) Len() int\n```\nLen returns the maximum size of the ByteBuffer\n\n```go\nfunc (b *ByteBuffer) Pos() int\n```\nPos returns the current write position of the ByteBuffer\n\n```go\nfunc (b *ByteBuffer) SetPos(position int) error\n```\nSetPos sets the write position of the ByteBuffer to the specified position\n\n```go\nfunc (b *ByteBuffer) Write(data []byte) (int, error)\n```\n\n```go\nfunc (b *ByteBuffer) WriteFloat32(val float32) error\n```\nWriteFloat32 writes an float32 to the buffer\n\n```go\nfunc (b *ByteBuffer) WriteFloat64(val float64) error\n```\nWriteFloat64 writes an float64 to the buffer\n\n```go\nfunc (b *ByteBuffer) WriteInt32(val int32) error\n```\nWriteInt32 writes an int32 to the buffer\n\n```go\nfunc (b *ByteBuffer) WriteInt64(val int64) error\n```\nWriteInt64 writes an int64 to the buffer\n\n```go\nfunc (b *ByteBuffer) WriteString(val string) error\n```\nWriteString writes a string to the buffer\n\n```go\nfunc (b *ByteBuffer) WriteUint32(val uint32) error\n```\nWriteUint32 writes an uint32 to the buffer\n\n```go\nfunc (b *ByteBuffer) WriteUint64(val uint64) error\n```\nWriteUint64 writes an uint64 to the buffer\n\n```go\nfunc (b *ByteBuffer) WriteVal(val interface{}) error\n```\nWriteVal writes an arbitrary value to the buffer\n\n```go\ntype MemoryMappedBuffer struct {\n\t*ByteBuffer\n\t// contains filtered or unexported fields\n}\n```\nMemoryMappedBuffer is a ByteBuffer that is also mapped into memory\n\n```go\nfunc NewMemoryMappedBuffer(loc string, size int) (*MemoryMappedBuffer, error)\n```\nNewMemoryMappedBuffer will create and return a new instance of a MemoryMappedBuffer\n\n```go\nfunc (b *MemoryMappedBuffer) Unmap(removefile bool) error\n```\nUnmap will manually delete the memory mapping of a mapped buffer\n\n","path":"github.com/performancecopilot/speed/bytebuffer","name":"bytebuffer","synopsis":"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.","isRedistributable":true}
