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
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
dc419056
Commit
dc419056
authored
4 years ago
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
Hide 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) {
v
,
ok
:=
e
.
xuint64Unpack
(
xv
)
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
}
}
This diff is collapsed.
Click to expand it.
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
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
])
// 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
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
{
...
...
@@ -202,13 +202,14 @@ func (r rpc) excError(exc string, argv []interface{}) error {
// zeo5Error decodes arg of reply with msgExcept flag set and returns
// corresponding error.
func
(
r
rpc
)
zeo5Error
(
arg
interface
{})
error
{
enc
:=
r
.
zlink
.
enc
// ('type', (arg1, arg2, arg3, ...))
texc
,
ok
:=
arg
.
(
pickle
.
Tuple
)
if
!
ok
||
len
(
texc
)
!=
2
{
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
)
if
!
(
ok1
&&
ok2
)
{
return
r
.
ereplyf
(
"except5: got (%T, %T); expect (str, tuple)"
,
texc
...
)
...
...
This diff is collapsed.
Click to expand it.
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