filequeue

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeadLen head 长度 文件前 xB 的数据为header 的存储空间
	HeadLen int64 = 64
	// VersionOffset 版本号在文件中下标
	VersionOffset = 0
	// BlockLenOffset  数据库在文件中下标
	BlockLenOffset = 8
	// OffsetConfigOffset 偏移量在文件中的下标
	OffsetConfigOffset = 16

	BlockValidOffset   = 0
	BlockValidLen      = 1
	BlockDataLenOffset = BlockValidOffset + BlockValidLen
	BlockDataLenLen    = 8
	BlockDataEndOffset = BlockDataLenOffset + BlockDataLenLen
)

下面部分常量不会记录在文件中

View Source
const (
	LibVersion = 1
	// DefaultOffset 默认偏移量
	DefaultOffset = 0
	// DefaultBlockLen 默认数据块长度
	DefaultBlockLen = 128
)

下面常量部分配置为默认值。并且有可能会写入文件中

Variables

This section is empty.

Functions

func Int64ToBytes

func Int64ToBytes(i int64) []byte

func OpenOrCreateFile

func OpenOrCreateFile(path string) (*os.File, error)

Types

type FileQueue

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

func NewDefaultFileQueue

func NewDefaultFileQueue(dirPath string) (*FileQueue, error)

NewDefaultFileQueue 标准队列实体,返回一个可以使用的队列管理器

func NewFileQueue

func NewFileQueue(dirPath string, blockLen int64) (*FileQueue, error)

NewFileQueue dirPath 是队列目录,blockLen 是队列的块长度,不要小于等于9。前9位用于块数据是否消费/块有效长度等数据。

func (*FileQueue) Int64ToBytes

func (itself *FileQueue) Int64ToBytes(n int64) []byte

func (*FileQueue) Len

func (itself *FileQueue) Len() int64

Len 队列有效长度,暂未实现

func (*FileQueue) Pop

func (itself *FileQueue) Pop() (string, error)

Pop 出队 计算偏移量 ,读取 数据块 ,读取长度位 ,读取对应长度数据 读取成功 设置最新的下标并写入文件

func (*FileQueue) Push

func (itself *FileQueue) Push(data string) error

Push 入队 传入数据 ,拼接数据块 有效位 长度 真实数据位 追加至文件尾

func (*FileQueue) Vacuum

func (itself *FileQueue) Vacuum() error

Vacuum 压缩文件,清理已经出队的数据

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

Jump to

Keyboard shortcuts

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