You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.4 KiB
Go

package ent
import (
"github.com/jordanorelli/hyperstone/bit"
)
var atom_types = []typeLiteral{
{
"bool",
func(r bit.Reader) (value, error) {
return bit.ReadBool(r), r.Err()
},
8 years ago
},
{
"uint8",
func(r bit.Reader) (value, error) {
// TODO: bounds check here
return uint8(bit.ReadVarInt(r)), r.Err()
},
8 years ago
},
{
"uint16",
func(r bit.Reader) (value, error) {
// TODO: bounds check here
return uint16(bit.ReadVarInt(r)), r.Err()
},
8 years ago
},
{
"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()
},
8 years ago
},
{
"int8",
func(r bit.Reader) (value, error) {
// TODO: bounds check here
return int8(bit.ReadZigZag32(r)), r.Err()
},
8 years ago
},
{
"int32",
func(r bit.Reader) (value, error) {
return bit.ReadZigZag32(r), r.Err()
},
8 years ago
},
{
"CUtlStringToken",
func(r bit.Reader) (value, error) {
return bit.ReadVarInt(r), r.Err()
},
},
{
"Color",
func(r bit.Reader) (value, error) {
u := bit.ReadVarInt(r)
return color{
r: uint8(u >> 6 & 0xff),
g: uint8(u >> 4 & 0xff),
b: uint8(u >> 2 & 0xff),
a: uint8(u >> 0 & 0xff),
}, r.Err()
},
8 years ago
},
}
func atomType(spec *typeSpec, env *Env) tÿpe {
for _, t := range atom_types {
if t.typeName() == spec.typeName {
Debug.Printf(" atom type: %s", t.typeName())
return t
}
8 years ago
}
return nil
}
8 years ago
type color struct{ r, g, b, a uint8 }