server: Client -> Peer

This commit is contained in:
2023-03-09 16:42:13 -06:00
parent 294e83d533
commit 8c52df6554
4 changed files with 49 additions and 54 deletions

View File

@@ -10,13 +10,14 @@ import (
)
/*
this file handles serializing (and deserializing) structs to alignment-strict c structures
this file handles serializing (and deserializing) structs to alignment-strict c structures generated via `tools/genstructs.py`.
see script for details on usage!
*/
type Packet struct {
ByteOrder binary.ByteOrder
Buf []byte
cursor int // to keep track of things like member alignment
cursor int // to keep track of things like member alignment for easier debugging
}
const PACK_ALIGN = 4
@@ -34,12 +35,6 @@ func (pkt *Packet) ResetCursor() {
pkt.cursor = 0
}
func (pkt *Packet) CompletePacket(typeID uint32) {
tmp := make([]byte, 4)
pkt.ByteOrder.PutUint32(tmp, typeID)
pkt.Buf = append(tmp, pkt.Buf...)
}
func (pkt *Packet) writeRaw(data []byte) {
pkt.Buf = append(pkt.Buf, data...)
pkt.cursor += len(data)