From f1c4db00fb604e621cce5220f74087a55f6b172a Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Fri, 23 Sep 2016 18:36:04 -0400 Subject: [PATCH] uint16 plz6 plz6 plz6 plz6 plz6 plz --- ent/atoms.go | 16 ++++++++++++++++ ent/field.go | 33 +++++---------------------------- ent/misc.go | 37 +++++++++++++++++++++++++++++++++++++ ent/type.go | 4 +++- 4 files changed, 61 insertions(+), 29 deletions(-) create mode 100644 ent/atoms.go diff --git a/ent/atoms.go b/ent/atoms.go new file mode 100644 index 0000000..6e4be52 --- /dev/null +++ b/ent/atoms.go @@ -0,0 +1,16 @@ +package ent + +import ( + "github.com/jordanorelli/hyperstone/bit" +) + +var atom_types = map[string]tÿpe{ + "uint16": {"uint16", func(...interface{}) value { return new(uint16_v) }}, +} + +type uint16_v uint16 + +func (u *uint16_v) read(r bit.Reader) error { + *u = uint16_v(bit.ReadVarInt(r)) + return r.Err() +} diff --git a/ent/field.go b/ent/field.go index f8dfdc1..cc18357 100644 --- a/ent/field.go +++ b/ent/field.go @@ -1,7 +1,6 @@ package ent import ( - "bytes" "fmt" "github.com/jordanorelli/hyperstone/dota" ) @@ -15,33 +14,11 @@ func (f *field) fromProto(flat *dota.ProtoFlattenedSerializerFieldT, env *Env) e var_name := env.symbol(int(flat.GetVarNameSym())) var_type := env.symbol(int(flat.GetVarTypeSym())) - var pretty bytes.Buffer - fmt.Fprintf(&pretty, "{name: %s type: %s", var_name, var_type) - if flat.BitCount != nil { - fmt.Fprintf(&pretty, " bits: %d", flat.GetBitCount()) + if t, ok := atom_types[var_type]; ok { + f.name = var_name + f.tÿpe = t + return nil } - if flat.LowValue != nil { - fmt.Fprintf(&pretty, " low: %f", flat.GetLowValue()) - } - if flat.HighValue != nil { - fmt.Fprintf(&pretty, " high: %f", flat.GetHighValue()) - } - if flat.EncodeFlags != nil { - fmt.Fprintf(&pretty, " flags: %d", flat.GetEncodeFlags()) - } - if flat.FieldSerializerNameSym != nil { - fmt.Fprintf(&pretty, " serializer: %s", env.symbol(int(flat.GetFieldSerializerNameSym()))) - } - if flat.FieldSerializerVersion != nil { - fmt.Fprintf(&pretty, " s_version: %d", flat.GetFieldSerializerVersion()) - } - if flat.SendNodeSym != nil { - fmt.Fprintf(&pretty, " send: %s", env.symbol(int(flat.GetSendNodeSym()))) - } - if flat.VarEncoderSym != nil { - fmt.Fprintf(&pretty, " var_enc: %s", env.symbol(int(flat.GetVarEncoderSym()))) - } - fmt.Fprint(&pretty, "}") - return fmt.Errorf("unable to parse type: %s", pretty.String()) + return fmt.Errorf("unable to parse type: %s", prettyFlatField(flat, env)) } diff --git a/ent/misc.go b/ent/misc.go index f79d0db..8c08273 100644 --- a/ent/misc.go +++ b/ent/misc.go @@ -1,6 +1,9 @@ package ent import ( + "bytes" + "fmt" + "github.com/golang/protobuf/proto" "github.com/jordanorelli/hyperstone/bit" @@ -25,3 +28,37 @@ func getSerializers(m *dota.CDemoSendTables) (*dota.CSVCMsg_FlattenedSerializer, } return &flat, nil } + +func prettyFlatField(flat *dota.ProtoFlattenedSerializerFieldT, env *Env) string { + var_name := env.symbol(int(flat.GetVarNameSym())) + var_type := env.symbol(int(flat.GetVarTypeSym())) + + var pretty bytes.Buffer + fmt.Fprintf(&pretty, "{name: %s type: %s", var_name, var_type) + if flat.BitCount != nil { + fmt.Fprintf(&pretty, " bits: %d", flat.GetBitCount()) + } + if flat.LowValue != nil { + fmt.Fprintf(&pretty, " low: %f", flat.GetLowValue()) + } + if flat.HighValue != nil { + fmt.Fprintf(&pretty, " high: %f", flat.GetHighValue()) + } + if flat.EncodeFlags != nil { + fmt.Fprintf(&pretty, " flags: %d", flat.GetEncodeFlags()) + } + if flat.FieldSerializerNameSym != nil { + fmt.Fprintf(&pretty, " serializer: %s", env.symbol(int(flat.GetFieldSerializerNameSym()))) + } + if flat.FieldSerializerVersion != nil { + fmt.Fprintf(&pretty, " s_version: %d", flat.GetFieldSerializerVersion()) + } + if flat.SendNodeSym != nil { + fmt.Fprintf(&pretty, " send: %s", env.symbol(int(flat.GetSendNodeSym()))) + } + if flat.VarEncoderSym != nil { + fmt.Fprintf(&pretty, " var_enc: %s", env.symbol(int(flat.GetVarEncoderSym()))) + } + fmt.Fprint(&pretty, "}") + return pretty.String() +} diff --git a/ent/type.go b/ent/type.go index 31583d9..6213c78 100644 --- a/ent/type.go +++ b/ent/type.go @@ -1,4 +1,6 @@ package ent -type tÿpe interface { +type tÿpe struct { + name string + alloc func(...interface{}) value }