mq_coder/packet.go

39 lines
725 B
Go
Raw Normal View History

2022-10-07 15:30:45 +08:00
package mq_coder
import (
"bytes"
)
2022-10-10 14:47:49 +08:00
// packet is the base type of the NodePacket and PrimitivePacket
type packet struct {
tag *Tag
length int
valBuf []byte
buf *bytes.Buffer
2022-10-07 15:30:45 +08:00
}
2022-10-10 14:47:49 +08:00
// GetRawBytes get all raw bytes of this packet
func (bp *packet) GetRawBytes() []byte {
return bp.buf.Bytes()
2022-10-07 15:30:45 +08:00
}
2022-10-10 14:47:49 +08:00
// Length return the length of Val this packet
func (bp *packet) Length() int {
return bp.length
2022-10-07 15:30:45 +08:00
}
2022-10-10 14:47:49 +08:00
// SeqId returns Tag of this packet
func (bp *packet) SeqId() byte {
return bp.tag.SeqId()
2022-10-07 15:30:45 +08:00
}
2022-10-10 14:47:49 +08:00
// IsSlice determine if the current node is a Slice
func (bp *packet) IsSlice() bool {
return bp.tag.IsSlice()
2022-10-07 15:30:45 +08:00
}
2022-10-10 14:47:49 +08:00
// GetValBuf get raw buffer of Val of this packet
func (bp *packet) GetValBuf() []byte {
return bp.valBuf
2022-10-07 15:30:45 +08:00
}