flatbuffers

This commit is contained in:
Ilia Denisov
2026-03-22 19:43:45 +02:00
committed by GitHub
parent 73a4b0d3ec
commit d6a707d60e
13 changed files with 665 additions and 0 deletions
+2
View File
@@ -5,12 +5,14 @@ use (
./game ./game
./pkg/connector ./pkg/connector
./pkg/error ./pkg/error
./pkg/schema
./pkg/model ./pkg/model
./pkg/storage ./pkg/storage
./pkg/util ./pkg/util
) )
replace ( replace (
galaxy/schema v0.0.0 => ./pkg/schema
galaxy/connector v0.0.0 => ./pkg/connector galaxy/connector v0.0.0 => ./pkg/connector
galaxy/error v0.0.0 => ./pkg/error galaxy/error v0.0.0 => ./pkg/error
galaxy/model v0.0.0 => ./pkg/model galaxy/model v0.0.0 => ./pkg/model
+47
View File
@@ -0,0 +1,47 @@
namespace order;
enum Relation : byte { War = 0, Peace = 1 }
table CommandRaceQuit {}
table CommandRaceVote {
for: string;
}
table CommandRaceRelation {
relation: Relation;
for: string;
}
table CommandShipClassCreate {
drive: float32;
weapons: float32;
shields: float32;
cargo: float32;
armament: uint16;
name: string;
}
union Commands {
CommandRaceQuit,
CommandRaceVote,
CommandRaceRelation,
CommandShipClassCreate
}
struct uuid {
high: int64;
low: int64;
}
table CommandItem {
id: uuid;
command: Commands;
}
table Order {
updated_at: uint64; // utc timestamp
commands: [CommandItem];
}
root_type Order;
+92
View File
@@ -0,0 +1,92 @@
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
package order
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type CommandItem struct {
_tab flatbuffers.Table
}
func GetRootAsCommandItem(buf []byte, offset flatbuffers.UOffsetT) *CommandItem {
n := flatbuffers.GetUOffsetT(buf[offset:])
x := &CommandItem{}
x.Init(buf, n+offset)
return x
}
func FinishCommandItemBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.Finish(offset)
}
func GetSizePrefixedRootAsCommandItem(buf []byte, offset flatbuffers.UOffsetT) *CommandItem {
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
x := &CommandItem{}
x.Init(buf, n+offset+flatbuffers.SizeUint32)
return x
}
func FinishSizePrefixedCommandItemBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.FinishSizePrefixed(offset)
}
func (rcv *CommandItem) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf
rcv._tab.Pos = i
}
func (rcv *CommandItem) Table() flatbuffers.Table {
return rcv._tab
}
func (rcv *CommandItem) Id(obj *uuid) *uuid {
o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
if o != 0 {
x := o + rcv._tab.Pos
if obj == nil {
obj = new(uuid)
}
obj.Init(rcv._tab.Bytes, x)
return obj
}
return nil
}
func (rcv *CommandItem) CommandType() Commands {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
return Commands(rcv._tab.GetByte(o + rcv._tab.Pos))
}
return 0
}
func (rcv *CommandItem) MutateCommandType(n Commands) bool {
return rcv._tab.MutateByteSlot(6, byte(n))
}
func (rcv *CommandItem) Command(obj *flatbuffers.Table) bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
if o != 0 {
rcv._tab.Union(obj, o)
return true
}
return false
}
func CommandItemStart(builder *flatbuffers.Builder) {
builder.StartObject(3)
}
func CommandItemAddId(builder *flatbuffers.Builder, id flatbuffers.UOffsetT) {
builder.PrependStructSlot(0, flatbuffers.UOffsetT(id), 0)
}
func CommandItemAddCommandType(builder *flatbuffers.Builder, commandType Commands) {
builder.PrependByteSlot(1, byte(commandType), 0)
}
func CommandItemAddCommand(builder *flatbuffers.Builder, command flatbuffers.UOffsetT) {
builder.PrependUOffsetTSlot(2, flatbuffers.UOffsetT(command), 0)
}
func CommandItemEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
return builder.EndObject()
}
+49
View File
@@ -0,0 +1,49 @@
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
package order
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type CommandRaceQuit struct {
_tab flatbuffers.Table
}
func GetRootAsCommandRaceQuit(buf []byte, offset flatbuffers.UOffsetT) *CommandRaceQuit {
n := flatbuffers.GetUOffsetT(buf[offset:])
x := &CommandRaceQuit{}
x.Init(buf, n+offset)
return x
}
func FinishCommandRaceQuitBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.Finish(offset)
}
func GetSizePrefixedRootAsCommandRaceQuit(buf []byte, offset flatbuffers.UOffsetT) *CommandRaceQuit {
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
x := &CommandRaceQuit{}
x.Init(buf, n+offset+flatbuffers.SizeUint32)
return x
}
func FinishSizePrefixedCommandRaceQuitBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.FinishSizePrefixed(offset)
}
func (rcv *CommandRaceQuit) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf
rcv._tab.Pos = i
}
func (rcv *CommandRaceQuit) Table() flatbuffers.Table {
return rcv._tab
}
func CommandRaceQuitStart(builder *flatbuffers.Builder) {
builder.StartObject(0)
}
func CommandRaceQuitEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
return builder.EndObject()
}
@@ -0,0 +1,75 @@
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
package order
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type CommandRaceRelation struct {
_tab flatbuffers.Table
}
func GetRootAsCommandRaceRelation(buf []byte, offset flatbuffers.UOffsetT) *CommandRaceRelation {
n := flatbuffers.GetUOffsetT(buf[offset:])
x := &CommandRaceRelation{}
x.Init(buf, n+offset)
return x
}
func FinishCommandRaceRelationBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.Finish(offset)
}
func GetSizePrefixedRootAsCommandRaceRelation(buf []byte, offset flatbuffers.UOffsetT) *CommandRaceRelation {
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
x := &CommandRaceRelation{}
x.Init(buf, n+offset+flatbuffers.SizeUint32)
return x
}
func FinishSizePrefixedCommandRaceRelationBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.FinishSizePrefixed(offset)
}
func (rcv *CommandRaceRelation) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf
rcv._tab.Pos = i
}
func (rcv *CommandRaceRelation) Table() flatbuffers.Table {
return rcv._tab
}
func (rcv *CommandRaceRelation) Relation() Relation {
o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
if o != 0 {
return Relation(rcv._tab.GetInt8(o + rcv._tab.Pos))
}
return 0
}
func (rcv *CommandRaceRelation) MutateRelation(n Relation) bool {
return rcv._tab.MutateInt8Slot(4, int8(n))
}
func (rcv *CommandRaceRelation) For() []byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
return rcv._tab.ByteVector(o + rcv._tab.Pos)
}
return nil
}
func CommandRaceRelationStart(builder *flatbuffers.Builder) {
builder.StartObject(2)
}
func CommandRaceRelationAddRelation(builder *flatbuffers.Builder, relation Relation) {
builder.PrependInt8Slot(0, int8(relation), 0)
}
func CommandRaceRelationAddFor(builder *flatbuffers.Builder, for_ flatbuffers.UOffsetT) {
builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(for_), 0)
}
func CommandRaceRelationEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
return builder.EndObject()
}
+60
View File
@@ -0,0 +1,60 @@
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
package order
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type CommandRaceVote struct {
_tab flatbuffers.Table
}
func GetRootAsCommandRaceVote(buf []byte, offset flatbuffers.UOffsetT) *CommandRaceVote {
n := flatbuffers.GetUOffsetT(buf[offset:])
x := &CommandRaceVote{}
x.Init(buf, n+offset)
return x
}
func FinishCommandRaceVoteBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.Finish(offset)
}
func GetSizePrefixedRootAsCommandRaceVote(buf []byte, offset flatbuffers.UOffsetT) *CommandRaceVote {
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
x := &CommandRaceVote{}
x.Init(buf, n+offset+flatbuffers.SizeUint32)
return x
}
func FinishSizePrefixedCommandRaceVoteBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.FinishSizePrefixed(offset)
}
func (rcv *CommandRaceVote) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf
rcv._tab.Pos = i
}
func (rcv *CommandRaceVote) Table() flatbuffers.Table {
return rcv._tab
}
func (rcv *CommandRaceVote) For() []byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
if o != 0 {
return rcv._tab.ByteVector(o + rcv._tab.Pos)
}
return nil
}
func CommandRaceVoteStart(builder *flatbuffers.Builder) {
builder.StartObject(1)
}
func CommandRaceVoteAddFor(builder *flatbuffers.Builder, for_ flatbuffers.UOffsetT) {
builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(for_), 0)
}
func CommandRaceVoteEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
return builder.EndObject()
}
@@ -0,0 +1,135 @@
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
package order
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type CommandShipClassCreate struct {
_tab flatbuffers.Table
}
func GetRootAsCommandShipClassCreate(buf []byte, offset flatbuffers.UOffsetT) *CommandShipClassCreate {
n := flatbuffers.GetUOffsetT(buf[offset:])
x := &CommandShipClassCreate{}
x.Init(buf, n+offset)
return x
}
func FinishCommandShipClassCreateBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.Finish(offset)
}
func GetSizePrefixedRootAsCommandShipClassCreate(buf []byte, offset flatbuffers.UOffsetT) *CommandShipClassCreate {
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
x := &CommandShipClassCreate{}
x.Init(buf, n+offset+flatbuffers.SizeUint32)
return x
}
func FinishSizePrefixedCommandShipClassCreateBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.FinishSizePrefixed(offset)
}
func (rcv *CommandShipClassCreate) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf
rcv._tab.Pos = i
}
func (rcv *CommandShipClassCreate) Table() flatbuffers.Table {
return rcv._tab
}
func (rcv *CommandShipClassCreate) Drive() float32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
if o != 0 {
return rcv._tab.GetFloat32(o + rcv._tab.Pos)
}
return 0.0
}
func (rcv *CommandShipClassCreate) MutateDrive(n float32) bool {
return rcv._tab.MutateFloat32Slot(4, n)
}
func (rcv *CommandShipClassCreate) Weapons() float32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
return rcv._tab.GetFloat32(o + rcv._tab.Pos)
}
return 0.0
}
func (rcv *CommandShipClassCreate) MutateWeapons(n float32) bool {
return rcv._tab.MutateFloat32Slot(6, n)
}
func (rcv *CommandShipClassCreate) Shields() float32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
if o != 0 {
return rcv._tab.GetFloat32(o + rcv._tab.Pos)
}
return 0.0
}
func (rcv *CommandShipClassCreate) MutateShields(n float32) bool {
return rcv._tab.MutateFloat32Slot(8, n)
}
func (rcv *CommandShipClassCreate) Cargo() float32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(10))
if o != 0 {
return rcv._tab.GetFloat32(o + rcv._tab.Pos)
}
return 0.0
}
func (rcv *CommandShipClassCreate) MutateCargo(n float32) bool {
return rcv._tab.MutateFloat32Slot(10, n)
}
func (rcv *CommandShipClassCreate) Armament() uint16 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(12))
if o != 0 {
return rcv._tab.GetUint16(o + rcv._tab.Pos)
}
return 0
}
func (rcv *CommandShipClassCreate) MutateArmament(n uint16) bool {
return rcv._tab.MutateUint16Slot(12, n)
}
func (rcv *CommandShipClassCreate) Name() []byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(14))
if o != 0 {
return rcv._tab.ByteVector(o + rcv._tab.Pos)
}
return nil
}
func CommandShipClassCreateStart(builder *flatbuffers.Builder) {
builder.StartObject(6)
}
func CommandShipClassCreateAddDrive(builder *flatbuffers.Builder, drive float32) {
builder.PrependFloat32Slot(0, drive, 0.0)
}
func CommandShipClassCreateAddWeapons(builder *flatbuffers.Builder, weapons float32) {
builder.PrependFloat32Slot(1, weapons, 0.0)
}
func CommandShipClassCreateAddShields(builder *flatbuffers.Builder, shields float32) {
builder.PrependFloat32Slot(2, shields, 0.0)
}
func CommandShipClassCreateAddCargo(builder *flatbuffers.Builder, cargo float32) {
builder.PrependFloat32Slot(3, cargo, 0.0)
}
func CommandShipClassCreateAddArmament(builder *flatbuffers.Builder, armament uint16) {
builder.PrependUint16Slot(4, armament, 0)
}
func CommandShipClassCreateAddName(builder *flatbuffers.Builder, name flatbuffers.UOffsetT) {
builder.PrependUOffsetTSlot(5, flatbuffers.UOffsetT(name), 0)
}
func CommandShipClassCreateEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
return builder.EndObject()
}
+38
View File
@@ -0,0 +1,38 @@
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
package order
import "strconv"
type Commands byte
const (
CommandsNONE Commands = 0
CommandsCommandRaceQuit Commands = 1
CommandsCommandRaceVote Commands = 2
CommandsCommandRaceRelation Commands = 3
CommandsCommandShipClassCreate Commands = 4
)
var EnumNamesCommands = map[Commands]string{
CommandsNONE: "NONE",
CommandsCommandRaceQuit: "CommandRaceQuit",
CommandsCommandRaceVote: "CommandRaceVote",
CommandsCommandRaceRelation: "CommandRaceRelation",
CommandsCommandShipClassCreate: "CommandShipClassCreate",
}
var EnumValuesCommands = map[string]Commands{
"NONE": CommandsNONE,
"CommandRaceQuit": CommandsCommandRaceQuit,
"CommandRaceVote": CommandsCommandRaceVote,
"CommandRaceRelation": CommandsCommandRaceRelation,
"CommandShipClassCreate": CommandsCommandShipClassCreate,
}
func (v Commands) String() string {
if s, ok := EnumNamesCommands[v]; ok {
return s
}
return "Commands(" + strconv.FormatInt(int64(v), 10) + ")"
}
+90
View File
@@ -0,0 +1,90 @@
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
package order
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type Order struct {
_tab flatbuffers.Table
}
func GetRootAsOrder(buf []byte, offset flatbuffers.UOffsetT) *Order {
n := flatbuffers.GetUOffsetT(buf[offset:])
x := &Order{}
x.Init(buf, n+offset)
return x
}
func FinishOrderBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.Finish(offset)
}
func GetSizePrefixedRootAsOrder(buf []byte, offset flatbuffers.UOffsetT) *Order {
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
x := &Order{}
x.Init(buf, n+offset+flatbuffers.SizeUint32)
return x
}
func FinishSizePrefixedOrderBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.FinishSizePrefixed(offset)
}
func (rcv *Order) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf
rcv._tab.Pos = i
}
func (rcv *Order) Table() flatbuffers.Table {
return rcv._tab
}
func (rcv *Order) UpdatedAt() uint64 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
if o != 0 {
return rcv._tab.GetUint64(o + rcv._tab.Pos)
}
return 0
}
func (rcv *Order) MutateUpdatedAt(n uint64) bool {
return rcv._tab.MutateUint64Slot(4, n)
}
func (rcv *Order) Commands(obj *CommandItem, j int) bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
x := rcv._tab.Vector(o)
x += flatbuffers.UOffsetT(j) * 4
x = rcv._tab.Indirect(x)
obj.Init(rcv._tab.Bytes, x)
return true
}
return false
}
func (rcv *Order) CommandsLength() int {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
return rcv._tab.VectorLen(o)
}
return 0
}
func OrderStart(builder *flatbuffers.Builder) {
builder.StartObject(2)
}
func OrderAddUpdatedAt(builder *flatbuffers.Builder, updatedAt uint64) {
builder.PrependUint64Slot(0, updatedAt, 0)
}
func OrderAddCommands(builder *flatbuffers.Builder, commands flatbuffers.UOffsetT) {
builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(commands), 0)
}
func OrderStartCommandsVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT {
return builder.StartVector(4, numElems, 4)
}
func OrderEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
return builder.EndObject()
}
+29
View File
@@ -0,0 +1,29 @@
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
package order
import "strconv"
type Relation int8
const (
RelationWar Relation = 0
RelationPeace Relation = 1
)
var EnumNamesRelation = map[Relation]string{
RelationWar: "War",
RelationPeace: "Peace",
}
var EnumValuesRelation = map[string]Relation{
"War": RelationWar,
"Peace": RelationPeace,
}
func (v Relation) String() string {
if s, ok := EnumNamesRelation[v]; ok {
return s
}
return "Relation(" + strconv.FormatInt(int64(v), 10) + ")"
}
+41
View File
@@ -0,0 +1,41 @@
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
package order
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type uuid struct {
_tab flatbuffers.Struct
}
func (rcv *uuid) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf
rcv._tab.Pos = i
}
func (rcv *uuid) Table() flatbuffers.Table {
return rcv._tab.Table
}
func (rcv *uuid) Left() int64 {
return rcv._tab.GetInt64(rcv._tab.Pos + flatbuffers.UOffsetT(0))
}
func (rcv *uuid) MutateLeft(n int64) bool {
return rcv._tab.MutateInt64(rcv._tab.Pos+flatbuffers.UOffsetT(0), n)
}
func (rcv *uuid) Right() int64 {
return rcv._tab.GetInt64(rcv._tab.Pos + flatbuffers.UOffsetT(8))
}
func (rcv *uuid) MutateRight(n int64) bool {
return rcv._tab.MutateInt64(rcv._tab.Pos+flatbuffers.UOffsetT(8), n)
}
func Createuuid(builder *flatbuffers.Builder, left int64, right int64) flatbuffers.UOffsetT {
builder.Prep(8, 16)
builder.PrependInt64(right)
builder.PrependInt64(left)
return builder.Offset()
}
+5
View File
@@ -0,0 +1,5 @@
module galaxy/schema
go 1.26.0
require github.com/google/flatbuffers v25.12.19+incompatible
+2
View File
@@ -0,0 +1,2 @@
github.com/google/flatbuffers v25.12.19+incompatible h1:haMV2JRRJCe1998HeW/p0X9UaMTK6SDo0ffLn2+DbLs=
github.com/google/flatbuffers v25.12.19+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=