this seems suspicious

types
Jordan Orelli 8 years ago
parent c372f14e33
commit ee09904289

@ -16,6 +16,9 @@ var atom_types = map[string]typeFn{
// TODO: bounds check here
return uint16(bit.ReadVarInt(r)), r.Err()
},
"uint32": func(r bit.Reader) (value, error) {
return bit.ReadVarInt32(r), r.Err()
},
"uint64": func(r bit.Reader) (value, error) {
return bit.ReadVarInt(r), r.Err()
},

@ -17,6 +17,7 @@ func floatType(spec *typeSpec, env *Env) tÿpe {
case "CNetworkedQuantizedFloat":
return qFloatType(spec, env)
case "float32":
case "Vector":
default:
return nil
}

@ -32,7 +32,8 @@ func parseTypeSpec(spec *typeSpec, env *Env) tÿpe {
}
return nil
}
return coalesce(arrayType, atomType, floatType, handleType, qAngleType, hSeqType, genericType, classType)
return coalesce(arrayType, atomType, floatType, handleType, qAngleType,
hSeqType, genericType, vectorType, classType)
}
// a type error is both an error and a type. It represents a type that we were

@ -1,3 +1,35 @@
package ent
import (
"github.com/jordanorelli/hyperstone/bit"
)
type vector struct{ x, y, z float32 }
func vectorType(spec *typeSpec, env *Env) tÿpe {
if spec.encoder != "" {
return nil
}
return vector_t{elem: floatType(spec, env)}
}
type vector_t struct {
elem tÿpe
}
func (t vector_t) read(r bit.Reader) (value, error) {
var err error
var v interface{}
read := func(f *float32) {
if err != nil {
return
}
v, err = t.elem.read(r)
*f = v.(float32)
}
var out vector
read(&out.x)
read(&out.y)
read(&out.z)
return out, err
}

Loading…
Cancel
Save