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
2dfb2bb8
Commit
2dfb2bb8
authored
Sep 17, 2014
by
Kamil Kisiel
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15 from dgryski/encode-struct-extra-dict
Fix struct encoding
parents
56b35bc5
0ade5ddc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
8 deletions
+23
-8
encode.go
encode.go
+1
-4
encode_test.go
encode_test.go
+22
-4
No files found.
encode.go
View file @
2dfb2bb8
...
@@ -185,10 +185,6 @@ func (e *Encoder) encodeStruct(st reflect.Value) {
...
@@ -185,10 +185,6 @@ func (e *Encoder) encodeStruct(st reflect.Value) {
return
return
}
}
e
.
w
.
Write
([]
byte
{
opEmptyDict
})
l
:=
typ
.
NumField
()
structTags
:=
getStructTags
(
st
)
structTags
:=
getStructTags
(
st
)
e
.
w
.
Write
([]
byte
{
opEmptyDict
,
opMark
})
e
.
w
.
Write
([]
byte
{
opEmptyDict
,
opMark
})
...
@@ -199,6 +195,7 @@ func (e *Encoder) encodeStruct(st reflect.Value) {
...
@@ -199,6 +195,7 @@ func (e *Encoder) encodeStruct(st reflect.Value) {
e
.
encode
(
st
.
Field
(
i
))
e
.
encode
(
st
.
Field
(
i
))
}
}
}
else
{
}
else
{
l
:=
typ
.
NumField
()
for
i
:=
0
;
i
<
l
;
i
++
{
for
i
:=
0
;
i
<
l
;
i
++
{
fty
:=
typ
.
Field
(
i
)
fty
:=
typ
.
Field
(
i
)
if
fty
.
PkgPath
!=
""
{
if
fty
.
PkgPath
!=
""
{
...
...
encode_test.go
View file @
2dfb2bb8
...
@@ -8,17 +8,30 @@ import (
...
@@ -8,17 +8,30 @@ import (
func
TestEncode
(
t
*
testing
.
T
)
{
func
TestEncode
(
t
*
testing
.
T
)
{
type
foo
struct
{
Foo
string
Bar
int32
}
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
input
interface
{}
input
interface
{}
output
interface
{}
}{
}{
{
{
"graphite message"
,
"graphite message"
,
[]
interface
{}{
map
[
interface
{}]
interface
{}{
"values"
:
[]
interface
{}{
float64
(
473
),
float64
(
497
),
float64
(
540
),
float64
(
1497
),
float64
(
1808
),
float64
(
1890
),
float64
(
2013
),
float64
(
1821
),
float64
(
1847
),
float64
(
2176
),
float64
(
2156
),
float64
(
1250
),
float64
(
2055
),
float64
(
1570
),
None
{},
None
{}},
"start"
:
int64
(
1383782400
),
"step"
:
int64
(
86400
),
"end"
:
int64
(
1385164800
),
"name"
:
"ZZZZ.UUUUUUUU.CCCCCCCC.MMMMMMMM.XXXXXXXXX.TTT"
}},
[]
interface
{}{
map
[
interface
{}]
interface
{}{
"values"
:
[]
interface
{}{
float64
(
473
),
float64
(
497
),
float64
(
540
),
float64
(
1497
),
float64
(
1808
),
float64
(
1890
),
float64
(
2013
),
float64
(
1821
),
float64
(
1847
),
float64
(
2176
),
float64
(
2156
),
float64
(
1250
),
float64
(
2055
),
float64
(
1570
),
None
{},
None
{}},
"start"
:
int64
(
1383782400
),
"step"
:
int64
(
86400
),
"end"
:
int64
(
1385164800
),
"name"
:
"ZZZZ.UUUUUUUU.CCCCCCCC.MMMMMMMM.XXXXXXXXX.TTT"
}},
nil
,
},
},
{
{
"small types"
,
"small types"
,
[]
interface
{}{
int64
(
0
),
int64
(
1
),
int64
(
258
),
int64
(
65537
),
false
,
true
},
[]
interface
{}{
int64
(
0
),
int64
(
1
),
int64
(
258
),
int64
(
65537
),
false
,
true
},
nil
,
},
{
"array of struct types"
,
[]
foo
{{
"Qux"
,
4
}},
[]
interface
{}{
map
[
interface
{}]
interface
{}{
"Foo"
:
"Qux"
,
"Bar"
:
int64
(
4
)}},
},
},
}
}
...
@@ -30,8 +43,13 @@ func TestEncode(t *testing.T) {
...
@@ -30,8 +43,13 @@ func TestEncode(t *testing.T) {
d
:=
NewDecoder
(
bytes
.
NewReader
(
p
.
Bytes
()))
d
:=
NewDecoder
(
bytes
.
NewReader
(
p
.
Bytes
()))
output
,
_
:=
d
.
Decode
()
output
,
_
:=
d
.
Decode
()
if
!
reflect
.
DeepEqual
(
tt
.
input
,
output
)
{
want
:=
tt
.
output
t
.
Errorf
(
"%s: got
\n
%q
\n
expected
\n
%q"
,
tt
.
name
,
output
,
tt
.
input
)
if
want
==
nil
{
want
=
tt
.
input
}
if
!
reflect
.
DeepEqual
(
want
,
output
)
{
t
.
Errorf
(
"%s: got
\n
%q
\n
expected
\n
%q"
,
tt
.
name
,
output
,
want
)
}
}
}
}
...
...
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