slotted interface
parent
de885e32fc
commit
efdf9e3d54
@ -1,47 +1,11 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/jordanorelli/hyperstone/bit"
|
||||
)
|
||||
|
||||
type Entity struct {
|
||||
*Class
|
||||
slots []interface{}
|
||||
serial int
|
||||
slots []interface{}
|
||||
}
|
||||
|
||||
func (e *Entity) Read(br bit.Reader, sr *selectionReader) error {
|
||||
if e.Class == nil {
|
||||
return fmt.Errorf("unable to read entity: entity has no class")
|
||||
}
|
||||
Debug.Printf("entity %v read", e)
|
||||
|
||||
if err := sr.read(br, htree); err != nil {
|
||||
return fmt.Errorf("unable to read entity: %v", err)
|
||||
}
|
||||
|
||||
for _, s := range sr.selections() {
|
||||
switch s.count {
|
||||
case 0:
|
||||
panic("field selection makes no sense")
|
||||
case 1:
|
||||
Debug.Printf("direct selection: %v", s.path())
|
||||
field := e.Class.Fields[s.vals[0]]
|
||||
Debug.Printf("field: %v", e.Class.Fields[s.vals[0]])
|
||||
fn := field.decoder
|
||||
if fn == nil {
|
||||
Info.Fatalf("field has no decoder: %v", field)
|
||||
}
|
||||
v, err := fn(br), br.Err()
|
||||
Debug.Printf("value: %v err: %v", v, err)
|
||||
if err != nil {
|
||||
Info.Fatalf("field decode error: %v", err)
|
||||
}
|
||||
default:
|
||||
Debug.Printf("child selection: %v", s.path())
|
||||
return fmt.Errorf("child selections aren't done yet")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (e *Entity) getSlotValue(n int) interface{} { return e.slots[n] }
|
||||
func (e *Entity) setSlotValue(n int, v interface{}) { e.slots[n] = v }
|
||||
func (e *Entity) getSlotDecoder(n int) decoder { return e.Class.Fields[n].decoder }
|
||||
|
@ -0,0 +1,25 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"github.com/jordanorelli/hyperstone/bit"
|
||||
)
|
||||
|
||||
type slotted interface {
|
||||
getSlotValue(int) interface{}
|
||||
setSlotValue(int, interface{})
|
||||
getSlotDecoder(int) decoder
|
||||
}
|
||||
|
||||
func fillSlots(dest slotted, sr *selectionReader, br bit.Reader) error {
|
||||
selections, err := sr.readSelections(br, htree)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, s := range selections {
|
||||
if err := s.fill(dest, br); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue