🔧 chore: 初始化番茄小说 API 项目结构
新增项目基础框架,包含核心 API 实现、算法模块、HTTP 处理器等完整功能模块
This commit is contained in:
commit
6981148727
107 files changed
+12463
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package algos
|
||||
|
||||
// ByteBuf 字节缓冲区
|
||||
type ByteBuf struct {
|
||||
mem []byte
|
||||
dataSize int
|
||||
pos int
|
||||
}
|
||||
|
||||
// NewByteBuf 创建新的字节缓冲区
|
||||
func NewByteBuf(data []byte, size *int) *ByteBuf {
|
||||
buf := &ByteBuf{
|
||||
pos: 0,
|
||||
}
|
||||
|
||||
if data != nil {
|
||||
buf.mem = data
|
||||
}
|
||||
|
||||
if size != nil {
|
||||
buf.dataSize = *size
|
||||
} else if data != nil {
|
||||
buf.dataSize = len(data)
|
||||
} else {
|
||||
panic("Either size or data must be provided")
|
||||
}
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
// Data 获取数据
|
||||
func (b *ByteBuf) Data() []byte {
|
||||
return b.mem
|
||||
}
|
||||
|
||||
// Size 获取大小
|
||||
func (b *ByteBuf) Size() int {
|
||||
return b.dataSize
|
||||
}
|
||||
|
||||
// RemovePadding 移除填充
|
||||
func (b *ByteBuf) RemovePadding() []byte {
|
||||
paddingSize := PKCS7DataLength(b.mem, b.dataSize, 16)
|
||||
if paddingSize == 0 {
|
||||
return b.mem[:b.dataSize]
|
||||
}
|
||||
b.dataSize = paddingSize
|
||||
dst := make([]byte, b.dataSize)
|
||||
copy(dst, b.mem[:b.dataSize])
|
||||
b.mem = dst
|
||||
return b.mem
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user