本文整理汇总了Golang中github.com/luci/gae/service/datastore.PropertyMap.Save方法的典型用法代码示例。如果您正苦于以下问题:Golang PropertyMap.Save方法的具体用法?Golang PropertyMap.Save怎么用?Golang PropertyMap.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/luci/gae/service/datastore.PropertyMap
的用法示例。
在下文中一共展示了PropertyMap.Save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WritePropertyMap
// WritePropertyMap writes an entire PropertyMap to the buffer. `context`
// behaves the same way that it does for WriteKey.
//
// If WritePropertyMapDeterministic is true, then the rows will be sorted by
// property name before they're serialized to buf (mostly useful for testing,
// but also potentially useful if you need to make a hash of the property data).
//
// Write skips metadata keys.
func WritePropertyMap(buf Buffer, context KeyContext, pm ds.PropertyMap) (err error) {
defer recoverTo(&err)
rows := make(sort.StringSlice, 0, len(pm))
tmpBuf := &bytes.Buffer{}
pm, _ = pm.Save(false)
for name, vals := range pm {
tmpBuf.Reset()
_, e := cmpbin.WriteString(tmpBuf, name)
panicIf(e)
_, e = cmpbin.WriteUint(tmpBuf, uint64(len(vals)))
panicIf(e)
for _, p := range vals {
panicIf(WriteProperty(tmpBuf, context, p))
}
rows = append(rows, tmpBuf.String())
}
if WritePropertyMapDeterministic {
rows.Sort()
}
_, e := cmpbin.WriteUint(buf, uint64(len(pm)))
panicIf(e)
for _, r := range rows {
_, e := buf.WriteString(r)
panicIf(e)
}
return
}
示例2: encodeItemValue
func encodeItemValue(pm ds.PropertyMap) []byte {
pm, _ = pm.Save(false)
buf := bytes.Buffer{}
// errs can't happen, since we're using a byte buffer.
_ = buf.WriteByte(byte(NoCompression))
_ = serialize.WritePropertyMap(&buf, serialize.WithoutContext, pm)
data := buf.Bytes()
if buf.Len() > CompressionThreshold {
buf2 := bytes.NewBuffer(make([]byte, 0, len(data)))
_ = buf2.WriteByte(byte(ZlibCompression))
writer := zlib.NewWriter(buf2)
_, _ = writer.Write(data[1:]) // skip the NoCompression byte
writer.Close()
data = buf2.Bytes()
}
return data
}