new server

This commit is contained in:
Smile Rex
2026-01-14 23:10:23 +03:00
parent 83f356cea9
commit c1df49fde1
12 changed files with 342 additions and 69 deletions

49
models/writer.go Normal file
View File

@@ -0,0 +1,49 @@
package models
import (
"encoding/binary"
"math"
)
type Writer struct {
buf []byte
}
func (w *Writer) Bytes() []byte {
return w.buf
}
func (w *Writer) WriteU8(v uint8) {
w.buf = append(w.buf, v)
}
func (w *Writer) WriteU16(v uint16) {
tmp := make([]byte, 2)
binary.LittleEndian.PutUint16(tmp, v)
w.buf = append(w.buf, tmp...)
}
func (w *Writer) WriteU32(v uint32) {
tmp := make([]byte, 4)
binary.LittleEndian.PutUint32(tmp, v)
w.buf = append(w.buf, tmp...)
}
func (w *Writer) WriteF32(v float32) {
tmp := make([]byte, 4)
binary.LittleEndian.PutUint32(tmp, math.Float32bits(v))
w.buf = append(w.buf, tmp...)
}
func (w *Writer) WriteBool(v bool) {
if v {
w.WriteU8(1)
} else {
w.WriteU8(0)
}
}
func (w *Writer) WriteString(s string) {
w.WriteU16(uint16(len(s)))
w.buf = append(w.buf, []byte(s)...)
}