drbuffer

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

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

Go to latest
Published: Jul 13, 2016 License: MIT Imports: 7 Imported by: 0

README

drbuffer

druable ring buffer (drbuffer) with variable length element

buffer, err := Open("/tmp/drbuffer", 1 /*in kb*/)
if err != nil {
    return nil
}
defer buffer.Close()
// push one packet ([]byte)
// must ensure the packet pushed do not exceed 65535 byte
buffer.PushOne([]byte("Hello")) 
// batch push multiple packets
buffer.PushN([][]byte{
    []byte("A"),
    []byte("B"),
}) 
// if nothing to pop, packet will be nil
packet := buffer.PopOne() 
fmt.Println(string(packet))
// packets is array of []byte
packets := buffer.PopN() 

Documentation

Index

Constants

View Source
const IS_DEBUG = false
View Source
const MAX_PACKETS_READ_ONE_TIME = 1024
View Source
const META_SECTION_SIZE = 16 // 4 for version 4 for nextWriteFrom 4 for lastReadTo 4 for wrapAt

Variables

This section is empty.

Functions

func NewRingBuffer

func NewRingBuffer(meta []byte, buffer []byte) *ringBuffer

Types

type DurableRingBuffer

type DurableRingBuffer interface {
	PushN(packets [][]byte)
	PushOne(packet []byte)
	PopN(n int) [][]byte
	PopOne() []byte
	Flush() error
	Close() error
}

func Open

func Open(filePath string, nkiloBytes int) (DurableRingBuffer, error)

Jump to

Keyboard shortcuts

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