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
9dac2c66
Commit
9dac2c66
authored
Mar 09, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
506e24ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
t/neo/zodb/cmd/zodbdump/zodbdump.go
t/neo/zodb/cmd/zodbdump/zodbdump.go
+11
-2
No files found.
t/neo/zodb/cmd/zodbdump/zodbdump.go
View file @
9dac2c66
...
@@ -47,16 +47,24 @@ import (
...
@@ -47,16 +47,24 @@ import (
)
)
// dumpb pickles an object to []byte
// dumpb pickles an object to []byte
// object must be picklable (i.e. no func, chan, unsafe.Pointer, ... inside)
// objects created by pickle.Decoder are always picklable
func
dumpb
(
obj
interface
{})
[]
byte
{
func
dumpb
(
obj
interface
{})
[]
byte
{
buf
:=
bytes
.
Buffer
{}
buf
:=
bytes
.
Buffer
{}
p
:=
pickle
.
NewEncoder
(
&
buf
)
p
:=
pickle
.
NewEncoder
(
&
buf
)
err
:=
p
.
Encode
(
obj
)
err
:=
p
.
Encode
(
obj
)
// as bytes.Buffer.Write will never return an error (it panics on oom)
// the only case when we can get error here is due to non-picklable object
if
err
!=
nil
{
panic
(
fmt
.
Errorf
(
"dumpb: Non-picklable object %#v: %v"
,
obj
,
err
)
}
return
buf
.
Bytes
()
}
}
// normalizeExtPy normalizes extension to the form zodbdump/py would print it.
// normalizeExtPy normalizes
ZODB
extension to the form zodbdump/py would print it.
// specifically the dictionary pickle inside is analyzed and then ... XXX
// specifically the dictionary pickle inside is analyzed and then ... XXX
func
normalizeExtPy
(
ext
[]
byte
)
[]
byte
{
func
normalizeExtPy
(
ext
[]
byte
)
[]
byte
{
//
de
pickle ext
//
un
pickle ext
r
:=
bufio
.
NewBuffer
(
ext
)
r
:=
bufio
.
NewBuffer
(
ext
)
p
:=
pickle
.
NewDecoder
(
r
)
p
:=
pickle
.
NewDecoder
(
r
)
xv
,
_
:=
p
.
Decode
()
xv
,
_
:=
p
.
Decode
()
...
@@ -70,6 +78,7 @@ func normalizeExtPy(ext []byte) []byte {
...
@@ -70,6 +78,7 @@ func normalizeExtPy(ext []byte) []byte {
keyv
:=
make
([]
*
struct
{
key
interface
{},
kpickle
[]
byte
},
len
(
v
))
keyv
:=
make
([]
*
struct
{
key
interface
{},
kpickle
[]
byte
},
len
(
v
))
for
i
,
key
:=
range
v
{
for
i
,
key
:=
range
v
{
keyv
[
i
]
.
key
=
key
keyv
[
i
]
.
key
=
key
// NOTE key was created by pickle.Decoder - it must be picklable
keyv
[
i
]
.
kpickle
=
dumpb
(
key
)
keyv
[
i
]
.
kpickle
=
dumpb
(
key
)
}
}
...
...
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