// WriteProperty writes a Property to the buffer. `context` behaves the same // way that it does for WriteKey, but only has an effect if `p` contains a // Key as its Value. func WriteProperty(buf Buffer, context KeyContext, p ds.Property) (err error) { defer recoverTo(&err) typb := byte(p.Type()) if p.IndexSetting() != ds.NoIndex { typb |= 0x80 } panicIf(buf.WriteByte(typb)) switch p.Type() { case ds.PTNull: case ds.PTBool: b := p.Value().(bool) if b { err = buf.WriteByte(1) } else { err = buf.WriteByte(0) } case ds.PTInt: _, err = cmpbin.WriteInt(buf, p.Value().(int64)) case ds.PTFloat: _, err = cmpbin.WriteFloat64(buf, p.Value().(float64)) case ds.PTString: _, err = cmpbin.WriteString(buf, p.Value().(string)) case ds.PTBytes: _, err = cmpbin.WriteBytes(buf, p.Value().([]byte)) case ds.PTTime: err = WriteTime(buf, p.Value().(time.Time)) case ds.PTGeoPoint: err = WriteGeoPoint(buf, p.Value().(ds.GeoPoint)) case ds.PTKey: err = WriteKey(buf, context, p.Value().(ds.Key)) case ds.PTBlobKey: _, err = cmpbin.WriteString(buf, string(p.Value().(blobstore.Key))) } return }
// writePropertyImpl is an implementation of WriteProperty and // WriteIndexProperty. func writePropertyImpl(buf Buffer, context KeyContext, p *ds.Property, index bool) (err error) { defer recoverTo(&err) it, v := p.IndexTypeAndValue() if !index { it = p.Type() } typb := byte(it) if p.IndexSetting() != ds.NoIndex { typb |= 0x80 } panicIf(buf.WriteByte(typb)) err = writeIndexValue(buf, context, v) return }
func dsF2RProp(ctx context.Context, in ds.Property) (datastore.Property, error) { err := error(nil) ret := datastore.Property{ NoIndex: in.IndexSetting() == ds.NoIndex, } switch in.Type() { case ds.PTBytes: v := in.Value().([]byte) if in.IndexSetting() == ds.ShouldIndex { ret.Value = datastore.ByteString(v) } else { ret.Value = v } case ds.PTKey: ret.Value, err = dsF2R(ctx, in.Value().(*ds.Key)) case ds.PTBlobKey: ret.Value = appengine.BlobKey(in.Value().(bs.Key)) case ds.PTGeoPoint: ret.Value = appengine.GeoPoint(in.Value().(ds.GeoPoint)) default: ret.Value = in.Value() } return ret, err }