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
977e18f0
Commit
977e18f0
authored
Nov 24, 2013
by
Kamil Kisiel
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3 from dgryski/more-encoding-decoding-work
A few more small fixes to the encoder and decoder.
parents
66358694
9112562f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
12 deletions
+39
-12
encode.go
encode.go
+7
-4
ogórek.go
ogórek.go
+32
-8
No files found.
encode.go
View file @
977e18f0
...
@@ -132,13 +132,16 @@ func (e *Encoder) encodeInt(k reflect.Kind, i int64) {
...
@@ -132,13 +132,16 @@ func (e *Encoder) encodeInt(k reflect.Kind, i int64) {
// FIXME: need support for 64-bit ints
// FIXME: need support for 64-bit ints
switch
{
switch
{
case
i
>
0
&&
i
<
math
.
Max
I
nt8
:
case
i
>
0
&&
i
<
math
.
Max
Ui
nt8
:
e
.
w
.
Write
([]
byte
{
opBinint1
,
byte
(
i
)})
e
.
w
.
Write
([]
byte
{
opBinint1
,
byte
(
i
)})
case
i
>
0
&&
i
<
math
.
Max
I
nt16
:
case
i
>
0
&&
i
<
math
.
Max
Ui
nt16
:
e
.
w
.
Write
([]
byte
{
opBinint2
,
byte
(
i
>>
8
),
byte
(
i
)})
e
.
w
.
Write
([]
byte
{
opBinint2
,
byte
(
i
),
byte
(
i
>>
8
)})
default
:
case
i
>=
math
.
MinInt32
&&
i
<=
math
.
MaxInt32
:
e
.
w
.
Write
([]
byte
{
opBinint
})
e
.
w
.
Write
([]
byte
{
opBinint
})
binary
.
Write
(
e
.
w
,
binary
.
LittleEndian
,
int32
(
i
))
binary
.
Write
(
e
.
w
,
binary
.
LittleEndian
,
int32
(
i
))
default
:
// int64, but as a string :/
e
.
w
.
Write
([]
byte
{
opInt
})
fmt
.
Fprintf
(
e
.
w
,
"%d
\n
"
,
i
)
}
}
}
}
...
...
ogórek.go
View file @
977e18f0
...
@@ -334,7 +334,13 @@ func (d *Decoder) loadLong() error {
...
@@ -334,7 +334,13 @@ func (d *Decoder) loadLong() error {
// Push a 2-byte unsigned int
// Push a 2-byte unsigned int
func
(
d
*
Decoder
)
loadBinInt2
()
error
{
func
(
d
*
Decoder
)
loadBinInt2
()
error
{
return
errNotImplemented
var
u
uint16
err
:=
binary
.
Read
(
d
.
r
,
binary
.
LittleEndian
,
&
u
)
if
err
!=
nil
{
return
err
}
d
.
push
(
int64
(
u
))
return
nil
}
}
// Push None
// Push None
...
@@ -388,13 +394,27 @@ func (d *Decoder) loadString() error {
...
@@ -388,13 +394,27 @@ func (d *Decoder) loadString() error {
}
}
func
(
d
*
Decoder
)
loadBinString
()
error
{
func
(
d
*
Decoder
)
loadBinString
()
error
{
return
errNotImplemented
var
v
int32
err
:=
binary
.
Read
(
d
.
r
,
binary
.
LittleEndian
,
&
v
)
if
err
!=
nil
{
return
err
}
s
:=
make
([]
byte
,
v
)
_
,
err
=
io
.
ReadFull
(
d
.
r
,
s
)
if
err
!=
nil
{
return
err
}
d
.
push
(
string
(
s
))
return
nil
}
}
func
(
d
*
Decoder
)
loadShortBinString
()
error
{
func
(
d
*
Decoder
)
loadShortBinString
()
error
{
b
,
_
:=
d
.
r
.
ReadByte
()
b
,
_
:=
d
.
r
.
ReadByte
()
s
:=
make
([]
byte
,
b
)
s
:=
make
([]
byte
,
b
)
d
.
r
.
Read
(
s
)
_
,
err
:=
io
.
ReadFull
(
d
.
r
,
s
)
if
err
!=
nil
{
return
err
}
d
.
push
(
string
(
s
))
d
.
push
(
string
(
s
))
return
nil
return
nil
}
}
...
@@ -491,7 +511,9 @@ func (d *Decoder) get() error {
...
@@ -491,7 +511,9 @@ func (d *Decoder) get() error {
}
}
func
(
d
*
Decoder
)
binGet
()
error
{
func
(
d
*
Decoder
)
binGet
()
error
{
return
errNotImplemented
b
,
_
:=
d
.
r
.
ReadByte
()
d
.
push
(
d
.
memo
[
strconv
.
Itoa
(
int
(
b
))])
return
nil
}
}
func
(
d
*
Decoder
)
inst
()
error
{
func
(
d
*
Decoder
)
inst
()
error
{
...
@@ -499,7 +521,10 @@ func (d *Decoder) inst() error {
...
@@ -499,7 +521,10 @@ func (d *Decoder) inst() error {
}
}
func
(
d
*
Decoder
)
longBinGet
()
error
{
func
(
d
*
Decoder
)
longBinGet
()
error
{
return
errNotImplemented
var
v
int32
binary
.
Read
(
d
.
r
,
binary
.
LittleEndian
,
&
v
)
d
.
push
(
d
.
memo
[
strconv
.
Itoa
(
int
(
v
))])
return
nil
}
}
func
(
d
*
Decoder
)
loadList
()
error
{
func
(
d
*
Decoder
)
loadList
()
error
{
...
@@ -569,9 +594,8 @@ func (d *Decoder) loadSetItems() error {
...
@@ -569,9 +594,8 @@ func (d *Decoder) loadSetItems() error {
}
}
func
(
d
*
Decoder
)
binFloat
()
error
{
func
(
d
*
Decoder
)
binFloat
()
error
{
f
:=
make
([]
byte
,
8
)
var
u
uint64
d
.
r
.
Read
(
f
)
binary
.
Read
(
d
.
r
,
binary
.
BigEndian
,
&
u
)
u
:=
binary
.
BigEndian
.
Uint64
(
f
)
d
.
stack
=
append
(
d
.
stack
,
math
.
Float64frombits
(
u
))
d
.
stack
=
append
(
d
.
stack
,
math
.
Float64frombits
(
u
))
return
nil
return
nil
}
}
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