Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-merkledag
Commits
1e0db6da
Commit
1e0db6da
authored
Apr 28, 2015
by
Henry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
godeps: move (go)goprotobuf to github location
parent
99bdf197
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
136 deletions
+114
-136
internal/pb/merkledag.pb.go
internal/pb/merkledag.pb.go
+48
-48
internal/pb/merkledagpb_test.go
internal/pb/merkledagpb_test.go
+66
-88
No files found.
internal/pb/merkledag.pb.go
View file @
1e0db6da
...
...
@@ -14,27 +14,21 @@
*/
package
merkledag_pb
import
proto
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/
code.google
.com/
p/
gogoprotobuf/proto"
import
proto
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/
github
.com/gogo
/
protobuf/proto"
import
math
"math"
// discarding unused import gogoproto "code.google.com/p/gogoprotobuf/gogoproto/gogo.pb"
import
io
"io"
import
fmt
"fmt"
import
code_google
_com_
p_
gogoprotobuf_proto
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/
code.google
.com/
p/
gogoprotobuf/proto"
import
github
_com_gogo
_
protobuf_proto
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/
github
.com/gogo
/
protobuf/proto"
import
fmt1
"fmt"
import
strings
"strings"
import
reflect
"reflect"
import
fmt2
"fmt"
import
strings1
"strings"
import
code_google_com_p_gogoprotobuf_proto1
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
import
sort
"sort"
import
strconv
"strconv"
import
reflect1
"reflect"
import
fmt3
"fmt"
import
bytes
"bytes"
// Reference imports to suppress errors if they are not otherwise used.
...
...
@@ -143,7 +137,7 @@ func (m *PBLink) Unmarshal(data []byte) error {
if
postIndex
>
l
{
return
io
.
ErrUnexpectedEOF
}
m
.
Hash
=
append
(
m
.
Hash
,
data
[
index
:
postIndex
]
...
)
m
.
Hash
=
append
(
[]
byte
{}
,
data
[
index
:
postIndex
]
...
)
index
=
postIndex
case
2
:
if
wireType
!=
2
{
...
...
@@ -195,7 +189,7 @@ func (m *PBLink) Unmarshal(data []byte) error {
}
}
index
-=
sizeOfWire
skippy
,
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Skip
(
data
[
index
:
])
skippy
,
err
:=
github
_com_gogo
_
protobuf_proto
.
Skip
(
data
[
index
:
])
if
err
!=
nil
{
return
err
}
...
...
@@ -270,7 +264,7 @@ func (m *PBNode) Unmarshal(data []byte) error {
if
postIndex
>
l
{
return
io
.
ErrUnexpectedEOF
}
m
.
Data
=
append
(
m
.
Data
,
data
[
index
:
postIndex
]
...
)
m
.
Data
=
append
(
[]
byte
{}
,
data
[
index
:
postIndex
]
...
)
index
=
postIndex
default
:
var
sizeOfWire
int
...
...
@@ -282,7 +276,7 @@ func (m *PBNode) Unmarshal(data []byte) error {
}
}
index
-=
sizeOfWire
skippy
,
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Skip
(
data
[
index
:
])
skippy
,
err
:=
github
_com_gogo
_
protobuf_proto
.
Skip
(
data
[
index
:
])
if
err
!=
nil
{
return
err
}
...
...
@@ -303,7 +297,7 @@ func (this *PBLink) String() string {
`Hash:`
+
valueToStringMerkledag
(
this
.
Hash
)
+
`,`
,
`Name:`
+
valueToStringMerkledag
(
this
.
Name
)
+
`,`
,
`Tsize:`
+
valueToStringMerkledag
(
this
.
Tsize
)
+
`,`
,
`XXX_unrecognized:`
+
fmt
1
.
Sprintf
(
"%v"
,
this
.
XXX_unrecognized
)
+
`,`
,
`XXX_unrecognized:`
+
fmt
.
Sprintf
(
"%v"
,
this
.
XXX_unrecognized
)
+
`,`
,
`}`
,
},
""
)
return
s
...
...
@@ -313,9 +307,9 @@ func (this *PBNode) String() string {
return
"nil"
}
s
:=
strings
.
Join
([]
string
{
`&PBNode{`
,
`Links:`
+
strings
.
Replace
(
fmt
1
.
Sprintf
(
"%v"
,
this
.
Links
),
"PBLink"
,
"PBLink"
,
1
)
+
`,`
,
`Links:`
+
strings
.
Replace
(
fmt
.
Sprintf
(
"%v"
,
this
.
Links
),
"PBLink"
,
"PBLink"
,
1
)
+
`,`
,
`Data:`
+
valueToStringMerkledag
(
this
.
Data
)
+
`,`
,
`XXX_unrecognized:`
+
fmt
1
.
Sprintf
(
"%v"
,
this
.
XXX_unrecognized
)
+
`,`
,
`XXX_unrecognized:`
+
fmt
.
Sprintf
(
"%v"
,
this
.
XXX_unrecognized
)
+
`,`
,
`}`
,
},
""
)
return
s
...
...
@@ -326,7 +320,7 @@ func valueToStringMerkledag(v interface{}) string {
return
"nil"
}
pv
:=
reflect
.
Indirect
(
rv
)
.
Interface
()
return
fmt
1
.
Sprintf
(
"*%v"
,
pv
)
return
fmt
.
Sprintf
(
"*%v"
,
pv
)
}
func
(
m
*
PBLink
)
Size
()
(
n
int
)
{
var
l
int
...
...
@@ -347,6 +341,7 @@ func (m *PBLink) Size() (n int) {
}
return
n
}
func
(
m
*
PBNode
)
Size
()
(
n
int
)
{
var
l
int
_
=
l
...
...
@@ -434,11 +429,7 @@ type randyMerkledag interface {
}
func
randUTF8RuneMerkledag
(
r
randyMerkledag
)
rune
{
res
:=
rune
(
r
.
Uint32
()
%
1112064
)
if
55296
<=
res
{
res
+=
2047
}
return
res
return
rune
(
r
.
Intn
(
126
-
43
)
+
43
)
}
func
randStringMerkledag
(
r
randyMerkledag
)
string
{
v6
:=
r
.
Intn
(
100
)
...
...
@@ -531,6 +522,7 @@ func (m *PBLink) MarshalTo(data []byte) (n int, err error) {
}
return
i
,
nil
}
func
(
m
*
PBNode
)
Marshal
()
(
data
[]
byte
,
err
error
)
{
size
:=
m
.
Size
()
data
=
make
([]
byte
,
size
)
...
...
@@ -569,6 +561,7 @@ func (m *PBNode) MarshalTo(data []byte) (n int, err error) {
}
return
i
,
nil
}
func
encodeFixed64Merkledag
(
data
[]
byte
,
offset
int
,
v
uint64
)
int
{
data
[
offset
]
=
uint8
(
v
)
data
[
offset
+
1
]
=
uint8
(
v
>>
8
)
...
...
@@ -600,25 +593,32 @@ func (this *PBLink) GoString() string {
if
this
==
nil
{
return
"nil"
}
s
:=
strings1
.
Join
([]
string
{
`&merkledag_pb.PBLink{`
+
`Hash:`
+
valueToGoStringMerkledag
(
this
.
Hash
,
"byte"
),
`Name:`
+
valueToGoStringMerkledag
(
this
.
Name
,
"string"
),
`Tsize:`
+
valueToGoStringMerkledag
(
this
.
Tsize
,
"uint64"
),
`XXX_unrecognized:`
+
fmt2
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
`}`
},
", "
)
s
:=
strings
.
Join
([]
string
{
`&merkledag_pb.PBLink{`
+
`Hash:`
+
valueToGoStringMerkledag
(
this
.
Hash
,
"byte"
),
`Name:`
+
valueToGoStringMerkledag
(
this
.
Name
,
"string"
),
`Tsize:`
+
valueToGoStringMerkledag
(
this
.
Tsize
,
"uint64"
),
`XXX_unrecognized:`
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
`}`
},
", "
)
return
s
}
func
(
this
*
PBNode
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
strings1
.
Join
([]
string
{
`&merkledag_pb.PBNode{`
+
`Links:`
+
fmt2
.
Sprintf
(
"%#v"
,
this
.
Links
),
`Data:`
+
valueToGoStringMerkledag
(
this
.
Data
,
"byte"
),
`XXX_unrecognized:`
+
fmt2
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
`}`
},
", "
)
s
:=
strings
.
Join
([]
string
{
`&merkledag_pb.PBNode{`
+
`Links:`
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Links
),
`Data:`
+
valueToGoStringMerkledag
(
this
.
Data
,
"byte"
),
`XXX_unrecognized:`
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
`}`
},
", "
)
return
s
}
func
valueToGoStringMerkledag
(
v
interface
{},
typ
string
)
string
{
rv
:=
reflect
1
.
ValueOf
(
v
)
rv
:=
reflect
.
ValueOf
(
v
)
if
rv
.
IsNil
()
{
return
"nil"
}
pv
:=
reflect
1
.
Indirect
(
rv
)
.
Interface
()
return
fmt
2
.
Sprintf
(
"func(v %v) *%v { return &v } ( %#v )"
,
typ
,
typ
,
pv
)
pv
:=
reflect
.
Indirect
(
rv
)
.
Interface
()
return
fmt
.
Sprintf
(
"func(v %v) *%v { return &v } ( %#v )"
,
typ
,
typ
,
pv
)
}
func
extensionToGoStringMerkledag
(
e
map
[
int32
]
code_google
_com_
p_
gogoprotobuf_proto
1
.
Extension
)
string
{
func
extensionToGoStringMerkledag
(
e
map
[
int32
]
github
_com_gogo
_
protobuf_proto
.
Extension
)
string
{
if
e
==
nil
{
return
"nil"
}
...
...
@@ -632,7 +632,7 @@ func extensionToGoStringMerkledag(e map[int32]code_google_com_p_gogoprotobuf_pro
for
_
,
k
:=
range
keys
{
ss
=
append
(
ss
,
strconv
.
Itoa
(
k
)
+
": "
+
e
[
int32
(
k
)]
.
GoString
())
}
s
+=
strings
1
.
Join
(
ss
,
","
)
+
"}"
s
+=
strings
.
Join
(
ss
,
","
)
+
"}"
return
s
}
func
(
this
*
PBLink
)
VerboseEqual
(
that
interface
{})
error
{
...
...
@@ -640,44 +640,44 @@ func (this *PBLink) VerboseEqual(that interface{}) error {
if
this
==
nil
{
return
nil
}
return
fmt
3
.
Errorf
(
"that == nil && this != nil"
)
return
fmt
.
Errorf
(
"that == nil && this != nil"
)
}
that1
,
ok
:=
that
.
(
*
PBLink
)
if
!
ok
{
return
fmt
3
.
Errorf
(
"that is not of type *PBLink"
)
return
fmt
.
Errorf
(
"that is not of type *PBLink"
)
}
if
that1
==
nil
{
if
this
==
nil
{
return
nil
}
return
fmt
3
.
Errorf
(
"that is type *PBLink but is nil && this != nil"
)
return
fmt
.
Errorf
(
"that is type *PBLink but is nil && this != nil"
)
}
else
if
this
==
nil
{
return
fmt
3
.
Errorf
(
"that is type *PBLinkbut is not nil && this == nil"
)
return
fmt
.
Errorf
(
"that is type *PBLinkbut is not nil && this == nil"
)
}
if
!
bytes
.
Equal
(
this
.
Hash
,
that1
.
Hash
)
{
return
fmt
3
.
Errorf
(
"Hash this(%v) Not Equal that(%v)"
,
this
.
Hash
,
that1
.
Hash
)
return
fmt
.
Errorf
(
"Hash this(%v) Not Equal that(%v)"
,
this
.
Hash
,
that1
.
Hash
)
}
if
this
.
Name
!=
nil
&&
that1
.
Name
!=
nil
{
if
*
this
.
Name
!=
*
that1
.
Name
{
return
fmt
3
.
Errorf
(
"Name this(%v) Not Equal that(%v)"
,
*
this
.
Name
,
*
that1
.
Name
)
return
fmt
.
Errorf
(
"Name this(%v) Not Equal that(%v)"
,
*
this
.
Name
,
*
that1
.
Name
)
}
}
else
if
this
.
Name
!=
nil
{
return
fmt
3
.
Errorf
(
"this.Name == nil && that.Name != nil"
)
return
fmt
.
Errorf
(
"this.Name == nil && that.Name != nil"
)
}
else
if
that1
.
Name
!=
nil
{
return
fmt
3
.
Errorf
(
"Name this(%v) Not Equal that(%v)"
,
this
.
Name
,
that1
.
Name
)
return
fmt
.
Errorf
(
"Name this(%v) Not Equal that(%v)"
,
this
.
Name
,
that1
.
Name
)
}
if
this
.
Tsize
!=
nil
&&
that1
.
Tsize
!=
nil
{
if
*
this
.
Tsize
!=
*
that1
.
Tsize
{
return
fmt
3
.
Errorf
(
"Tsize this(%v) Not Equal that(%v)"
,
*
this
.
Tsize
,
*
that1
.
Tsize
)
return
fmt
.
Errorf
(
"Tsize this(%v) Not Equal that(%v)"
,
*
this
.
Tsize
,
*
that1
.
Tsize
)
}
}
else
if
this
.
Tsize
!=
nil
{
return
fmt
3
.
Errorf
(
"this.Tsize == nil && that.Tsize != nil"
)
return
fmt
.
Errorf
(
"this.Tsize == nil && that.Tsize != nil"
)
}
else
if
that1
.
Tsize
!=
nil
{
return
fmt
3
.
Errorf
(
"Tsize this(%v) Not Equal that(%v)"
,
this
.
Tsize
,
that1
.
Tsize
)
return
fmt
.
Errorf
(
"Tsize this(%v) Not Equal that(%v)"
,
this
.
Tsize
,
that1
.
Tsize
)
}
if
!
bytes
.
Equal
(
this
.
XXX_unrecognized
,
that1
.
XXX_unrecognized
)
{
return
fmt
3
.
Errorf
(
"XXX_unrecognized this(%v) Not Equal that(%v)"
,
this
.
XXX_unrecognized
,
that1
.
XXX_unrecognized
)
return
fmt
.
Errorf
(
"XXX_unrecognized this(%v) Not Equal that(%v)"
,
this
.
XXX_unrecognized
,
that1
.
XXX_unrecognized
)
}
return
nil
}
...
...
@@ -732,34 +732,34 @@ func (this *PBNode) VerboseEqual(that interface{}) error {
if
this
==
nil
{
return
nil
}
return
fmt
3
.
Errorf
(
"that == nil && this != nil"
)
return
fmt
.
Errorf
(
"that == nil && this != nil"
)
}
that1
,
ok
:=
that
.
(
*
PBNode
)
if
!
ok
{
return
fmt
3
.
Errorf
(
"that is not of type *PBNode"
)
return
fmt
.
Errorf
(
"that is not of type *PBNode"
)
}
if
that1
==
nil
{
if
this
==
nil
{
return
nil
}
return
fmt
3
.
Errorf
(
"that is type *PBNode but is nil && this != nil"
)
return
fmt
.
Errorf
(
"that is type *PBNode but is nil && this != nil"
)
}
else
if
this
==
nil
{
return
fmt
3
.
Errorf
(
"that is type *PBNodebut is not nil && this == nil"
)
return
fmt
.
Errorf
(
"that is type *PBNodebut is not nil && this == nil"
)
}
if
len
(
this
.
Links
)
!=
len
(
that1
.
Links
)
{
return
fmt
3
.
Errorf
(
"Links this(%v) Not Equal that(%v)"
,
len
(
this
.
Links
),
len
(
that1
.
Links
))
return
fmt
.
Errorf
(
"Links this(%v) Not Equal that(%v)"
,
len
(
this
.
Links
),
len
(
that1
.
Links
))
}
for
i
:=
range
this
.
Links
{
if
!
this
.
Links
[
i
]
.
Equal
(
that1
.
Links
[
i
])
{
return
fmt
3
.
Errorf
(
"Links this[%v](%v) Not Equal that[%v](%v)"
,
i
,
this
.
Links
[
i
],
i
,
that1
.
Links
[
i
])
return
fmt
.
Errorf
(
"Links this[%v](%v) Not Equal that[%v](%v)"
,
i
,
this
.
Links
[
i
],
i
,
that1
.
Links
[
i
])
}
}
if
!
bytes
.
Equal
(
this
.
Data
,
that1
.
Data
)
{
return
fmt
3
.
Errorf
(
"Data this(%v) Not Equal that(%v)"
,
this
.
Data
,
that1
.
Data
)
return
fmt
.
Errorf
(
"Data this(%v) Not Equal that(%v)"
,
this
.
Data
,
that1
.
Data
)
}
if
!
bytes
.
Equal
(
this
.
XXX_unrecognized
,
that1
.
XXX_unrecognized
)
{
return
fmt
3
.
Errorf
(
"XXX_unrecognized this(%v) Not Equal that(%v)"
,
this
.
XXX_unrecognized
,
that1
.
XXX_unrecognized
)
return
fmt
.
Errorf
(
"XXX_unrecognized this(%v) Not Equal that(%v)"
,
this
.
XXX_unrecognized
,
that1
.
XXX_unrecognized
)
}
return
nil
}
...
...
internal/pb/merkledagpb_test.go
View file @
1e0db6da
...
...
@@ -17,42 +17,20 @@ package merkledag_pb
import
testing
"testing"
import
math_rand
"math/rand"
import
time
"time"
import
code_google_com_p_gogoprotobuf_proto
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
import
testing1
"testing"
import
math_rand1
"math/rand"
import
time1
"time"
import
github_com_gogo_protobuf_proto
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
import
encoding_json
"encoding/json"
import
testing2
"testing"
import
math_rand2
"math/rand"
import
time2
"time"
import
code_google_com_p_gogoprotobuf_proto1
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
import
math_rand3
"math/rand"
import
time3
"time"
import
testing3
"testing"
import
fmt
"fmt"
import
math_rand4
"math/rand"
import
time4
"time"
import
testing4
"testing"
import
code_google_com_p_gogoprotobuf_proto2
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
import
math_rand5
"math/rand"
import
time5
"time"
import
testing5
"testing"
import
fmt1
"fmt"
import
go_parser
"go/parser"
import
math_rand6
"math/rand"
import
time6
"time"
import
testing6
"testing"
import
code_google_com_p_gogoprotobuf_proto3
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
func
TestPBLinkProto
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBLink
(
popr
,
false
)
data
,
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Marshal
(
p
)
data
,
err
:=
github
_com_gogo
_
protobuf_proto
.
Marshal
(
p
)
if
err
!=
nil
{
panic
(
err
)
}
msg
:=
&
PBLink
{}
if
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Unmarshal
(
data
,
msg
);
err
!=
nil
{
if
err
:=
github
_com_gogo
_
protobuf_proto
.
Unmarshal
(
data
,
msg
);
err
!=
nil
{
panic
(
err
)
}
for
i
:=
range
data
{
...
...
@@ -79,7 +57,7 @@ func TestPBLinkMarshalTo(t *testing.T) {
panic
(
err
)
}
msg
:=
&
PBLink
{}
if
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Unmarshal
(
data
,
msg
);
err
!=
nil
{
if
err
:=
github
_com_gogo
_
protobuf_proto
.
Unmarshal
(
data
,
msg
);
err
!=
nil
{
panic
(
err
)
}
for
i
:=
range
data
{
...
...
@@ -102,7 +80,7 @@ func BenchmarkPBLinkProtoMarshal(b *testing.B) {
}
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
data
,
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Marshal
(
pops
[
i
%
10000
])
data
,
err
:=
github
_com_gogo
_
protobuf_proto
.
Marshal
(
pops
[
i
%
10000
])
if
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -116,7 +94,7 @@ func BenchmarkPBLinkProtoUnmarshal(b *testing.B) {
total
:=
0
datas
:=
make
([][]
byte
,
10000
)
for
i
:=
0
;
i
<
10000
;
i
++
{
data
,
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Marshal
(
NewPopulatedPBLink
(
popr
,
false
))
data
,
err
:=
github
_com_gogo
_
protobuf_proto
.
Marshal
(
NewPopulatedPBLink
(
popr
,
false
))
if
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -126,7 +104,7 @@ func BenchmarkPBLinkProtoUnmarshal(b *testing.B) {
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
total
+=
len
(
datas
[
i
%
10000
])
if
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Unmarshal
(
datas
[
i
%
10000
],
msg
);
err
!=
nil
{
if
err
:=
github
_com_gogo
_
protobuf_proto
.
Unmarshal
(
datas
[
i
%
10000
],
msg
);
err
!=
nil
{
panic
(
err
)
}
}
...
...
@@ -136,12 +114,12 @@ func BenchmarkPBLinkProtoUnmarshal(b *testing.B) {
func
TestPBNodeProto
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBNode
(
popr
,
false
)
data
,
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Marshal
(
p
)
data
,
err
:=
github
_com_gogo
_
protobuf_proto
.
Marshal
(
p
)
if
err
!=
nil
{
panic
(
err
)
}
msg
:=
&
PBNode
{}
if
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Unmarshal
(
data
,
msg
);
err
!=
nil
{
if
err
:=
github
_com_gogo
_
protobuf_proto
.
Unmarshal
(
data
,
msg
);
err
!=
nil
{
panic
(
err
)
}
for
i
:=
range
data
{
...
...
@@ -168,7 +146,7 @@ func TestPBNodeMarshalTo(t *testing.T) {
panic
(
err
)
}
msg
:=
&
PBNode
{}
if
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Unmarshal
(
data
,
msg
);
err
!=
nil
{
if
err
:=
github
_com_gogo
_
protobuf_proto
.
Unmarshal
(
data
,
msg
);
err
!=
nil
{
panic
(
err
)
}
for
i
:=
range
data
{
...
...
@@ -191,7 +169,7 @@ func BenchmarkPBNodeProtoMarshal(b *testing.B) {
}
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
data
,
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Marshal
(
pops
[
i
%
10000
])
data
,
err
:=
github
_com_gogo
_
protobuf_proto
.
Marshal
(
pops
[
i
%
10000
])
if
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -205,7 +183,7 @@ func BenchmarkPBNodeProtoUnmarshal(b *testing.B) {
total
:=
0
datas
:=
make
([][]
byte
,
10000
)
for
i
:=
0
;
i
<
10000
;
i
++
{
data
,
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Marshal
(
NewPopulatedPBNode
(
popr
,
false
))
data
,
err
:=
github
_com_gogo
_
protobuf_proto
.
Marshal
(
NewPopulatedPBNode
(
popr
,
false
))
if
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -215,15 +193,15 @@ func BenchmarkPBNodeProtoUnmarshal(b *testing.B) {
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
total
+=
len
(
datas
[
i
%
10000
])
if
err
:=
code_google
_com_
p_
gogoprotobuf_proto
.
Unmarshal
(
datas
[
i
%
10000
],
msg
);
err
!=
nil
{
if
err
:=
github
_com_gogo
_
protobuf_proto
.
Unmarshal
(
datas
[
i
%
10000
],
msg
);
err
!=
nil
{
panic
(
err
)
}
}
b
.
SetBytes
(
int64
(
total
/
b
.
N
))
}
func
TestPBLinkJSON
(
t
*
testing
1
.
T
)
{
popr
:=
math_rand
1
.
New
(
math_rand
1
.
NewSource
(
time
1
.
Now
()
.
UnixNano
()))
func
TestPBLinkJSON
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBLink
(
popr
,
true
)
jsondata
,
err
:=
encoding_json
.
Marshal
(
p
)
if
err
!=
nil
{
...
...
@@ -241,8 +219,8 @@ func TestPBLinkJSON(t *testing1.T) {
t
.
Fatalf
(
"%#v !Json Equal %#v"
,
msg
,
p
)
}
}
func
TestPBNodeJSON
(
t
*
testing
1
.
T
)
{
popr
:=
math_rand
1
.
New
(
math_rand
1
.
NewSource
(
time
1
.
Now
()
.
UnixNano
()))
func
TestPBNodeJSON
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBNode
(
popr
,
true
)
jsondata
,
err
:=
encoding_json
.
Marshal
(
p
)
if
err
!=
nil
{
...
...
@@ -260,12 +238,12 @@ func TestPBNodeJSON(t *testing1.T) {
t
.
Fatalf
(
"%#v !Json Equal %#v"
,
msg
,
p
)
}
}
func
TestPBLinkProtoText
(
t
*
testing
2
.
T
)
{
popr
:=
math_rand
2
.
New
(
math_rand
2
.
NewSource
(
time
2
.
Now
()
.
UnixNano
()))
func
TestPBLinkProtoText
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBLink
(
popr
,
true
)
data
:=
code_google
_com_
p_
gogoprotobuf_proto
1
.
MarshalTextString
(
p
)
data
:=
github
_com_gogo
_
protobuf_proto
.
MarshalTextString
(
p
)
msg
:=
&
PBLink
{}
if
err
:=
code_google
_com_
p_
gogoprotobuf_proto
1
.
UnmarshalText
(
data
,
msg
);
err
!=
nil
{
if
err
:=
github
_com_gogo
_
protobuf_proto
.
UnmarshalText
(
data
,
msg
);
err
!=
nil
{
panic
(
err
)
}
if
err
:=
p
.
VerboseEqual
(
msg
);
err
!=
nil
{
...
...
@@ -276,12 +254,12 @@ func TestPBLinkProtoText(t *testing2.T) {
}
}
func
TestPBLinkProtoCompactText
(
t
*
testing
2
.
T
)
{
popr
:=
math_rand
2
.
New
(
math_rand
2
.
NewSource
(
time
2
.
Now
()
.
UnixNano
()))
func
TestPBLinkProtoCompactText
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBLink
(
popr
,
true
)
data
:=
code_google
_com_
p_
gogoprotobuf_proto
1
.
CompactTextString
(
p
)
data
:=
github
_com_gogo
_
protobuf_proto
.
CompactTextString
(
p
)
msg
:=
&
PBLink
{}
if
err
:=
code_google
_com_
p_
gogoprotobuf_proto
1
.
UnmarshalText
(
data
,
msg
);
err
!=
nil
{
if
err
:=
github
_com_gogo
_
protobuf_proto
.
UnmarshalText
(
data
,
msg
);
err
!=
nil
{
panic
(
err
)
}
if
err
:=
p
.
VerboseEqual
(
msg
);
err
!=
nil
{
...
...
@@ -292,12 +270,12 @@ func TestPBLinkProtoCompactText(t *testing2.T) {
}
}
func
TestPBNodeProtoText
(
t
*
testing
2
.
T
)
{
popr
:=
math_rand
2
.
New
(
math_rand
2
.
NewSource
(
time
2
.
Now
()
.
UnixNano
()))
func
TestPBNodeProtoText
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBNode
(
popr
,
true
)
data
:=
code_google
_com_
p_
gogoprotobuf_proto
1
.
MarshalTextString
(
p
)
data
:=
github
_com_gogo
_
protobuf_proto
.
MarshalTextString
(
p
)
msg
:=
&
PBNode
{}
if
err
:=
code_google
_com_
p_
gogoprotobuf_proto
1
.
UnmarshalText
(
data
,
msg
);
err
!=
nil
{
if
err
:=
github
_com_gogo
_
protobuf_proto
.
UnmarshalText
(
data
,
msg
);
err
!=
nil
{
panic
(
err
)
}
if
err
:=
p
.
VerboseEqual
(
msg
);
err
!=
nil
{
...
...
@@ -308,12 +286,12 @@ func TestPBNodeProtoText(t *testing2.T) {
}
}
func
TestPBNodeProtoCompactText
(
t
*
testing
2
.
T
)
{
popr
:=
math_rand
2
.
New
(
math_rand
2
.
NewSource
(
time
2
.
Now
()
.
UnixNano
()))
func
TestPBNodeProtoCompactText
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBNode
(
popr
,
true
)
data
:=
code_google
_com_
p_
gogoprotobuf_proto
1
.
CompactTextString
(
p
)
data
:=
github
_com_gogo
_
protobuf_proto
.
CompactTextString
(
p
)
msg
:=
&
PBNode
{}
if
err
:=
code_google
_com_
p_
gogoprotobuf_proto
1
.
UnmarshalText
(
data
,
msg
);
err
!=
nil
{
if
err
:=
github
_com_gogo
_
protobuf_proto
.
UnmarshalText
(
data
,
msg
);
err
!=
nil
{
panic
(
err
)
}
if
err
:=
p
.
VerboseEqual
(
msg
);
err
!=
nil
{
...
...
@@ -324,8 +302,8 @@ func TestPBNodeProtoCompactText(t *testing2.T) {
}
}
func
TestPBLinkStringer
(
t
*
testing
3
.
T
)
{
popr
:=
math_rand
3
.
New
(
math_rand
3
.
NewSource
(
time
3
.
Now
()
.
UnixNano
()))
func
TestPBLinkStringer
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBLink
(
popr
,
false
)
s1
:=
p
.
String
()
s2
:=
fmt
.
Sprintf
(
"%v"
,
p
)
...
...
@@ -333,8 +311,8 @@ func TestPBLinkStringer(t *testing3.T) {
t
.
Fatalf
(
"String want %v got %v"
,
s1
,
s2
)
}
}
func
TestPBNodeStringer
(
t
*
testing
3
.
T
)
{
popr
:=
math_rand
3
.
New
(
math_rand
3
.
NewSource
(
time
3
.
Now
()
.
UnixNano
()))
func
TestPBNodeStringer
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBNode
(
popr
,
false
)
s1
:=
p
.
String
()
s2
:=
fmt
.
Sprintf
(
"%v"
,
p
)
...
...
@@ -342,11 +320,11 @@ func TestPBNodeStringer(t *testing3.T) {
t
.
Fatalf
(
"String want %v got %v"
,
s1
,
s2
)
}
}
func
TestPBLinkSize
(
t
*
testing
4
.
T
)
{
popr
:=
math_rand
4
.
New
(
math_rand
4
.
NewSource
(
time
4
.
Now
()
.
UnixNano
()))
func
TestPBLinkSize
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBLink
(
popr
,
true
)
size2
:=
code_google
_com_
p_
gogoprotobuf_proto
2
.
Size
(
p
)
data
,
err
:=
code_google
_com_
p_
gogoprotobuf_proto
2
.
Marshal
(
p
)
size2
:=
github
_com_gogo
_
protobuf_proto
.
Size
(
p
)
data
,
err
:=
github
_com_gogo
_
protobuf_proto
.
Marshal
(
p
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -357,14 +335,14 @@ func TestPBLinkSize(t *testing4.T) {
if
size2
!=
size
{
t
.
Fatalf
(
"size %v != before marshal proto.Size %v"
,
size
,
size2
)
}
size3
:=
code_google
_com_
p_
gogoprotobuf_proto
2
.
Size
(
p
)
size3
:=
github
_com_gogo
_
protobuf_proto
.
Size
(
p
)
if
size3
!=
size
{
t
.
Fatalf
(
"size %v != after marshal proto.Size %v"
,
size
,
size3
)
}
}
func
BenchmarkPBLinkSize
(
b
*
testing
4
.
B
)
{
popr
:=
math_rand
4
.
New
(
math_rand
4
.
NewSource
(
616
))
func
BenchmarkPBLinkSize
(
b
*
testing
.
B
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
616
))
total
:=
0
pops
:=
make
([]
*
PBLink
,
1000
)
for
i
:=
0
;
i
<
1000
;
i
++
{
...
...
@@ -377,11 +355,11 @@ func BenchmarkPBLinkSize(b *testing4.B) {
b
.
SetBytes
(
int64
(
total
/
b
.
N
))
}
func
TestPBNodeSize
(
t
*
testing
4
.
T
)
{
popr
:=
math_rand
4
.
New
(
math_rand
4
.
NewSource
(
time
4
.
Now
()
.
UnixNano
()))
func
TestPBNodeSize
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBNode
(
popr
,
true
)
size2
:=
code_google
_com_
p_
gogoprotobuf_proto
2
.
Size
(
p
)
data
,
err
:=
code_google
_com_
p_
gogoprotobuf_proto
2
.
Marshal
(
p
)
size2
:=
github
_com_gogo
_
protobuf_proto
.
Size
(
p
)
data
,
err
:=
github
_com_gogo
_
protobuf_proto
.
Marshal
(
p
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
@@ -392,14 +370,14 @@ func TestPBNodeSize(t *testing4.T) {
if
size2
!=
size
{
t
.
Fatalf
(
"size %v != before marshal proto.Size %v"
,
size
,
size2
)
}
size3
:=
code_google
_com_
p_
gogoprotobuf_proto
2
.
Size
(
p
)
size3
:=
github
_com_gogo
_
protobuf_proto
.
Size
(
p
)
if
size3
!=
size
{
t
.
Fatalf
(
"size %v != after marshal proto.Size %v"
,
size
,
size3
)
}
}
func
BenchmarkPBNodeSize
(
b
*
testing
4
.
B
)
{
popr
:=
math_rand
4
.
New
(
math_rand
4
.
NewSource
(
616
))
func
BenchmarkPBNodeSize
(
b
*
testing
.
B
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
616
))
total
:=
0
pops
:=
make
([]
*
PBNode
,
1000
)
for
i
:=
0
;
i
<
1000
;
i
++
{
...
...
@@ -412,11 +390,11 @@ func BenchmarkPBNodeSize(b *testing4.B) {
b
.
SetBytes
(
int64
(
total
/
b
.
N
))
}
func
TestPBLinkGoString
(
t
*
testing
5
.
T
)
{
popr
:=
math_rand
5
.
New
(
math_rand
5
.
NewSource
(
time
5
.
Now
()
.
UnixNano
()))
func
TestPBLinkGoString
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBLink
(
popr
,
false
)
s1
:=
p
.
GoString
()
s2
:=
fmt
1
.
Sprintf
(
"%#v"
,
p
)
s2
:=
fmt
.
Sprintf
(
"%#v"
,
p
)
if
s1
!=
s2
{
t
.
Fatalf
(
"GoString want %v got %v"
,
s1
,
s2
)
}
...
...
@@ -425,11 +403,11 @@ func TestPBLinkGoString(t *testing5.T) {
panic
(
err
)
}
}
func
TestPBNodeGoString
(
t
*
testing
5
.
T
)
{
popr
:=
math_rand
5
.
New
(
math_rand
5
.
NewSource
(
time
5
.
Now
()
.
UnixNano
()))
func
TestPBNodeGoString
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBNode
(
popr
,
false
)
s1
:=
p
.
GoString
()
s2
:=
fmt
1
.
Sprintf
(
"%#v"
,
p
)
s2
:=
fmt
.
Sprintf
(
"%#v"
,
p
)
if
s1
!=
s2
{
t
.
Fatalf
(
"GoString want %v got %v"
,
s1
,
s2
)
}
...
...
@@ -438,30 +416,30 @@ func TestPBNodeGoString(t *testing5.T) {
panic
(
err
)
}
}
func
TestPBLinkVerboseEqual
(
t
*
testing
6
.
T
)
{
popr
:=
math_rand
6
.
New
(
math_rand
6
.
NewSource
(
time
6
.
Now
()
.
UnixNano
()))
func
TestPBLinkVerboseEqual
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBLink
(
popr
,
false
)
data
,
err
:=
code_google
_com_
p_
gogoprotobuf_proto
3
.
Marshal
(
p
)
data
,
err
:=
github
_com_gogo
_
protobuf_proto
.
Marshal
(
p
)
if
err
!=
nil
{
panic
(
err
)
}
msg
:=
&
PBLink
{}
if
err
:=
code_google
_com_
p_
gogoprotobuf_proto
3
.
Unmarshal
(
data
,
msg
);
err
!=
nil
{
if
err
:=
github
_com_gogo
_
protobuf_proto
.
Unmarshal
(
data
,
msg
);
err
!=
nil
{
panic
(
err
)
}
if
err
:=
p
.
VerboseEqual
(
msg
);
err
!=
nil
{
t
.
Fatalf
(
"%#v !VerboseEqual %#v, since %v"
,
msg
,
p
,
err
)
}
}
func
TestPBNodeVerboseEqual
(
t
*
testing
6
.
T
)
{
popr
:=
math_rand
6
.
New
(
math_rand
6
.
NewSource
(
time
6
.
Now
()
.
UnixNano
()))
func
TestPBNodeVerboseEqual
(
t
*
testing
.
T
)
{
popr
:=
math_rand
.
New
(
math_rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
p
:=
NewPopulatedPBNode
(
popr
,
false
)
data
,
err
:=
code_google
_com_
p_
gogoprotobuf_proto
3
.
Marshal
(
p
)
data
,
err
:=
github
_com_gogo
_
protobuf_proto
.
Marshal
(
p
)
if
err
!=
nil
{
panic
(
err
)
}
msg
:=
&
PBNode
{}
if
err
:=
code_google
_com_
p_
gogoprotobuf_proto
3
.
Unmarshal
(
data
,
msg
);
err
!=
nil
{
if
err
:=
github
_com_gogo
_
protobuf_proto
.
Unmarshal
(
data
,
msg
);
err
!=
nil
{
panic
(
err
)
}
if
err
:=
p
.
VerboseEqual
(
msg
);
err
!=
nil
{
...
...
@@ -469,4 +447,4 @@ func TestPBNodeVerboseEqual(t *testing6.T) {
}
}
//These tests are generated by
code.google
.com/
p/
gogoprotobuf/plugin/testgen
//These tests are generated by
github
.com/gogo
/
protobuf/plugin/testgen
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