From de885e32fc3de862dac34bc6b2b871603f821b1c Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Mon, 12 Sep 2016 20:05:41 -0400 Subject: [PATCH] read numbers --- bit/decode.go | 8 ++++++++ ent/decoders.go | 7 +++++-- ent/entity.go | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bit/decode.go b/bit/decode.go index bdf49c4..e098b46 100644 --- a/bit/decode.go +++ b/bit/decode.go @@ -106,6 +106,14 @@ func ReadString(r Reader) string { return buf.String() } +func ReadZigZag(r Reader) int64 { + u := ReadVarInt(r) + if u&1 > 0 { + return ^int64(u >> 1) + } + return int64(u >> 1) +} + // reads a ZigZag-encoded 32 bit signed integer func ReadZigZag32(r Reader) int32 { u := ReadVarInt32(r) diff --git a/ent/decoders.go b/ent/decoders.go index 1e631ff..bcaacd6 100644 --- a/ent/decoders.go +++ b/ent/decoders.go @@ -17,10 +17,12 @@ func newFieldDecoder(n *Namespace, f *Field) decoder { switch f._type.String() { case "bool": return decodeBool - case "float32": - return floatDecoder(f) case "uint8", "uint16", "uint32", "uint64", "Color": return decodeVarInt64 + case "int8", "int16", "int32", "int64": + return decodeZigZag + case "float32": + return floatDecoder(f) case "Vector": return vectorDecoder(f) } @@ -40,6 +42,7 @@ func newFieldDecoder(n *Namespace, f *Field) decoder { func decodeBool(br bit.Reader) interface{} { return bit.ReadBool(br) } func decodeVarInt32(br bit.Reader) interface{} { return bit.ReadVarInt32(br) } func decodeVarInt64(br bit.Reader) interface{} { return bit.ReadVarInt(br) } +func decodeZigZag(br bit.Reader) interface{} { return bit.ReadZigZag(br) } func floatDecoder(f *Field) decoder { if f.bits <= 0 || f.bits >= 32 { diff --git a/ent/entity.go b/ent/entity.go index 658646c..6a16256 100644 --- a/ent/entity.go +++ b/ent/entity.go @@ -40,6 +40,7 @@ func (e *Entity) Read(br bit.Reader, sr *selectionReader) error { } default: Debug.Printf("child selection: %v", s.path()) + return fmt.Errorf("child selections aren't done yet") } } return nil