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
da8d1520
Commit
da8d1520
authored
Jan 30, 2014
by
Kamil Kisiel
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5 from dgryski/remove-binary-read-write
Remove binary.{Read,Write} in favour of doing it by hand
parents
58cc0977
4e6b529c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
14 deletions
+34
-14
encode.go
encode.go
+9
-3
ogórek.go
ogórek.go
+25
-11
No files found.
encode.go
View file @
da8d1520
...
...
@@ -114,7 +114,9 @@ func (e *Encoder) encodeBytes(byt []byte) {
e
.
w
.
Write
([]
byte
{
opShortBinstring
,
byte
(
l
)})
}
else
{
e
.
w
.
Write
([]
byte
{
opBinstring
})
binary
.
Write
(
e
.
w
,
binary
.
LittleEndian
,
int32
(
l
))
var
b
[
4
]
byte
binary
.
LittleEndian
.
PutUint32
(
b
[
:
],
uint32
(
l
))
e
.
w
.
Write
(
b
[
:
])
}
e
.
w
.
Write
(
byt
)
...
...
@@ -124,7 +126,9 @@ func (e *Encoder) encodeFloat(f float64) {
var
u
uint64
u
=
math
.
Float64bits
(
f
)
e
.
w
.
Write
([]
byte
{
opBinfloat
})
binary
.
Write
(
e
.
w
,
binary
.
BigEndian
,
u
)
var
b
[
8
]
byte
binary
.
BigEndian
.
PutUint64
(
b
[
:
],
uint64
(
u
))
e
.
w
.
Write
(
b
[
:
])
}
func
(
e
*
Encoder
)
encodeInt
(
k
reflect
.
Kind
,
i
int64
)
{
...
...
@@ -138,7 +142,9 @@ func (e *Encoder) encodeInt(k reflect.Kind, i int64) {
e
.
w
.
Write
([]
byte
{
opBinint2
,
byte
(
i
),
byte
(
i
>>
8
)})
case
i
>=
math
.
MinInt32
&&
i
<=
math
.
MaxInt32
:
e
.
w
.
Write
([]
byte
{
opBinint
})
binary
.
Write
(
e
.
w
,
binary
.
LittleEndian
,
int32
(
i
))
var
b
[
4
]
byte
binary
.
LittleEndian
.
PutUint32
(
b
[
:
],
uint32
(
i
))
e
.
w
.
Write
(
b
[
:
])
default
:
// int64, but as a string :/
e
.
w
.
Write
([]
byte
{
opInt
})
fmt
.
Fprintf
(
e
.
w
,
"%d
\n
"
,
i
)
...
...
ogórek.go
View file @
da8d1520
...
...
@@ -307,8 +307,12 @@ func (d *Decoder) loadInt() error {
// Push a four-byte signed int
func
(
d
*
Decoder
)
loadBinInt
()
error
{
var
v
int32
binary
.
Read
(
d
.
r
,
binary
.
LittleEndian
,
&
v
)
var
b
[
4
]
byte
_
,
err
:=
io
.
ReadFull
(
d
.
r
,
b
[
:
])
if
err
!=
nil
{
return
err
}
v
:=
binary
.
LittleEndian
.
Uint32
(
b
[
:
])
d
.
push
(
int64
(
v
))
return
nil
}
...
...
@@ -334,12 +338,13 @@ func (d *Decoder) loadLong() error {
// Push a 2-byte unsigned int
func
(
d
*
Decoder
)
loadBinInt2
()
error
{
var
u
uint16
err
:=
binary
.
Read
(
d
.
r
,
binary
.
LittleEndian
,
&
u
)
var
b
[
2
]
byte
_
,
err
:=
io
.
ReadFull
(
d
.
r
,
b
[
:
]
)
if
err
!=
nil
{
return
err
}
d
.
push
(
int64
(
u
))
v
:=
binary
.
LittleEndian
.
Uint16
(
b
[
:
])
d
.
push
(
int64
(
v
))
return
nil
}
...
...
@@ -394,11 +399,12 @@ func (d *Decoder) loadString() error {
}
func
(
d
*
Decoder
)
loadBinString
()
error
{
var
v
int32
err
:=
binary
.
Read
(
d
.
r
,
binary
.
LittleEndian
,
&
v
)
var
b
[
4
]
byte
_
,
err
:=
io
.
ReadFull
(
d
.
r
,
b
[
:
]
)
if
err
!=
nil
{
return
err
}
v
:=
binary
.
LittleEndian
.
Uint32
(
b
[
:
])
s
:=
make
([]
byte
,
v
)
_
,
err
=
io
.
ReadFull
(
d
.
r
,
s
)
if
err
!=
nil
{
...
...
@@ -526,8 +532,12 @@ func (d *Decoder) inst() error {
}
func
(
d
*
Decoder
)
longBinGet
()
error
{
var
v
int32
binary
.
Read
(
d
.
r
,
binary
.
LittleEndian
,
&
v
)
var
b
[
4
]
byte
_
,
err
:=
io
.
ReadFull
(
d
.
r
,
b
[
:
])
if
err
!=
nil
{
return
err
}
v
:=
binary
.
LittleEndian
.
Uint32
(
b
[
:
])
d
.
push
(
d
.
memo
[
strconv
.
Itoa
(
int
(
v
))])
return
nil
}
...
...
@@ -599,8 +609,12 @@ func (d *Decoder) loadSetItems() error {
}
func
(
d
*
Decoder
)
binFloat
()
error
{
var
u
uint64
binary
.
Read
(
d
.
r
,
binary
.
BigEndian
,
&
u
)
var
b
[
8
]
byte
_
,
err
:=
io
.
ReadFull
(
d
.
r
,
b
[
:
])
if
err
!=
nil
{
return
err
}
u
:=
binary
.
BigEndian
.
Uint64
(
b
[
:
])
d
.
stack
=
append
(
d
.
stack
,
math
.
Float64frombits
(
u
))
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