From 66fe4d7290b1d3fb65d540785f37983f7795dedd Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 24 Sep 2016 22:34:08 -0400 Subject: [PATCH] more atoms --- ent/atoms.go | 7 +++++++ ent/string.go | 14 ++++++++++++++ ent/type.go | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 ent/string.go diff --git a/ent/atoms.go b/ent/atoms.go index 7eda21a..e4c38d6 100644 --- a/ent/atoms.go +++ b/ent/atoms.go @@ -5,6 +5,13 @@ import ( ) var atom_types = map[string]typeFn{ + "bool": func(r bit.Reader) (value, error) { + return bit.ReadBool(r), r.Err() + }, + "uint8": func(r bit.Reader) (value, error) { + // TODO: bounds check here + return uint8(bit.ReadVarInt(r)), r.Err() + }, "uint16": func(r bit.Reader) (value, error) { // TODO: bounds check here return uint16(bit.ReadVarInt(r)), r.Err() diff --git a/ent/string.go b/ent/string.go new file mode 100644 index 0000000..63aca57 --- /dev/null +++ b/ent/string.go @@ -0,0 +1,14 @@ +package ent + +import ( + "github.com/jordanorelli/hyperstone/bit" +) + +func stringType(spec *typeSpec, env *Env) tÿpe { + if spec.typeName != "CUtlStringToken" { + return nil + } + return typeFn(func(r bit.Reader) (value, error) { + return bit.ReadVarInt(r), r.Err() + }) +} diff --git a/ent/type.go b/ent/type.go index 62c6b23..e78a6bc 100644 --- a/ent/type.go +++ b/ent/type.go @@ -32,7 +32,7 @@ func parseTypeSpec(spec *typeSpec, env *Env) tÿpe { } return nil } - return coalesce(atomType, floatType, handleType, qAngleType, hSeqType, genericType) + return coalesce(atomType, floatType, handleType, qAngleType, hSeqType, genericType, stringType) } // a type error is both an error and a type. It represents a type that we were