me when i dont use vcs properly

This commit is contained in:
adman
2025-12-30 14:15:43 +01:00
parent 0b493d43f3
commit 8400d8f5dc
15 changed files with 192 additions and 94 deletions
+71
View File
@@ -0,0 +1,71 @@
package proto
import (
"reflect"
"github.com/admin-else/strom/proto_base"
"github.com/admin-else/strom/proto_generated"
)
// I know this is in-performant and i dont care until it becomes a problem for somebody it will stay like this and it is pretty easy to make caches or simular to speed this up so yeah
func LookUpTypeByPacketInfo(direction proto_base.Direction, state proto_base.State, pid, version int32) (p proto_base.PacketInfo, ok bool) {
for _, pin := range proto_generated.Packets {
if pin.Direction != direction || pin.State != state || pin.ProtocolVersion != version || pin.PacketId != pid {
continue
}
return pin, true
}
return
}
func LookUpTypeByPacketInfoAndCopyType(direction proto_base.Direction, state proto_base.State, pid, version int32) (p proto_base.EncodeDecodeAble, ok bool) {
i, ok := LookUpTypeByPacketInfo(direction, state, pid, version)
if !ok {
return
}
p = reflect.New(reflect.TypeOf(i.Type).Elem()).Interface().(proto_base.EncodeDecodeAble)
return
}
func LookupPacketInfoByType(packet proto_base.EncodeDecodeAble) (p proto_base.PacketInfo, ok bool) {
switch packet := packet.(type) {
case *UnCodablePacket:
p = proto_base.PacketInfo{
Type: &UnCodablePacket{},
Name: "undecodeable",
Direction: packet.Direction,
State: -1,
PacketId: -1,
ProtocolVersion: -1,
}
default:
for _, p := range proto_generated.Packets {
if reflect.TypeOf(p.Type) == reflect.TypeOf(packet) {
return p, true
}
}
}
return
}
func LookupPacketInfoByTypeAndMore(packet proto_base.EncodeDecodeAble, state proto_base.State) (p proto_base.PacketInfo, ok bool) {
switch packet := packet.(type) {
case *UnCodablePacket:
p = proto_base.PacketInfo{
Type: &UnCodablePacket{},
Name: "undecodeable",
Direction: packet.Direction,
State: -1,
PacketId: -1,
ProtocolVersion: -1,
}
default:
for _, p := range proto_generated.Packets {
if state == p.State && reflect.TypeOf(p.Type) == reflect.TypeOf(packet) {
return p, true
}
}
}
return
}