Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
dc419056
Commit
dc419056
authored
Jul 14, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go/zodb/zeo: Factor-out string|bytes handling into encoding
parent
ffe0d6e9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
3 deletions
+34
-3
go/zodb/storage/zeo/proto.go
go/zodb/storage/zeo/proto.go
+30
-0
go/zodb/storage/zeo/zeo.go
go/zodb/storage/zeo/zeo.go
+4
-3
No files found.
go/zodb/storage/zeo/proto.go
View file @
dc419056
...
@@ -186,3 +186,33 @@ func (e encoding) asOid(xv interface{}) (zodb.Oid, bool) {
...
@@ -186,3 +186,33 @@ func (e encoding) asOid(xv interface{}) (zodb.Oid, bool) {
v
,
ok
:=
e
.
xuint64Unpack
(
xv
)
v
,
ok
:=
e
.
xuint64Unpack
(
xv
)
return
zodb
.
Oid
(
v
),
ok
return
zodb
.
Oid
(
v
),
ok
}
}
// asBytes tries to retrieve bytes from corresponding object decoded via encoding e.
func
(
e
encoding
)
asBytes
(
xb
interface
{})
([]
byte
,
bool
)
{
switch
e
{
default
:
panic
(
"bug"
)
case
'Z'
:
// pickle: str|bytes
s
,
err
:=
pickletools
.
Xstrbytes
(
xb
)
if
err
!=
nil
{
return
nil
,
false
}
return
mem
.
Bytes
(
s
),
true
}
}
// asString tries to retrieve string from corresponding object decoded via encoding e.
func
(
e
encoding
)
asString
(
xs
interface
{})
(
string
,
bool
)
{
switch
e
{
default
:
panic
(
"bug"
)
case
'Z'
:
// pickle: str
s
,
ok
:=
xs
.
(
string
)
return
s
,
ok
}
}
go/zodb/storage/zeo/zeo.go
View file @
dc419056
...
@@ -91,7 +91,7 @@ func (z *zeo) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial zodb
...
@@ -91,7 +91,7 @@ func (z *zeo) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial zodb
return
nil
,
0
,
rpc
.
ereplyf
(
"got %#v; expect 3-tuple"
,
res
)
return
nil
,
0
,
rpc
.
ereplyf
(
"got %#v; expect 3-tuple"
,
res
)
}
}
data
,
ok1
:=
res
[
0
]
.
(
string
)
data
,
ok1
:=
enc
.
asBytes
(
res
[
0
]
)
serial
,
ok2
:=
enc
.
asTid
(
res
[
1
])
serial
,
ok2
:=
enc
.
asTid
(
res
[
1
])
// next_serial (res[2]) - just ignore
// next_serial (res[2]) - just ignore
...
@@ -99,7 +99,7 @@ func (z *zeo) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial zodb
...
@@ -99,7 +99,7 @@ func (z *zeo) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial zodb
return
nil
,
0
,
rpc
.
ereplyf
(
"got (%T, %v, %T); expect (str, tid, .)"
,
res
...
)
return
nil
,
0
,
rpc
.
ereplyf
(
"got (%T, %v, %T); expect (str, tid, .)"
,
res
...
)
}
}
return
&
mem
.
Buf
{
Data
:
mem
.
Bytes
(
data
)
},
serial
,
nil
return
&
mem
.
Buf
{
Data
:
data
},
serial
,
nil
}
}
func
(
z
*
zeo
)
Iterate
(
ctx
context
.
Context
,
tidMin
,
tidMax
zodb
.
Tid
)
zodb
.
ITxnIterator
{
func
(
z
*
zeo
)
Iterate
(
ctx
context
.
Context
,
tidMin
,
tidMax
zodb
.
Tid
)
zodb
.
ITxnIterator
{
...
@@ -202,13 +202,14 @@ func (r rpc) excError(exc string, argv []interface{}) error {
...
@@ -202,13 +202,14 @@ func (r rpc) excError(exc string, argv []interface{}) error {
// zeo5Error decodes arg of reply with msgExcept flag set and returns
// zeo5Error decodes arg of reply with msgExcept flag set and returns
// corresponding error.
// corresponding error.
func
(
r
rpc
)
zeo5Error
(
arg
interface
{})
error
{
func
(
r
rpc
)
zeo5Error
(
arg
interface
{})
error
{
enc
:=
r
.
zlink
.
enc
// ('type', (arg1, arg2, arg3, ...))
// ('type', (arg1, arg2, arg3, ...))
texc
,
ok
:=
arg
.
(
pickle
.
Tuple
)
texc
,
ok
:=
arg
.
(
pickle
.
Tuple
)
if
!
ok
||
len
(
texc
)
!=
2
{
if
!
ok
||
len
(
texc
)
!=
2
{
return
r
.
ereplyf
(
"except5: got %#v; expect 2-tuple"
,
arg
)
return
r
.
ereplyf
(
"except5: got %#v; expect 2-tuple"
,
arg
)
}
}
exc
,
ok1
:=
texc
[
0
]
.
(
string
)
exc
,
ok1
:=
enc
.
asString
(
texc
[
0
]
)
argv
,
ok2
:=
texc
[
1
]
.
(
pickle
.
Tuple
)
argv
,
ok2
:=
texc
[
1
]
.
(
pickle
.
Tuple
)
if
!
(
ok1
&&
ok2
)
{
if
!
(
ok1
&&
ok2
)
{
return
r
.
ereplyf
(
"except5: got (%T, %T); expect (str, tuple)"
,
texc
...
)
return
r
.
ereplyf
(
"except5: got (%T, %T); expect (str, tuple)"
,
texc
...
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment