bit_buffer

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

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 1 Imported by: 1

README

go-bit-buffer

一、这是什么?

可以申请一块bit缓存空间,可以一个bit一个bit的写入,用于方便进行位操作。

二、安装

go get -u github.com/compression-algorithm-research-lab/go-bit-buffer

三、API示例

package main

import (
	"fmt"
	bit_buffer "github.com/compression-algorithm-research-lab/go-bit-buffer"
)

func main() {

	// 创建一块缓存空间,可以一个bit一个bit的往里面写
	buffer := bit_buffer.New().Append(1).Append(0)

	// 转为二进制字符串
	binaryString := buffer.ToBinaryString()
	fmt.Println(binaryString) // Output: 10000000

	// 转为字节数组
	bytes := buffer.Bytes()
	fmt.Println(bytes) // Output: [128]

}

Documentation

Index

Constants

View Source
const BitBeginOffset = 7

Variables

This section is empty.

Functions

This section is empty.

Types

type BitBuffer

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

BitBuffer 在bit级别提供一些便于操作的API

func New

func New() *BitBuffer

New 创建一个可以用来写数据的位缓存空间

func (*BitBuffer) Bytes

func (x *BitBuffer) Bytes() []byte

Bytes 返回当前缓存空间所对应的字节数组

func (*BitBuffer) Capacity

func (x *BitBuffer) Capacity() int

Capacity 获取当前的容量

func (*BitBuffer) GetSeek

func (x *BitBuffer) GetSeek() int

GetSeek 获取当前写指针

func (*BitBuffer) IsTail

func (x *BitBuffer) IsTail() bool

IsTail 是否已经存在尾部了

func (*BitBuffer) ReadBit

func (x *BitBuffer) ReadBit() int

ReadBit 从seek读取一个bit

func (*BitBuffer) Seek

func (x *BitBuffer) Seek(offset int) *BitBuffer

Seek 移动指针到指定的position

func (*BitBuffer) SeekHead

func (x *BitBuffer) SeekHead() *BitBuffer

SeekHead 移动操作指针到头部

func (*BitBuffer) SeekTail

func (x *BitBuffer) SeekTail() *BitBuffer

SeekTail 移动指针到尾部

func (*BitBuffer) SetBytes

func (x *BitBuffer) SetBytes(bytes []byte) *BitBuffer

SetBytes 设置buff底层的字节数组

func (*BitBuffer) ToBinaryString

func (x *BitBuffer) ToBinaryString() string

ToBinaryString 把当前的缓存空间转换为二进制字符串

func (*BitBuffer) WriteBit

func (x *BitBuffer) WriteBit(bitValue int) *BitBuffer

WriteBit 往缓存空间追加一个bit,会获取 bitValue 的最低位的bit值,1或者0

func (*BitBuffer) WriteByte

func (x *BitBuffer) WriteByte(b byte) *BitBuffer

WriteByte 往缓存空间一次追加一个byte

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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