Esempio n. 1
0
func (p *PropertyLoadSaver) Load(c <-chan datastore.Property) error {
	if err := datastore.LoadStruct(p, c); err != nil {
		return err
	}
	p.S += ".load"
	return nil
}
Esempio n. 2
0
func (x *storableWrap) Load(ch <-chan datastore.Property) error {
	var err error
	var all []datastore.Property
	for p := range ch {
		if !strings.HasPrefix(p.Name, internalPrefixKey) {
			all = append(all, p)
			continue
		}
		switch p.Name[len(internalPrefixKey):] { // switch on rest of key
		case keyUpdated:
			x.Updated = p.Value.(time.Time)
		default:
			// Record an error, but otherwise continue (must consume whole ch).
			err = ErrInvalidStorableData
		}
	}
	if err != nil {
		return err
	}

	// Create another channel and re-send everything not consumed.
	// TODO(samthor): In 'modern AE', PropertyLoadSaver is just given a slice instead.
	ich := make(chan datastore.Property)
	go func() {
		for _, p := range all {
			ich <- p
		}
	}()
	return datastore.LoadStruct(x, ich)
}
Esempio n. 3
0
func (score *Score) Load(c <-chan datastore.Property) os.Error {
	if err := datastore.LoadStruct(score, c); err != nil {
		return err
	}

	// 平均点を設定する。
	score.Average = float32(score.Japanese+score.Math+score.English) / 3

	return nil
}
Esempio n. 4
0
func (e *Evolution) Load(c <-chan datastore.Property) error {
	if err := datastore.LoadStruct(e, c); err != nil {
		return err
	}
	e.Ancestry = make([]evolve.Genome, e.AncestorCount)
	err := json.Unmarshal(e.AncestryBytes, &e.Ancestry)
	if err != nil {
		panic(err)
	}
	return nil
}
Esempio n. 5
0
func (notebook *Notebook) Load(c <-chan datastore.Property) error {
	// load Ordering
	prop := <-c
	reader := bytes.NewReader(prop.Value.([]byte))
	decoder := gob.NewDecoder(reader)
	err := decoder.Decode(&notebook.Order)
	if err != nil {
		return err
	}
	// load the rest
	return datastore.LoadStruct(notebook, c)
}
Esempio n. 6
0
// decode decodes b into dst using a gob.Decoder
func decode(dst interface{}, b []byte) (err error) {
	c := make(chan datastore.Property, 32)
	errc := make(chan error, 1)
	defer func() {
		if err == nil {
			err = <-errc
		}
	}()
	go gobToProperties(c, errc, b)
	if e, ok := dst.(datastore.PropertyLoadSaver); ok {
		return e.Load(c)
	}
	return datastore.LoadStruct(dst, c)
}
Esempio n. 7
0
func (u *user) Load(c <-chan datastore.Property) error {
	if err := datastore.LoadStruct(u, c); err != nil {
		return err
	}

	u.ConfirmCodes = make(map[string]string)
	for i := 0; i < len(u.confirmCodesKey); i++ {
		u.ConfirmCodes[u.confirmCodesKey[i]] = u.confirmCodesVal[i]
	}

	// should I do this?
	u.confirmCodesKey = nil
	u.confirmCodesVal = nil

	return nil
}
Esempio n. 8
0
func (d *Driver) LoadStruct(dst interface{}, c <-chan datastore.Property) error {
	// TODO: d.logOps
	return datastore.LoadStruct(dst, c)
}