Commit ffe0d6e9 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/zeo: proto: Use enc.<X> and enc.as<X> to encode/decode type X

This is more uniform and will be followed by all data types in the next patch.
Here rename tid/oid pack/unpack routines correspondingly.
Add docstrings for X=tid|oid.
parent 0696cd64
......@@ -38,8 +38,8 @@ import (
// msg represents 1 message.
// arg is arbitrary argument(s) passed/received along ZEO call or reply.
//
// for objects in arg user code has to obtain them via encoding.*Unpack() and
// set them via encoding.*Pack() methods that
// for objects in arg user code has to obtain them via encoding.as*() and
// set them via encoding.Tid(), encoding.Oid() and other similar methods that
// convert application-level data into objects properly corresponding to wire
// encoding of messages.
type msg struct {
......@@ -165,20 +165,24 @@ func (e encoding) xuint64Pack(v uint64) string {
}
}
func (e encoding) tidPack(tid zodb.Tid) string {
// Tid converts tid into corresponding object appropriate for encoding e.
func (e encoding) Tid(tid zodb.Tid) string {
return e.xuint64Pack(uint64(tid))
}
func (e encoding) oidPack(oid zodb.Oid) string {
// Oid converts oid into corresponding object appropriate for encoding e.
func (e encoding) Oid(oid zodb.Oid) string {
return e.xuint64Pack(uint64(oid))
}
func (e encoding) tidUnpack(xv interface{}) (zodb.Tid, bool) {
// asTid tries to retrieve Tid from corresponding object decoded via encoding e.
func (e encoding) asTid(xv interface{}) (zodb.Tid, bool) {
v, ok := e.xuint64Unpack(xv)
return zodb.Tid(v), ok
}
func (e encoding) oidUnpack(xv interface{}) (zodb.Oid, bool) {
// asOid tries to retrieve Oid from corresponding object decoded via encoding e.
func (e encoding) asOid(xv interface{}) (zodb.Oid, bool) {
v, ok := e.xuint64Unpack(xv)
return zodb.Oid(v), ok
}
......@@ -63,7 +63,7 @@ func (z *zeo) Sync(ctx context.Context) (head zodb.Tid, err error) {
return zodb.InvalidTid, err
}
head, ok := z.link.enc.tidUnpack(xhead)
head, ok := z.link.enc.asTid(xhead)
if !ok {
return zodb.InvalidTid, rpc.ereplyf("got %v; expect tid", xhead)
}
......@@ -80,7 +80,7 @@ func (z *zeo) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial zodb
rpc := z.rpc("loadBefore")
enc := z.link.enc
xres, err := rpc.call(ctx, enc.oidPack(xid.Oid), enc.tidPack(xid.At+1)) // XXX at2Before
xres, err := rpc.call(ctx, enc.Oid(xid.Oid), enc.Tid(xid.At+1)) // XXX at2Before
if err != nil {
return nil, 0, err
}
......@@ -92,7 +92,7 @@ func (z *zeo) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial zodb
}
data, ok1 := res[0].(string)
serial, ok2 := enc.tidUnpack(res[1])
serial, ok2 := enc.asTid(res[1])
// next_serial (res[2]) - just ignore
if !(ok1 && ok2) {
......@@ -184,7 +184,7 @@ func (r rpc) excError(exc string, argv []interface{}) error {
return r.ereplyf("poskeyerror: got %#v; expect 1-tuple", argv...)
}
oid, ok := r.zlink.enc.oidUnpack(argv[0])
oid, ok := r.zlink.enc.asOid(argv[0])
if !ok {
return r.ereplyf("poskeyerror: got (%v); expect (oid)", argv[0])
}
......@@ -361,7 +361,7 @@ func openByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (_ zodb
}
}
lastTid, ok := zlink.enc.tidUnpack(xlastTid) // XXX -> xlastTid -> scan
lastTid, ok := zlink.enc.asTid(xlastTid) // XXX -> xlastTid -> scan
if !ok {
return nil, zodb.InvalidTid, rpc.ereplyf("got %v; expect tid", xlastTid)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment