read numbers

master
Jordan Orelli 8 years ago
parent 2691879d4f
commit de885e32fc

@ -106,6 +106,14 @@ func ReadString(r Reader) string {
return buf.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 // reads a ZigZag-encoded 32 bit signed integer
func ReadZigZag32(r Reader) int32 { func ReadZigZag32(r Reader) int32 {
u := ReadVarInt32(r) u := ReadVarInt32(r)

@ -17,10 +17,12 @@ func newFieldDecoder(n *Namespace, f *Field) decoder {
switch f._type.String() { switch f._type.String() {
case "bool": case "bool":
return decodeBool return decodeBool
case "float32":
return floatDecoder(f)
case "uint8", "uint16", "uint32", "uint64", "Color": case "uint8", "uint16", "uint32", "uint64", "Color":
return decodeVarInt64 return decodeVarInt64
case "int8", "int16", "int32", "int64":
return decodeZigZag
case "float32":
return floatDecoder(f)
case "Vector": case "Vector":
return vectorDecoder(f) 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 decodeBool(br bit.Reader) interface{} { return bit.ReadBool(br) }
func decodeVarInt32(br bit.Reader) interface{} { return bit.ReadVarInt32(br) } func decodeVarInt32(br bit.Reader) interface{} { return bit.ReadVarInt32(br) }
func decodeVarInt64(br bit.Reader) interface{} { return bit.ReadVarInt(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 { func floatDecoder(f *Field) decoder {
if f.bits <= 0 || f.bits >= 32 { if f.bits <= 0 || f.bits >= 32 {

@ -40,6 +40,7 @@ func (e *Entity) Read(br bit.Reader, sr *selectionReader) error {
} }
default: default:
Debug.Printf("child selection: %v", s.path()) Debug.Printf("child selection: %v", s.path())
return fmt.Errorf("child selections aren't done yet")
} }
} }
return nil return nil

Loading…
Cancel
Save