Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1005)

Unified Diff: service/datastore/serialize/serialize.go

Issue 2569923002: Split Buffer into WriteBuffer/ReadBuffer. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « service/datastore/serialize/invertible.go ('k') | service/datastore/serialize/serialize_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/serialize/serialize.go
diff --git a/service/datastore/serialize/serialize.go b/service/datastore/serialize/serialize.go
index cc929f5deaf536d68c4791a3fa3491070970986c..60ad530f8acc079a158681980c10c03b51b22073 100644
--- a/service/datastore/serialize/serialize.go
+++ b/service/datastore/serialize/serialize.go
@@ -51,7 +51,7 @@ const (
// WriteKey encodes a key to the buffer. If context is WithContext, then this
// encoded value will include the appid and namespace of the key.
-func WriteKey(buf Buffer, context KeyContext, k *ds.Key) (err error) {
+func WriteKey(buf WriteBuffer, context KeyContext, k *ds.Key) (err error) {
// [appid ++ namespace]? ++ [1 ++ token]* ++ NULL
defer recoverTo(&err)
appid, namespace, toks := k.Split()
@@ -75,7 +75,7 @@ func WriteKey(buf Buffer, context KeyContext, k *ds.Key) (err error) {
// the value of context that was passed to WriteKey when the key was encoded.
// If context == WithoutContext, then the appid and namespace parameters are
// used in the decoded Key. Otherwise they're ignored.
-func ReadKey(buf Buffer, context KeyContext, inKC ds.KeyContext) (ret *ds.Key, err error) {
+func ReadKey(buf ReadBuffer, context KeyContext, inKC ds.KeyContext) (ret *ds.Key, err error) {
defer recoverTo(&err)
actualCtx, e := buf.ReadByte()
panicIf(e)
@@ -121,7 +121,7 @@ func ReadKey(buf Buffer, context KeyContext, inKC ds.KeyContext) (ret *ds.Key, e
// WriteKeyTok writes a KeyTok to the buffer. You usually want WriteKey
// instead of this.
-func WriteKeyTok(buf Buffer, tok ds.KeyTok) (err error) {
+func WriteKeyTok(buf WriteBuffer, tok ds.KeyTok) (err error) {
// tok.kind ++ typ ++ [tok.stringID || tok.intID]
defer recoverTo(&err)
_, e := cmpbin.WriteString(buf, tok.Kind)
@@ -140,7 +140,7 @@ func WriteKeyTok(buf Buffer, tok ds.KeyTok) (err error) {
// ReadKeyTok reads a KeyTok from the buffer. You usually want ReadKey
// instead of this.
-func ReadKeyTok(buf Buffer) (ret ds.KeyTok, err error) {
+func ReadKeyTok(buf ReadBuffer) (ret ds.KeyTok, err error) {
defer recoverTo(&err)
e := error(nil)
ret.Kind, _, e = cmpbin.ReadString(buf)
@@ -164,7 +164,7 @@ func ReadKeyTok(buf Buffer) (ret ds.KeyTok, err error) {
}
// WriteGeoPoint writes a GeoPoint to the buffer.
-func WriteGeoPoint(buf Buffer, gp ds.GeoPoint) (err error) {
+func WriteGeoPoint(buf WriteBuffer, gp ds.GeoPoint) (err error) {
defer recoverTo(&err)
_, e := cmpbin.WriteFloat64(buf, gp.Lat)
panicIf(e)
@@ -173,7 +173,7 @@ func WriteGeoPoint(buf Buffer, gp ds.GeoPoint) (err error) {
}
// ReadGeoPoint reads a GeoPoint from the buffer.
-func ReadGeoPoint(buf Buffer) (gp ds.GeoPoint, err error) {
+func ReadGeoPoint(buf ReadBuffer) (gp ds.GeoPoint, err error) {
defer recoverTo(&err)
e := error(nil)
gp.Lat, _, e = cmpbin.ReadFloat64(buf)
@@ -192,7 +192,7 @@ func ReadGeoPoint(buf Buffer) (gp ds.GeoPoint, err error) {
//
// The supplied time is rounded via datastore.RoundTime and written as a
// microseconds-since-epoch integer to comform to datastore storage standards.
-func WriteTime(buf Buffer, t time.Time) error {
+func WriteTime(buf WriteBuffer, t time.Time) error {
name, off := t.Zone()
if name != "UTC" || off != 0 {
panic(fmt.Errorf("helper: UTC OR DEATH: %s", t))
@@ -203,7 +203,7 @@ func WriteTime(buf Buffer, t time.Time) error {
}
// ReadTime reads a time.Time from the buffer.
-func ReadTime(buf Buffer) (time.Time, error) {
+func ReadTime(buf ReadBuffer) (time.Time, error) {
v, _, err := cmpbin.ReadInt(buf)
if err != nil {
return time.Time{}, err
@@ -214,20 +214,20 @@ func ReadTime(buf Buffer) (time.Time, error) {
// 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 IndexValue.
-func WriteProperty(buf Buffer, context KeyContext, p ds.Property) error {
+func WriteProperty(buf WriteBuffer, context KeyContext, p ds.Property) error {
return writePropertyImpl(buf, context, &p, false)
}
// WriteIndexProperty writes a Property to the buffer as its native index type.
// `context` behaves the same way that it does for WriteKey, but only has an
// effect if `p` contains a Key as its IndexValue.
-func WriteIndexProperty(buf Buffer, context KeyContext, p ds.Property) error {
+func WriteIndexProperty(buf WriteBuffer, context KeyContext, p ds.Property) error {
return writePropertyImpl(buf, context, &p, true)
}
// writePropertyImpl is an implementation of WriteProperty and
// WriteIndexProperty.
-func writePropertyImpl(buf Buffer, context KeyContext, p *ds.Property, index bool) (err error) {
+func writePropertyImpl(buf WriteBuffer, context KeyContext, p *ds.Property, index bool) (err error) {
defer recoverTo(&err)
it, v := p.IndexTypeAndValue()
@@ -248,7 +248,7 @@ func writePropertyImpl(buf Buffer, context KeyContext, p *ds.Property, index boo
//
// v may be one of the return types from ds.Property's GetIndexTypeAndValue
// method.
-func writeIndexValue(buf Buffer, context KeyContext, v interface{}) (err error) {
+func writeIndexValue(buf WriteBuffer, context KeyContext, v interface{}) (err error) {
switch t := v.(type) {
case nil:
case bool:
@@ -279,7 +279,7 @@ func writeIndexValue(buf Buffer, context KeyContext, v interface{}) (err error)
// ReadProperty reads a Property from the buffer. `context` and `kc` behave the
// same way they do for ReadKey, but only have an effect if the decoded property
// has a Key value.
-func ReadProperty(buf Buffer, context KeyContext, kc ds.KeyContext) (p ds.Property, err error) {
+func ReadProperty(buf ReadBuffer, context KeyContext, kc ds.KeyContext) (p ds.Property, err error) {
val := interface{}(nil)
b, err := buf.ReadByte()
if err != nil {
@@ -331,7 +331,7 @@ func ReadProperty(buf Buffer, context KeyContext, kc ds.KeyContext) (p ds.Proper
// 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) {
+func WritePropertyMap(buf WriteBuffer, context KeyContext, pm ds.PropertyMap) (err error) {
defer recoverTo(&err)
rows := make(sort.StringSlice, 0, len(pm))
tmpBuf := &bytes.Buffer{}
@@ -375,7 +375,7 @@ func WritePropertyMap(buf Buffer, context KeyContext, pm ds.PropertyMap) (err er
// ReadPropertyMap reads a PropertyMap from the buffer. `context` and
// friends behave the same way that they do for ReadKey.
-func ReadPropertyMap(buf Buffer, context KeyContext, kc ds.KeyContext) (pm ds.PropertyMap, err error) {
+func ReadPropertyMap(buf ReadBuffer, context KeyContext, kc ds.KeyContext) (pm ds.PropertyMap, err error) {
defer recoverTo(&err)
numRows := uint64(0)
@@ -420,7 +420,7 @@ func ReadPropertyMap(buf Buffer, context KeyContext, kc ds.KeyContext) (pm ds.Pr
}
// WriteIndexColumn writes an IndexColumn to the buffer.
-func WriteIndexColumn(buf Buffer, c ds.IndexColumn) (err error) {
+func WriteIndexColumn(buf WriteBuffer, c ds.IndexColumn) (err error) {
defer recoverTo(&err)
if !c.Descending {
@@ -433,7 +433,7 @@ func WriteIndexColumn(buf Buffer, c ds.IndexColumn) (err error) {
}
// ReadIndexColumn reads an IndexColumn from the buffer.
-func ReadIndexColumn(buf Buffer) (c ds.IndexColumn, err error) {
+func ReadIndexColumn(buf ReadBuffer) (c ds.IndexColumn, err error) {
defer recoverTo(&err)
dir, err := buf.ReadByte()
@@ -445,7 +445,7 @@ func ReadIndexColumn(buf Buffer) (c ds.IndexColumn, err error) {
}
// WriteIndexDefinition writes an IndexDefinition to the buffer
-func WriteIndexDefinition(buf Buffer, i ds.IndexDefinition) (err error) {
+func WriteIndexDefinition(buf WriteBuffer, i ds.IndexDefinition) (err error) {
defer recoverTo(&err)
_, err = cmpbin.WriteString(buf, i.Kind)
@@ -463,7 +463,7 @@ func WriteIndexDefinition(buf Buffer, i ds.IndexDefinition) (err error) {
}
// ReadIndexDefinition reads an IndexDefinition from the buffer.
-func ReadIndexDefinition(buf Buffer) (i ds.IndexDefinition, err error) {
+func ReadIndexDefinition(buf ReadBuffer) (i ds.IndexDefinition, err error) {
defer recoverTo(&err)
i.Kind, _, err = cmpbin.ReadString(buf)
« no previous file with comments | « service/datastore/serialize/invertible.go ('k') | service/datastore/serialize/serialize_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698