Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
og-rek
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
og-rek
Commits
39ea1352
Commit
39ea1352
authored
Oct 20, 2014
by
Kamil Kisiel
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'no-panics' of
https://github.com/larzconwell/og-rek
into larzconwell-no-panics
parents
92c2c3bf
06476df7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
10 deletions
+43
-10
encode.go
encode.go
+9
-1
ogórek.go
ogórek.go
+29
-8
ogórek_test.go
ogórek_test.go
+5
-1
No files found.
encode.go
View file @
39ea1352
...
...
@@ -8,6 +8,14 @@ import (
"reflect"
)
type
TypeError
struct
{
typ
string
}
func
(
te
*
TypeError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"no support for type '%s'"
,
te
.
typ
)
}
// An Encoder encodes Go data structures into pickle byte stream
type
Encoder
struct
{
w
io
.
Writer
...
...
@@ -74,7 +82,7 @@ func (e *Encoder) encode(rv reflect.Value) error {
_
,
err
:=
e
.
w
.
Write
([]
byte
{
opNone
})
return
err
default
:
panic
(
fmt
.
Sprintf
(
"no support for type '%s'"
,
rk
.
String
()))
return
&
TypeError
{
typ
:
rk
.
String
()}
}
return
nil
...
...
ogórek.go
View file @
39ea1352
...
...
@@ -80,6 +80,7 @@ const (
var
errNotImplemented
=
errors
.
New
(
"unimplemented opcode"
)
var
ErrInvalidPickleVersion
=
errors
.
New
(
"invalid pickle version"
)
var
ErrNoMarker
=
errors
.
New
(
"no marker in stack"
)
type
OpcodeError
struct
{
Key
byte
...
...
@@ -243,15 +244,15 @@ func (d *Decoder) mark() {
}
// Return the position of the topmost marker
func
(
d
*
Decoder
)
marker
()
int
{
func
(
d
*
Decoder
)
marker
()
(
int
,
error
)
{
m
:=
mark
{}
var
k
int
for
k
=
len
(
d
.
stack
)
-
1
;
d
.
stack
[
k
]
!=
m
&&
k
>
0
;
k
--
{
}
if
k
>=
0
{
return
k
return
k
,
nil
}
panic
(
"no marker in stack"
)
return
0
,
ErrNoMarker
}
// Append a new value
...
...
@@ -560,7 +561,11 @@ func (d *Decoder) global() error {
}
func
(
d
*
Decoder
)
loadDict
()
error
{
k
:=
d
.
marker
()
k
,
err
:=
d
.
marker
()
if
err
!=
nil
{
return
err
}
m
:=
make
(
map
[
interface
{}]
interface
{},
0
)
items
:=
d
.
stack
[
k
+
1
:
]
for
i
:=
0
;
i
<
len
(
items
);
i
+=
2
{
...
...
@@ -577,7 +582,11 @@ func (d *Decoder) loadEmptyDict() error {
}
func
(
d
*
Decoder
)
loadAppends
()
error
{
k
:=
d
.
marker
()
k
,
err
:=
d
.
marker
()
if
err
!=
nil
{
return
err
}
l
:=
d
.
stack
[
k
-
1
]
switch
l
.
(
type
)
{
case
[]
interface
{}
:
...
...
@@ -632,14 +641,22 @@ func (d *Decoder) loadBool(b bool) error {
}
func
(
d
*
Decoder
)
loadList
()
error
{
k
:=
d
.
marker
()
k
,
err
:=
d
.
marker
()
if
err
!=
nil
{
return
err
}
v
:=
append
([]
interface
{}{},
d
.
stack
[
k
+
1
:
]
...
)
d
.
stack
=
append
(
d
.
stack
[
:
k
],
v
)
return
nil
}
func
(
d
*
Decoder
)
loadTuple
()
error
{
k
:=
d
.
marker
()
k
,
err
:=
d
.
marker
()
if
err
!=
nil
{
return
err
}
v
:=
append
([]
interface
{}{},
d
.
stack
[
k
+
1
:
]
...
)
d
.
stack
=
append
(
d
.
stack
[
:
k
],
v
)
return
nil
...
...
@@ -715,7 +732,11 @@ func (d *Decoder) loadSetItem() error {
}
func
(
d
*
Decoder
)
loadSetItems
()
error
{
k
:=
d
.
marker
()
k
,
err
:=
d
.
marker
()
if
err
!=
nil
{
return
err
}
l
:=
d
.
stack
[
k
-
1
]
switch
m
:=
l
.
(
type
)
{
case
map
[
interface
{}]
interface
{}
:
...
...
ogórek_test.go
View file @
39ea1352
...
...
@@ -18,7 +18,11 @@ func TestMarker(t *testing.T) {
buf
:=
bytes
.
Buffer
{}
dec
:=
NewDecoder
(
&
buf
)
dec
.
mark
()
if
dec
.
marker
()
!=
0
{
k
,
err
:=
dec
.
marker
()
if
err
!=
nil
{
t
.
Error
(
err
)
}
if
k
!=
0
{
t
.
Error
(
"no marker found"
)
}
}
...
...
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