代码拉取完成,页面将自动刷新
package cassandra
import (
"fmt"
"net"
)
type ByteArrayDecoder struct {
Data *[]byte
}
func readInt(p []byte) int32 {
return int32(p[0])<<24 | int32(p[1])<<16 | int32(p[2])<<8 | int32(p[3])
}
func (f ByteArrayDecoder) ReadByte() (byte, error) {
data := *f.Data
if len(data) < 1 {
panic(fmt.Errorf("not enough bytes in buffer to Read byte require 1 got: %d", len(data)))
}
b := data[0]
*f.Data = data[1:]
return b, nil
}
func (f ByteArrayDecoder) ReadInt() (n int) {
data := *f.Data
if len(data) < 4 {
panic(fmt.Errorf("not enough bytes in buffer to Read int require 4 got: %d", len(data)))
}
n = int(int32(data[0])<<24 | int32(data[1])<<16 | int32(data[2])<<8 | int32(data[3]))
*f.Data = data[4:]
return
}
func (f ByteArrayDecoder) ReadShort() (n uint16) {
data := *f.Data
if len(data) < 2 {
panic(fmt.Errorf("not enough bytes in buffer to Read short require 2 got: %d", len(data)))
}
n = uint16(data[0])<<8 | uint16(data[1])
*f.Data = data[2:]
return
}
func (f ByteArrayDecoder) ReadLong() (n int64) {
data := *f.Data
if len(data) < 8 {
panic(fmt.Errorf("not enough bytes in buffer to Read long require 8 got: %d", len(data)))
}
n = int64(data[0])<<56 | int64(data[1])<<48 | int64(data[2])<<40 | int64(data[3])<<32 |
int64(data[4])<<24 | int64(data[5])<<16 | int64(data[6])<<8 | int64(data[7])
*f.Data = data[8:]
return
}
func (f ByteArrayDecoder) ReadString() (s string) {
size := f.ReadShort()
data := *f.Data
if len(data) < int(size) {
panic(fmt.Errorf("not enough bytes in buffer to Read string require %d got: %d", size, len(data)))
}
s = string(data[:size])
*f.Data = data[size:]
return
}
func (f ByteArrayDecoder) ReadLongString() (s string) {
size := f.ReadInt()
data := *f.Data
if len(data) < size {
panic(fmt.Errorf("not enough bytes in buffer to Read long string require %d got: %d", size, len(data)))
}
s = string(data[:size])
*f.Data = data[size:]
return
}
func (f ByteArrayDecoder) ReadUUID() *UUID {
data := *f.Data
if len(data) < 16 {
panic(fmt.Errorf("not enough bytes in buffer to Read uuid require %d got: %d", 16, len(data)))
}
u, _ := UUIDFromBytes(data[:16])
*f.Data = data[16:]
return &u
}
func (f ByteArrayDecoder) ReadStringList() []string {
size := f.ReadShort()
l := make([]string, size)
for i := 0; i < int(size); i++ {
l[i] = f.ReadString()
}
return l
}
func (f ByteArrayDecoder) ReadBytesInternal() []byte {
size := f.ReadInt()
if size < 0 {
return nil
}
data := *f.Data
if len(data) < size {
panic(fmt.Errorf("not enough bytes in buffer to Read bytes require %d got: %d", size, len(data)))
}
l := data[:size]
*f.Data = data[size:]
return l
}
func (f ByteArrayDecoder) ReadBytes() []byte {
l := f.ReadBytesInternal()
return l
}
func (f ByteArrayDecoder) ReadShortBytes() []byte {
size := f.ReadShort()
data := *f.Data
if len(data) < int(size) {
panic(fmt.Errorf("not enough bytes in buffer to Read short bytes: require %d got %d", size, len(data)))
}
l := data[:size]
*f.Data = data[size:]
return l
}
func (f ByteArrayDecoder) ReadInet() (net.IP, int) {
data := *f.Data
if len(data) < 1 {
panic(fmt.Errorf("not enough bytes in buffer to Read inet size require %d got: %d", 1, len(data)))
}
size := data[0]
*f.Data = data[1:]
if !(size == 4 || size == 16) {
panic(fmt.Errorf("invalid IP size: %d", size))
}
data = *f.Data
if len(data) < 1 {
panic(fmt.Errorf("not enough bytes in buffer to Read inet require %d got: %d", size, len(data)))
}
ip := make([]byte, size)
copy(ip, data[:size])
*f.Data = data[size:]
port := f.ReadInt()
return net.IP(ip), port
}
func (f ByteArrayDecoder) ReadConsistency() Consistency {
return Consistency(f.ReadShort())
}
func (f ByteArrayDecoder) ReadStringMap() map[string]string {
size := f.ReadShort()
m := make(map[string]string)
for i := 0; i < int(size); i++ {
k := f.ReadString()
v := f.ReadString()
m[k] = v
}
return m
}
func (f ByteArrayDecoder) ReadBytesMap() map[string][]byte {
size := f.ReadShort()
m := make(map[string][]byte)
for i := 0; i < int(size); i++ {
k := f.ReadString()
v := f.ReadBytes()
m[k] = v
}
return m
}
func (f ByteArrayDecoder) ReadStringMultiMap() map[string][]string {
size := f.ReadShort()
m := make(map[string][]string)
for i := 0; i < int(size); i++ {
k := f.ReadString()
v := f.ReadStringList()
m[k] = v
}
return m
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。