This commit is contained in:
jdl
2025-08-26 15:33:27 +02:00
parent d558ebbd14
commit ab246b2a90
28 changed files with 1093 additions and 447 deletions

View File

@@ -6,13 +6,14 @@ import "unsafe"
const (
headerSize = 12
controlStreamID = 2
controlHeaderSize = 24
dataStreamID = 1
dataHeaderSize = 12
dataStreamID = 1
controlStreamID = 2
)
type header struct {
type Header struct {
Version byte
StreamID byte
SourceIP byte
@@ -20,7 +21,7 @@ type header struct {
Counter uint64 // Init with time.Now().Unix << 30 to ensure monotonic.
}
func parseHeader(b []byte) (h header) {
func parseHeader(b []byte) (h Header) {
h.Version = b[0]
h.StreamID = b[1]
h.SourceIP = b[2]
@@ -29,7 +30,7 @@ func parseHeader(b []byte) (h header) {
return h
}
func (h *header) Parse(b []byte) {
func (h *Header) Parse(b []byte) {
h.Version = b[0]
h.StreamID = b[1]
h.SourceIP = b[2]
@@ -37,7 +38,7 @@ func (h *header) Parse(b []byte) {
h.Counter = *(*uint64)(unsafe.Pointer(&b[4]))
}
func (h *header) Marshal(buf []byte) {
func (h *Header) Marshal(buf []byte) {
buf[0] = h.Version
buf[1] = h.StreamID
buf[2] = h.SourceIP