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.

67 lines
1.2 KiB
Go

8 years ago
package ent
8 years ago
import (
"fmt"
"github.com/jordanorelli/hyperstone/bit"
)
8 years ago
type class struct {
8 years ago
name string
version int
fields []field
}
func (c class) String() string {
return fmt.Sprintf("<%s.%d>", c.name, c.version)
8 years ago
}
func (c class) typeName() string {
return fmt.Sprintf("class:%s", c.name)
}
8 years ago
func (c *class) read(r bit.Reader) (value, error) {
bit.ReadBool(r) // ???
return c.nü(), nil
8 years ago
}
func (c *class) nü() value {
return &entity{class: c, slots: make([]value, len(c.fields))}
}
type classHistory struct {
versions map[int]*class
oldest *class
newest *class
}
func (h *classHistory) add(c *class) {
if h.oldest == nil || c.version < h.oldest.version {
h.oldest = c
}
if h.newest == nil || c.version > h.newest.version {
h.newest = c
}
if h.versions == nil {
h.versions = make(map[int]*class)
}
h.versions[c.version] = c
}
func (h *classHistory) version(v int) *class {
if h.versions == nil {
return nil
}
return h.versions[v]
}
8 years ago
func classType(spec *typeSpec, env *Env) tÿpe {
if spec.serializer != "" {
c := env.classVersion(spec.serializer, spec.serializerV)
if c != nil {
return c
8 years ago
}
return typeError("unable to find class named %s with version %d", spec.serializer, spec.serializerV)
8 years ago
}
return nil
}