godeps: move (go)goprotobuf to github location
Henry committed
Apr 28, 2015 at 12:33 UTC
5fff7742f3ce67cf3e6b09a01fa34c8b59e48b07
101 files changed
+683
-12795
Godeps/Godeps.json
+8
-13
@@ -19,19 +19,6 @@
19
"Comment": "null-240",
20
"Rev": "937a34c9de13c766c814510f76bca091dee06028"
21
},
22
- {
23
- "ImportPath": "code.google.com/p/gogoprotobuf/io",
24
- "Rev": "6c980277330804e94257ac7ef70a3adbe1641059"
25
- },
26
- {
27
- "ImportPath": "code.google.com/p/gogoprotobuf/proto",
28
- "Rev": "6c980277330804e94257ac7ef70a3adbe1641059"
29
- },
30
- {
31
- "ImportPath": "code.google.com/p/goprotobuf/proto",
32
- "Comment": "go.r60-152",
33
- "Rev": "36be16571e14f67e114bb0af619e5de2c1591679"
34
- },
22
{
23
"ImportPath": "github.com/ActiveState/tail",
24
"Rev": "068b72961a6bc5b4a82cf4fc14ccc724c0cfa73a"
@@ -111,6 +98,14 @@
98
"Comment": "v0.5.1",
99
"Rev": "27a863cdffdb0998d13e1e11992b18489aeeaa25"
100
},
101
+ {
102
+ "ImportPath": "github.com/gogo/protobuf/io",
103
+ "Rev": "0ac967c269268f1af7d9bcc7927ccc9a589b2b36"
104
+ },
105
+ {
106
+ "ImportPath": "github.com/gogo/protobuf/proto",
107
+ "Rev": "0ac967c269268f1af7d9bcc7927ccc9a589b2b36"
108
+ },
109
{
110
"ImportPath": "github.com/h2so5/utp",
111
"Rev": "654d875bb65e96729678180215cf080fe2810371"
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/Makefile
deleted
-40
@@ -1,40 +0,0 @@
1
-# Go support for Protocol Buffers - Google's data interchange format
2
-#
3
-# Copyright 2010 The Go Authors. All rights reserved.
4
-# http://code.google.com/p/goprotobuf/
5
-#
6
-# Redistribution and use in source and binary forms, with or without
7
-# modification, are permitted provided that the following conditions are
8
-# met:
9
-#
10
-# * Redistributions of source code must retain the above copyright
11
-# notice, this list of conditions and the following disclaimer.
12
-# * Redistributions in binary form must reproduce the above
13
-# copyright notice, this list of conditions and the following disclaimer
14
-# in the documentation and/or other materials provided with the
15
-# distribution.
16
-# * Neither the name of Google Inc. nor the names of its
17
-# contributors may be used to endorse or promote products derived from
18
-# this software without specific prior written permission.
19
-#
20
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-install:
33
- go install
34
-
35
-test: install generate-test-pbs
36
- go test
37
-
38
-
39
-generate-test-pbs:
40
- make install && cd testdata && make
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/all_test.go
deleted
-1948
@@ -1,1948 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto_test
33
-
34
-import (
35
- "bytes"
36
- "encoding/json"
37
- "errors"
38
- "fmt"
39
- "math"
40
- "math/rand"
41
- "reflect"
42
- "runtime/debug"
43
- "strings"
44
- "testing"
45
- "time"
46
-
47
- . "./testdata"
48
- . "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
49
-)
50
-
51
-var globalO *Buffer
52
-
53
-func old() *Buffer {
54
- if globalO == nil {
55
- globalO = NewBuffer(nil)
56
- }
57
- globalO.Reset()
58
- return globalO
59
-}
60
-
61
-func equalbytes(b1, b2 []byte, t *testing.T) {
62
- if len(b1) != len(b2) {
63
- t.Errorf("wrong lengths: 2*%d != %d", len(b1), len(b2))
64
- return
65
- }
66
- for i := 0; i < len(b1); i++ {
67
- if b1[i] != b2[i] {
68
- t.Errorf("bad byte[%d]:%x %x: %s %s", i, b1[i], b2[i], b1, b2)
69
- }
70
- }
71
-}
72
-
73
-func initGoTestField() *GoTestField {
74
- f := new(GoTestField)
75
- f.Label = String("label")
76
- f.Type = String("type")
77
- return f
78
-}
79
-
80
-// These are all structurally equivalent but the tag numbers differ.
81
-// (It's remarkable that required, optional, and repeated all have
82
-// 8 letters.)
83
-func initGoTest_RequiredGroup() *GoTest_RequiredGroup {
84
- return &GoTest_RequiredGroup{
85
- RequiredField: String("required"),
86
- }
87
-}
88
-
89
-func initGoTest_OptionalGroup() *GoTest_OptionalGroup {
90
- return &GoTest_OptionalGroup{
91
- RequiredField: String("optional"),
92
- }
93
-}
94
-
95
-func initGoTest_RepeatedGroup() *GoTest_RepeatedGroup {
96
- return &GoTest_RepeatedGroup{
97
- RequiredField: String("repeated"),
98
- }
99
-}
100
-
101
-func initGoTest(setdefaults bool) *GoTest {
102
- pb := new(GoTest)
103
- if setdefaults {
104
- pb.F_BoolDefaulted = Bool(Default_GoTest_F_BoolDefaulted)
105
- pb.F_Int32Defaulted = Int32(Default_GoTest_F_Int32Defaulted)
106
- pb.F_Int64Defaulted = Int64(Default_GoTest_F_Int64Defaulted)
107
- pb.F_Fixed32Defaulted = Uint32(Default_GoTest_F_Fixed32Defaulted)
108
- pb.F_Fixed64Defaulted = Uint64(Default_GoTest_F_Fixed64Defaulted)
109
- pb.F_Uint32Defaulted = Uint32(Default_GoTest_F_Uint32Defaulted)
110
- pb.F_Uint64Defaulted = Uint64(Default_GoTest_F_Uint64Defaulted)
111
- pb.F_FloatDefaulted = Float32(Default_GoTest_F_FloatDefaulted)
112
- pb.F_DoubleDefaulted = Float64(Default_GoTest_F_DoubleDefaulted)
113
- pb.F_StringDefaulted = String(Default_GoTest_F_StringDefaulted)
114
- pb.F_BytesDefaulted = Default_GoTest_F_BytesDefaulted
115
- pb.F_Sint32Defaulted = Int32(Default_GoTest_F_Sint32Defaulted)
116
- pb.F_Sint64Defaulted = Int64(Default_GoTest_F_Sint64Defaulted)
117
- }
118
-
119
- pb.Kind = GoTest_TIME.Enum()
120
- pb.RequiredField = initGoTestField()
121
- pb.F_BoolRequired = Bool(true)
122
- pb.F_Int32Required = Int32(3)
123
- pb.F_Int64Required = Int64(6)
124
- pb.F_Fixed32Required = Uint32(32)
125
- pb.F_Fixed64Required = Uint64(64)
126
- pb.F_Uint32Required = Uint32(3232)
127
- pb.F_Uint64Required = Uint64(6464)
128
- pb.F_FloatRequired = Float32(3232)
129
- pb.F_DoubleRequired = Float64(6464)
130
- pb.F_StringRequired = String("string")
131
- pb.F_BytesRequired = []byte("bytes")
132
- pb.F_Sint32Required = Int32(-32)
133
- pb.F_Sint64Required = Int64(-64)
134
- pb.Requiredgroup = initGoTest_RequiredGroup()
135
-
136
- return pb
137
-}
138
-
139
-func fail(msg string, b *bytes.Buffer, s string, t *testing.T) {
140
- data := b.Bytes()
141
- ld := len(data)
142
- ls := len(s) / 2
143
-
144
- fmt.Printf("fail %s ld=%d ls=%d\n", msg, ld, ls)
145
-
146
- // find the interesting spot - n
147
- n := ls
148
- if ld < ls {
149
- n = ld
150
- }
151
- j := 0
152
- for i := 0; i < n; i++ {
153
- bs := hex(s[j])*16 + hex(s[j+1])
154
- j += 2
155
- if data[i] == bs {
156
- continue
157
- }
158
- n = i
159
- break
160
- }
161
- l := n - 10
162
- if l < 0 {
163
- l = 0
164
- }
165
- h := n + 10
166
-
167
- // find the interesting spot - n
168
- fmt.Printf("is[%d]:", l)
169
- for i := l; i < h; i++ {
170
- if i >= ld {
171
- fmt.Printf(" --")
172
- continue
173
- }
174
- fmt.Printf(" %.2x", data[i])
175
- }
176
- fmt.Printf("\n")
177
-
178
- fmt.Printf("sb[%d]:", l)
179
- for i := l; i < h; i++ {
180
- if i >= ls {
181
- fmt.Printf(" --")
182
- continue
183
- }
184
- bs := hex(s[j])*16 + hex(s[j+1])
185
- j += 2
186
- fmt.Printf(" %.2x", bs)
187
- }
188
- fmt.Printf("\n")
189
-
190
- t.Fail()
191
-
192
- // t.Errorf("%s: \ngood: %s\nbad: %x", msg, s, b.Bytes())
193
- // Print the output in a partially-decoded format; can
194
- // be helpful when updating the test. It produces the output
195
- // that is pasted, with minor edits, into the argument to verify().
196
- // data := b.Bytes()
197
- // nesting := 0
198
- // for b.Len() > 0 {
199
- // start := len(data) - b.Len()
200
- // var u uint64
201
- // u, err := DecodeVarint(b)
202
- // if err != nil {
203
- // fmt.Printf("decode error on varint:", err)
204
- // return
205
- // }
206
- // wire := u & 0x7
207
- // tag := u >> 3
208
- // switch wire {
209
- // case WireVarint:
210
- // v, err := DecodeVarint(b)
211
- // if err != nil {
212
- // fmt.Printf("decode error on varint:", err)
213
- // return
214
- // }
215
- // fmt.Printf("\t\t\"%x\" // field %d, encoding %d, value %d\n",
216
- // data[start:len(data)-b.Len()], tag, wire, v)
217
- // case WireFixed32:
218
- // v, err := DecodeFixed32(b)
219
- // if err != nil {
220
- // fmt.Printf("decode error on fixed32:", err)
221
- // return
222
- // }
223
- // fmt.Printf("\t\t\"%x\" // field %d, encoding %d, value %d\n",
224
- // data[start:len(data)-b.Len()], tag, wire, v)
225
- // case WireFixed64:
226
- // v, err := DecodeFixed64(b)
227
- // if err != nil {
228
- // fmt.Printf("decode error on fixed64:", err)
229
- // return
230
- // }
231
- // fmt.Printf("\t\t\"%x\" // field %d, encoding %d, value %d\n",
232
- // data[start:len(data)-b.Len()], tag, wire, v)
233
- // case WireBytes:
234
- // nb, err := DecodeVarint(b)
235
- // if err != nil {
236
- // fmt.Printf("decode error on bytes:", err)
237
- // return
238
- // }
239
- // after_tag := len(data) - b.Len()
240
- // str := make([]byte, nb)
241
- // _, err = b.Read(str)
242
- // if err != nil {
243
- // fmt.Printf("decode error on bytes:", err)
244
- // return
245
- // }
246
- // fmt.Printf("\t\t\"%x\" \"%x\" // field %d, encoding %d (FIELD)\n",
247
- // data[start:after_tag], str, tag, wire)
248
- // case WireStartGroup:
249
- // nesting++
250
- // fmt.Printf("\t\t\"%x\"\t\t// start group field %d level %d\n",
251
- // data[start:len(data)-b.Len()], tag, nesting)
252
- // case WireEndGroup:
253
- // fmt.Printf("\t\t\"%x\"\t\t// end group field %d level %d\n",
254
- // data[start:len(data)-b.Len()], tag, nesting)
255
- // nesting--
256
- // default:
257
- // fmt.Printf("unrecognized wire type %d\n", wire)
258
- // return
259
- // }
260
- // }
261
-}
262
-
263
-func hex(c uint8) uint8 {
264
- if '0' <= c && c <= '9' {
265
- return c - '0'
266
- }
267
- if 'a' <= c && c <= 'f' {
268
- return 10 + c - 'a'
269
- }
270
- if 'A' <= c && c <= 'F' {
271
- return 10 + c - 'A'
272
- }
273
- return 0
274
-}
275
-
276
-func equal(b []byte, s string, t *testing.T) bool {
277
- if 2*len(b) != len(s) {
278
- // fail(fmt.Sprintf("wrong lengths: 2*%d != %d", len(b), len(s)), b, s, t)
279
- fmt.Printf("wrong lengths: 2*%d != %d\n", len(b), len(s))
280
- return false
281
- }
282
- for i, j := 0, 0; i < len(b); i, j = i+1, j+2 {
283
- x := hex(s[j])*16 + hex(s[j+1])
284
- if b[i] != x {
285
- // fail(fmt.Sprintf("bad byte[%d]:%x %x", i, b[i], x), b, s, t)
286
- fmt.Printf("bad byte[%d]:%x %x", i, b[i], x)
287
- return false
288
- }
289
- }
290
- return true
291
-}
292
-
293
-func overify(t *testing.T, pb *GoTest, expected string) {
294
- o := old()
295
- err := o.Marshal(pb)
296
- if err != nil {
297
- fmt.Printf("overify marshal-1 err = %v", err)
298
- o.DebugPrint("", o.Bytes())
299
- t.Fatalf("expected = %s", expected)
300
- }
301
- if !equal(o.Bytes(), expected, t) {
302
- o.DebugPrint("overify neq 1", o.Bytes())
303
- t.Fatalf("expected = %s", expected)
304
- }
305
-
306
- // Now test Unmarshal by recreating the original buffer.
307
- pbd := new(GoTest)
308
- err = o.Unmarshal(pbd)
309
- if err != nil {
310
- t.Fatalf("overify unmarshal err = %v", err)
311
- o.DebugPrint("", o.Bytes())
312
- t.Fatalf("string = %s", expected)
313
- }
314
- o.Reset()
315
- err = o.Marshal(pbd)
316
- if err != nil {
317
- t.Errorf("overify marshal-2 err = %v", err)
318
- o.DebugPrint("", o.Bytes())
319
- t.Fatalf("string = %s", expected)
320
- }
321
- if !equal(o.Bytes(), expected, t) {
322
- o.DebugPrint("overify neq 2", o.Bytes())
323
- t.Fatalf("string = %s", expected)
324
- }
325
-}
326
-
327
-// Simple tests for numeric encode/decode primitives (varint, etc.)
328
-func TestNumericPrimitives(t *testing.T) {
329
- for i := uint64(0); i < 1e6; i += 111 {
330
- o := old()
331
- if o.EncodeVarint(i) != nil {
332
- t.Error("EncodeVarint")
333
- break
334
- }
335
- x, e := o.DecodeVarint()
336
- if e != nil {
337
- t.Fatal("DecodeVarint")
338
- }
339
- if x != i {
340
- t.Fatal("varint decode fail:", i, x)
341
- }
342
-
343
- o = old()
344
- if o.EncodeFixed32(i) != nil {
345
- t.Fatal("encFixed32")
346
- }
347
- x, e = o.DecodeFixed32()
348
- if e != nil {
349
- t.Fatal("decFixed32")
350
- }
351
- if x != i {
352
- t.Fatal("fixed32 decode fail:", i, x)
353
- }
354
-
355
- o = old()
356
- if o.EncodeFixed64(i*1234567) != nil {
357
- t.Error("encFixed64")
358
- break
359
- }
360
- x, e = o.DecodeFixed64()
361
- if e != nil {
362
- t.Error("decFixed64")
363
- break
364
- }
365
- if x != i*1234567 {
366
- t.Error("fixed64 decode fail:", i*1234567, x)
367
- break
368
- }
369
-
370
- o = old()
371
- i32 := int32(i - 12345)
372
- if o.EncodeZigzag32(uint64(i32)) != nil {
373
- t.Fatal("EncodeZigzag32")
374
- }
375
- x, e = o.DecodeZigzag32()
376
- if e != nil {
377
- t.Fatal("DecodeZigzag32")
378
- }
379
- if x != uint64(uint32(i32)) {
380
- t.Fatal("zigzag32 decode fail:", i32, x)
381
- }
382
-
383
- o = old()
384
- i64 := int64(i - 12345)
385
- if o.EncodeZigzag64(uint64(i64)) != nil {
386
- t.Fatal("EncodeZigzag64")
387
- }
388
- x, e = o.DecodeZigzag64()
389
- if e != nil {
390
- t.Fatal("DecodeZigzag64")
391
- }
392
- if x != uint64(i64) {
393
- t.Fatal("zigzag64 decode fail:", i64, x)
394
- }
395
- }
396
-}
397
-
398
-// fakeMarshaler is a simple struct implementing Marshaler and Message interfaces.
399
-type fakeMarshaler struct {
400
- b []byte
401
- err error
402
-}
403
-
404
-func (f fakeMarshaler) Marshal() ([]byte, error) {
405
- return f.b, f.err
406
-}
407
-
408
-func (f fakeMarshaler) String() string {
409
- return fmt.Sprintf("Bytes: %v Error: %v", f.b, f.err)
410
-}
411
-
412
-func (f fakeMarshaler) ProtoMessage() {}
413
-
414
-func (f fakeMarshaler) Reset() {}
415
-
416
-// Simple tests for proto messages that implement the Marshaler interface.
417
-func TestMarshalerEncoding(t *testing.T) {
418
- tests := []struct {
419
- name string
420
- m Message
421
- want []byte
422
- wantErr error
423
- }{
424
- {
425
- name: "Marshaler that fails",
426
- m: fakeMarshaler{
427
- err: errors.New("some marshal err"),
428
- b: []byte{5, 6, 7},
429
- },
430
- // Since there's an error, nothing should be written to buffer.
431
- want: nil,
432
- wantErr: errors.New("some marshal err"),
433
- },
434
- {
435
- name: "Marshaler that succeeds",
436
- m: fakeMarshaler{
437
- b: []byte{0, 1, 2, 3, 4, 127, 255},
438
- },
439
- want: []byte{0, 1, 2, 3, 4, 127, 255},
440
- wantErr: nil,
441
- },
442
- }
443
- for _, test := range tests {
444
- b := NewBuffer(nil)
445
- err := b.Marshal(test.m)
446
- if !reflect.DeepEqual(test.wantErr, err) {
447
- t.Errorf("%s: got err %v wanted %v", test.name, err, test.wantErr)
448
- }
449
- if !reflect.DeepEqual(test.want, b.Bytes()) {
450
- t.Errorf("%s: got bytes %v wanted %v", test.name, b.Bytes(), test.want)
451
- }
452
- }
453
-}
454
-
455
-// Simple tests for bytes
456
-func TestBytesPrimitives(t *testing.T) {
457
- o := old()
458
- bytes := []byte{'n', 'o', 'w', ' ', 'i', 's', ' ', 't', 'h', 'e', ' ', 't', 'i', 'm', 'e'}
459
- if o.EncodeRawBytes(bytes) != nil {
460
- t.Error("EncodeRawBytes")
461
- }
462
- decb, e := o.DecodeRawBytes(false)
463
- if e != nil {
464
- t.Error("DecodeRawBytes")
465
- }
466
- equalbytes(bytes, decb, t)
467
-}
468
-
469
-// Simple tests for strings
470
-func TestStringPrimitives(t *testing.T) {
471
- o := old()
472
- s := "now is the time"
473
- if o.EncodeStringBytes(s) != nil {
474
- t.Error("enc_string")
475
- }
476
- decs, e := o.DecodeStringBytes()
477
- if e != nil {
478
- t.Error("dec_string")
479
- }
480
- if s != decs {
481
- t.Error("string encode/decode fail:", s, decs)
482
- }
483
-}
484
-
485
-// Do we catch the "required bit not set" case?
486
-func TestRequiredBit(t *testing.T) {
487
- o := old()
488
- pb := new(GoTest)
489
- err := o.Marshal(pb)
490
- if err == nil {
491
- t.Error("did not catch missing required fields")
492
- } else if strings.Index(err.Error(), "Kind") < 0 {
493
- t.Error("wrong error type:", err)
494
- }
495
-}
496
-
497
-// Check that all fields are nil.
498
-// Clearly silly, and a residue from a more interesting test with an earlier,
499
-// different initialization property, but it once caught a compiler bug so
500
-// it lives.
501
-func checkInitialized(pb *GoTest, t *testing.T) {
502
- if pb.F_BoolDefaulted != nil {
503
- t.Error("New or Reset did not set boolean:", *pb.F_BoolDefaulted)
504
- }
505
- if pb.F_Int32Defaulted != nil {
506
- t.Error("New or Reset did not set int32:", *pb.F_Int32Defaulted)
507
- }
508
- if pb.F_Int64Defaulted != nil {
509
- t.Error("New or Reset did not set int64:", *pb.F_Int64Defaulted)
510
- }
511
- if pb.F_Fixed32Defaulted != nil {
512
- t.Error("New or Reset did not set fixed32:", *pb.F_Fixed32Defaulted)
513
- }
514
- if pb.F_Fixed64Defaulted != nil {
515
- t.Error("New or Reset did not set fixed64:", *pb.F_Fixed64Defaulted)
516
- }
517
- if pb.F_Uint32Defaulted != nil {
518
- t.Error("New or Reset did not set uint32:", *pb.F_Uint32Defaulted)
519
- }
520
- if pb.F_Uint64Defaulted != nil {
521
- t.Error("New or Reset did not set uint64:", *pb.F_Uint64Defaulted)
522
- }
523
- if pb.F_FloatDefaulted != nil {
524
- t.Error("New or Reset did not set float:", *pb.F_FloatDefaulted)
525
- }
526
- if pb.F_DoubleDefaulted != nil {
527
- t.Error("New or Reset did not set double:", *pb.F_DoubleDefaulted)
528
- }
529
- if pb.F_StringDefaulted != nil {
530
- t.Error("New or Reset did not set string:", *pb.F_StringDefaulted)
531
- }
532
- if pb.F_BytesDefaulted != nil {
533
- t.Error("New or Reset did not set bytes:", string(pb.F_BytesDefaulted))
534
- }
535
- if pb.F_Sint32Defaulted != nil {
536
- t.Error("New or Reset did not set int32:", *pb.F_Sint32Defaulted)
537
- }
538
- if pb.F_Sint64Defaulted != nil {
539
- t.Error("New or Reset did not set int64:", *pb.F_Sint64Defaulted)
540
- }
541
-}
542
-
543
-// Does Reset() reset?
544
-func TestReset(t *testing.T) {
545
- pb := initGoTest(true)
546
- // muck with some values
547
- pb.F_BoolDefaulted = Bool(false)
548
- pb.F_Int32Defaulted = Int32(237)
549
- pb.F_Int64Defaulted = Int64(12346)
550
- pb.F_Fixed32Defaulted = Uint32(32000)
551
- pb.F_Fixed64Defaulted = Uint64(666)
552
- pb.F_Uint32Defaulted = Uint32(323232)
553
- pb.F_Uint64Defaulted = nil
554
- pb.F_FloatDefaulted = nil
555
- pb.F_DoubleDefaulted = Float64(0)
556
- pb.F_StringDefaulted = String("gotcha")
557
- pb.F_BytesDefaulted = []byte("asdfasdf")
558
- pb.F_Sint32Defaulted = Int32(123)
559
- pb.F_Sint64Defaulted = Int64(789)
560
- pb.Reset()
561
- checkInitialized(pb, t)
562
-}
563
-
564
-// All required fields set, no defaults provided.
565
-func TestEncodeDecode1(t *testing.T) {
566
- pb := initGoTest(false)
567
- overify(t, pb,
568
- "0807"+ // field 1, encoding 0, value 7
569
- "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
570
- "5001"+ // field 10, encoding 0, value 1
571
- "5803"+ // field 11, encoding 0, value 3
572
- "6006"+ // field 12, encoding 0, value 6
573
- "6d20000000"+ // field 13, encoding 5, value 0x20
574
- "714000000000000000"+ // field 14, encoding 1, value 0x40
575
- "78a019"+ // field 15, encoding 0, value 0xca0 = 3232
576
- "8001c032"+ // field 16, encoding 0, value 0x1940 = 6464
577
- "8d0100004a45"+ // field 17, encoding 5, value 3232.0
578
- "9101000000000040b940"+ // field 18, encoding 1, value 6464.0
579
- "9a0106"+"737472696e67"+ // field 19, encoding 2, string "string"
580
- "b304"+ // field 70, encoding 3, start group
581
- "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
582
- "b404"+ // field 70, encoding 4, end group
583
- "aa0605"+"6279746573"+ // field 101, encoding 2, string "bytes"
584
- "b0063f"+ // field 102, encoding 0, 0x3f zigzag32
585
- "b8067f") // field 103, encoding 0, 0x7f zigzag64
586
-}
587
-
588
-// All required fields set, defaults provided.
589
-func TestEncodeDecode2(t *testing.T) {
590
- pb := initGoTest(true)
591
- overify(t, pb,
592
- "0807"+ // field 1, encoding 0, value 7
593
- "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
594
- "5001"+ // field 10, encoding 0, value 1
595
- "5803"+ // field 11, encoding 0, value 3
596
- "6006"+ // field 12, encoding 0, value 6
597
- "6d20000000"+ // field 13, encoding 5, value 32
598
- "714000000000000000"+ // field 14, encoding 1, value 64
599
- "78a019"+ // field 15, encoding 0, value 3232
600
- "8001c032"+ // field 16, encoding 0, value 6464
601
- "8d0100004a45"+ // field 17, encoding 5, value 3232.0
602
- "9101000000000040b940"+ // field 18, encoding 1, value 6464.0
603
- "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
604
- "c00201"+ // field 40, encoding 0, value 1
605
- "c80220"+ // field 41, encoding 0, value 32
606
- "d00240"+ // field 42, encoding 0, value 64
607
- "dd0240010000"+ // field 43, encoding 5, value 320
608
- "e1028002000000000000"+ // field 44, encoding 1, value 640
609
- "e8028019"+ // field 45, encoding 0, value 3200
610
- "f0028032"+ // field 46, encoding 0, value 6400
611
- "fd02e0659948"+ // field 47, encoding 5, value 314159.0
612
- "81030000000050971041"+ // field 48, encoding 1, value 271828.0
613
- "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
614
- "b304"+ // start group field 70 level 1
615
- "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
616
- "b404"+ // end group field 70 level 1
617
- "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
618
- "b0063f"+ // field 102, encoding 0, 0x3f zigzag32
619
- "b8067f"+ // field 103, encoding 0, 0x7f zigzag64
620
- "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
621
- "90193f"+ // field 402, encoding 0, value 63
622
- "98197f") // field 403, encoding 0, value 127
623
-
624
-}
625
-
626
-// All default fields set to their default value by hand
627
-func TestEncodeDecode3(t *testing.T) {
628
- pb := initGoTest(false)
629
- pb.F_BoolDefaulted = Bool(true)
630
- pb.F_Int32Defaulted = Int32(32)
631
- pb.F_Int64Defaulted = Int64(64)
632
- pb.F_Fixed32Defaulted = Uint32(320)
633
- pb.F_Fixed64Defaulted = Uint64(640)
634
- pb.F_Uint32Defaulted = Uint32(3200)
635
- pb.F_Uint64Defaulted = Uint64(6400)
636
- pb.F_FloatDefaulted = Float32(314159)
637
- pb.F_DoubleDefaulted = Float64(271828)
638
- pb.F_StringDefaulted = String("hello, \"world!\"\n")
639
- pb.F_BytesDefaulted = []byte("Bignose")
640
- pb.F_Sint32Defaulted = Int32(-32)
641
- pb.F_Sint64Defaulted = Int64(-64)
642
-
643
- overify(t, pb,
644
- "0807"+ // field 1, encoding 0, value 7
645
- "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
646
- "5001"+ // field 10, encoding 0, value 1
647
- "5803"+ // field 11, encoding 0, value 3
648
- "6006"+ // field 12, encoding 0, value 6
649
- "6d20000000"+ // field 13, encoding 5, value 32
650
- "714000000000000000"+ // field 14, encoding 1, value 64
651
- "78a019"+ // field 15, encoding 0, value 3232
652
- "8001c032"+ // field 16, encoding 0, value 6464
653
- "8d0100004a45"+ // field 17, encoding 5, value 3232.0
654
- "9101000000000040b940"+ // field 18, encoding 1, value 6464.0
655
- "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
656
- "c00201"+ // field 40, encoding 0, value 1
657
- "c80220"+ // field 41, encoding 0, value 32
658
- "d00240"+ // field 42, encoding 0, value 64
659
- "dd0240010000"+ // field 43, encoding 5, value 320
660
- "e1028002000000000000"+ // field 44, encoding 1, value 640
661
- "e8028019"+ // field 45, encoding 0, value 3200
662
- "f0028032"+ // field 46, encoding 0, value 6400
663
- "fd02e0659948"+ // field 47, encoding 5, value 314159.0
664
- "81030000000050971041"+ // field 48, encoding 1, value 271828.0
665
- "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
666
- "b304"+ // start group field 70 level 1
667
- "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
668
- "b404"+ // end group field 70 level 1
669
- "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
670
- "b0063f"+ // field 102, encoding 0, 0x3f zigzag32
671
- "b8067f"+ // field 103, encoding 0, 0x7f zigzag64
672
- "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
673
- "90193f"+ // field 402, encoding 0, value 63
674
- "98197f") // field 403, encoding 0, value 127
675
-
676
-}
677
-
678
-// All required fields set, defaults provided, all non-defaulted optional fields have values.
679
-func TestEncodeDecode4(t *testing.T) {
680
- pb := initGoTest(true)
681
- pb.Table = String("hello")
682
- pb.Param = Int32(7)
683
- pb.OptionalField = initGoTestField()
684
- pb.F_BoolOptional = Bool(true)
685
- pb.F_Int32Optional = Int32(32)
686
- pb.F_Int64Optional = Int64(64)
687
- pb.F_Fixed32Optional = Uint32(3232)
688
- pb.F_Fixed64Optional = Uint64(6464)
689
- pb.F_Uint32Optional = Uint32(323232)
690
- pb.F_Uint64Optional = Uint64(646464)
691
- pb.F_FloatOptional = Float32(32.)
692
- pb.F_DoubleOptional = Float64(64.)
693
- pb.F_StringOptional = String("hello")
694
- pb.F_BytesOptional = []byte("Bignose")
695
- pb.F_Sint32Optional = Int32(-32)
696
- pb.F_Sint64Optional = Int64(-64)
697
- pb.Optionalgroup = initGoTest_OptionalGroup()
698
-
699
- overify(t, pb,
700
- "0807"+ // field 1, encoding 0, value 7
701
- "1205"+"68656c6c6f"+ // field 2, encoding 2, string "hello"
702
- "1807"+ // field 3, encoding 0, value 7
703
- "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
704
- "320d"+"0a056c6162656c120474797065"+ // field 6, encoding 2 (GoTestField)
705
- "5001"+ // field 10, encoding 0, value 1
706
- "5803"+ // field 11, encoding 0, value 3
707
- "6006"+ // field 12, encoding 0, value 6
708
- "6d20000000"+ // field 13, encoding 5, value 32
709
- "714000000000000000"+ // field 14, encoding 1, value 64
710
- "78a019"+ // field 15, encoding 0, value 3232
711
- "8001c032"+ // field 16, encoding 0, value 6464
712
- "8d0100004a45"+ // field 17, encoding 5, value 3232.0
713
- "9101000000000040b940"+ // field 18, encoding 1, value 6464.0
714
- "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
715
- "f00101"+ // field 30, encoding 0, value 1
716
- "f80120"+ // field 31, encoding 0, value 32
717
- "800240"+ // field 32, encoding 0, value 64
718
- "8d02a00c0000"+ // field 33, encoding 5, value 3232
719
- "91024019000000000000"+ // field 34, encoding 1, value 6464
720
- "9802a0dd13"+ // field 35, encoding 0, value 323232
721
- "a002c0ba27"+ // field 36, encoding 0, value 646464
722
- "ad0200000042"+ // field 37, encoding 5, value 32.0
723
- "b1020000000000005040"+ // field 38, encoding 1, value 64.0
724
- "ba0205"+"68656c6c6f"+ // field 39, encoding 2, string "hello"
725
- "c00201"+ // field 40, encoding 0, value 1
726
- "c80220"+ // field 41, encoding 0, value 32
727
- "d00240"+ // field 42, encoding 0, value 64
728
- "dd0240010000"+ // field 43, encoding 5, value 320
729
- "e1028002000000000000"+ // field 44, encoding 1, value 640
730
- "e8028019"+ // field 45, encoding 0, value 3200
731
- "f0028032"+ // field 46, encoding 0, value 6400
732
- "fd02e0659948"+ // field 47, encoding 5, value 314159.0
733
- "81030000000050971041"+ // field 48, encoding 1, value 271828.0
734
- "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
735
- "b304"+ // start group field 70 level 1
736
- "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
737
- "b404"+ // end group field 70 level 1
738
- "d305"+ // start group field 90 level 1
739
- "da0508"+"6f7074696f6e616c"+ // field 91, encoding 2, string "optional"
740
- "d405"+ // end group field 90 level 1
741
- "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
742
- "b0063f"+ // field 102, encoding 0, 0x3f zigzag32
743
- "b8067f"+ // field 103, encoding 0, 0x7f zigzag64
744
- "ea1207"+"4269676e6f7365"+ // field 301, encoding 2, string "Bignose"
745
- "f0123f"+ // field 302, encoding 0, value 63
746
- "f8127f"+ // field 303, encoding 0, value 127
747
- "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
748
- "90193f"+ // field 402, encoding 0, value 63
749
- "98197f") // field 403, encoding 0, value 127
750
-
751
-}
752
-
753
-// All required fields set, defaults provided, all repeated fields given two values.
754
-func TestEncodeDecode5(t *testing.T) {
755
- pb := initGoTest(true)
756
- pb.RepeatedField = []*GoTestField{initGoTestField(), initGoTestField()}
757
- pb.F_BoolRepeated = []bool{false, true}
758
- pb.F_Int32Repeated = []int32{32, 33}
759
- pb.F_Int64Repeated = []int64{64, 65}
760
- pb.F_Fixed32Repeated = []uint32{3232, 3333}
761
- pb.F_Fixed64Repeated = []uint64{6464, 6565}
762
- pb.F_Uint32Repeated = []uint32{323232, 333333}
763
- pb.F_Uint64Repeated = []uint64{646464, 656565}
764
- pb.F_FloatRepeated = []float32{32., 33.}
765
- pb.F_DoubleRepeated = []float64{64., 65.}
766
- pb.F_StringRepeated = []string{"hello", "sailor"}
767
- pb.F_BytesRepeated = [][]byte{[]byte("big"), []byte("nose")}
768
- pb.F_Sint32Repeated = []int32{32, -32}
769
- pb.F_Sint64Repeated = []int64{64, -64}
770
- pb.Repeatedgroup = []*GoTest_RepeatedGroup{initGoTest_RepeatedGroup(), initGoTest_RepeatedGroup()}
771
-
772
- overify(t, pb,
773
- "0807"+ // field 1, encoding 0, value 7
774
- "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
775
- "2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField)
776
- "2a0d"+"0a056c6162656c120474797065"+ // field 5, encoding 2 (GoTestField)
777
- "5001"+ // field 10, encoding 0, value 1
778
- "5803"+ // field 11, encoding 0, value 3
779
- "6006"+ // field 12, encoding 0, value 6
780
- "6d20000000"+ // field 13, encoding 5, value 32
781
- "714000000000000000"+ // field 14, encoding 1, value 64
782
- "78a019"+ // field 15, encoding 0, value 3232
783
- "8001c032"+ // field 16, encoding 0, value 6464
784
- "8d0100004a45"+ // field 17, encoding 5, value 3232.0
785
- "9101000000000040b940"+ // field 18, encoding 1, value 6464.0
786
- "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
787
- "a00100"+ // field 20, encoding 0, value 0
788
- "a00101"+ // field 20, encoding 0, value 1
789
- "a80120"+ // field 21, encoding 0, value 32
790
- "a80121"+ // field 21, encoding 0, value 33
791
- "b00140"+ // field 22, encoding 0, value 64
792
- "b00141"+ // field 22, encoding 0, value 65
793
- "bd01a00c0000"+ // field 23, encoding 5, value 3232
794
- "bd01050d0000"+ // field 23, encoding 5, value 3333
795
- "c1014019000000000000"+ // field 24, encoding 1, value 6464
796
- "c101a519000000000000"+ // field 24, encoding 1, value 6565
797
- "c801a0dd13"+ // field 25, encoding 0, value 323232
798
- "c80195ac14"+ // field 25, encoding 0, value 333333
799
- "d001c0ba27"+ // field 26, encoding 0, value 646464
800
- "d001b58928"+ // field 26, encoding 0, value 656565
801
- "dd0100000042"+ // field 27, encoding 5, value 32.0
802
- "dd0100000442"+ // field 27, encoding 5, value 33.0
803
- "e1010000000000005040"+ // field 28, encoding 1, value 64.0
804
- "e1010000000000405040"+ // field 28, encoding 1, value 65.0
805
- "ea0105"+"68656c6c6f"+ // field 29, encoding 2, string "hello"
806
- "ea0106"+"7361696c6f72"+ // field 29, encoding 2, string "sailor"
807
- "c00201"+ // field 40, encoding 0, value 1
808
- "c80220"+ // field 41, encoding 0, value 32
809
- "d00240"+ // field 42, encoding 0, value 64
810
- "dd0240010000"+ // field 43, encoding 5, value 320
811
- "e1028002000000000000"+ // field 44, encoding 1, value 640
812
- "e8028019"+ // field 45, encoding 0, value 3200
813
- "f0028032"+ // field 46, encoding 0, value 6400
814
- "fd02e0659948"+ // field 47, encoding 5, value 314159.0
815
- "81030000000050971041"+ // field 48, encoding 1, value 271828.0
816
- "8a0310"+"68656c6c6f2c2022776f726c6421220a"+ // field 49, encoding 2 string "hello, \"world!\"\n"
817
- "b304"+ // start group field 70 level 1
818
- "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
819
- "b404"+ // end group field 70 level 1
820
- "8305"+ // start group field 80 level 1
821
- "8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated"
822
- "8405"+ // end group field 80 level 1
823
- "8305"+ // start group field 80 level 1
824
- "8a0508"+"7265706561746564"+ // field 81, encoding 2, string "repeated"
825
- "8405"+ // end group field 80 level 1
826
- "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
827
- "b0063f"+ // field 102, encoding 0, 0x3f zigzag32
828
- "b8067f"+ // field 103, encoding 0, 0x7f zigzag64
829
- "ca0c03"+"626967"+ // field 201, encoding 2, string "big"
830
- "ca0c04"+"6e6f7365"+ // field 201, encoding 2, string "nose"
831
- "d00c40"+ // field 202, encoding 0, value 32
832
- "d00c3f"+ // field 202, encoding 0, value -32
833
- "d80c8001"+ // field 203, encoding 0, value 64
834
- "d80c7f"+ // field 203, encoding 0, value -64
835
- "8a1907"+"4269676e6f7365"+ // field 401, encoding 2, string "Bignose"
836
- "90193f"+ // field 402, encoding 0, value 63
837
- "98197f") // field 403, encoding 0, value 127
838
-
839
-}
840
-
841
-// All required fields set, all packed repeated fields given two values.
842
-func TestEncodeDecode6(t *testing.T) {
843
- pb := initGoTest(false)
844
- pb.F_BoolRepeatedPacked = []bool{false, true}
845
- pb.F_Int32RepeatedPacked = []int32{32, 33}
846
- pb.F_Int64RepeatedPacked = []int64{64, 65}
847
- pb.F_Fixed32RepeatedPacked = []uint32{3232, 3333}
848
- pb.F_Fixed64RepeatedPacked = []uint64{6464, 6565}
849
- pb.F_Uint32RepeatedPacked = []uint32{323232, 333333}
850
- pb.F_Uint64RepeatedPacked = []uint64{646464, 656565}
851
- pb.F_FloatRepeatedPacked = []float32{32., 33.}
852
- pb.F_DoubleRepeatedPacked = []float64{64., 65.}
853
- pb.F_Sint32RepeatedPacked = []int32{32, -32}
854
- pb.F_Sint64RepeatedPacked = []int64{64, -64}
855
-
856
- overify(t, pb,
857
- "0807"+ // field 1, encoding 0, value 7
858
- "220d"+"0a056c6162656c120474797065"+ // field 4, encoding 2 (GoTestField)
859
- "5001"+ // field 10, encoding 0, value 1
860
- "5803"+ // field 11, encoding 0, value 3
861
- "6006"+ // field 12, encoding 0, value 6
862
- "6d20000000"+ // field 13, encoding 5, value 32
863
- "714000000000000000"+ // field 14, encoding 1, value 64
864
- "78a019"+ // field 15, encoding 0, value 3232
865
- "8001c032"+ // field 16, encoding 0, value 6464
866
- "8d0100004a45"+ // field 17, encoding 5, value 3232.0
867
- "9101000000000040b940"+ // field 18, encoding 1, value 6464.0
868
- "9a0106"+"737472696e67"+ // field 19, encoding 2 string "string"
869
- "9203020001"+ // field 50, encoding 2, 2 bytes, value 0, value 1
870
- "9a03022021"+ // field 51, encoding 2, 2 bytes, value 32, value 33
871
- "a203024041"+ // field 52, encoding 2, 2 bytes, value 64, value 65
872
- "aa0308"+ // field 53, encoding 2, 8 bytes
873
- "a00c0000050d0000"+ // value 3232, value 3333
874
- "b20310"+ // field 54, encoding 2, 16 bytes
875
- "4019000000000000a519000000000000"+ // value 6464, value 6565
876
- "ba0306"+ // field 55, encoding 2, 6 bytes
877
- "a0dd1395ac14"+ // value 323232, value 333333
878
- "c20306"+ // field 56, encoding 2, 6 bytes
879
- "c0ba27b58928"+ // value 646464, value 656565
880
- "ca0308"+ // field 57, encoding 2, 8 bytes
881
- "0000004200000442"+ // value 32.0, value 33.0
882
- "d20310"+ // field 58, encoding 2, 16 bytes
883
- "00000000000050400000000000405040"+ // value 64.0, value 65.0
884
- "b304"+ // start group field 70 level 1
885
- "ba0408"+"7265717569726564"+ // field 71, encoding 2, string "required"
886
- "b404"+ // end group field 70 level 1
887
- "aa0605"+"6279746573"+ // field 101, encoding 2 string "bytes"
888
- "b0063f"+ // field 102, encoding 0, 0x3f zigzag32
889
- "b8067f"+ // field 103, encoding 0, 0x7f zigzag64
890
- "b21f02"+ // field 502, encoding 2, 2 bytes
891
- "403f"+ // value 32, value -32
892
- "ba1f03"+ // field 503, encoding 2, 3 bytes
893
- "80017f") // value 64, value -64
894
-}
895
-
896
-// Test that we can encode empty bytes fields.
897
-func TestEncodeDecodeBytes1(t *testing.T) {
898
- pb := initGoTest(false)
899
-
900
- // Create our bytes
901
- pb.F_BytesRequired = []byte{}
902
- pb.F_BytesRepeated = [][]byte{{}}
903
- pb.F_BytesOptional = []byte{}
904
-
905
- d, err := Marshal(pb)
906
- if err != nil {
907
- t.Error(err)
908
- }
909
-
910
- pbd := new(GoTest)
911
- if err := Unmarshal(d, pbd); err != nil {
912
- t.Error(err)
913
- }
914
-
915
- if pbd.F_BytesRequired == nil || len(pbd.F_BytesRequired) != 0 {
916
- t.Error("required empty bytes field is incorrect")
917
- }
918
- if pbd.F_BytesRepeated == nil || len(pbd.F_BytesRepeated) == 1 && pbd.F_BytesRepeated[0] == nil {
919
- t.Error("repeated empty bytes field is incorrect")
920
- }
921
- if pbd.F_BytesOptional == nil || len(pbd.F_BytesOptional) != 0 {
922
- t.Error("optional empty bytes field is incorrect")
923
- }
924
-}
925
-
926
-// Test that we encode nil-valued fields of a repeated bytes field correctly.
927
-// Since entries in a repeated field cannot be nil, nil must mean empty value.
928
-func TestEncodeDecodeBytes2(t *testing.T) {
929
- pb := initGoTest(false)
930
-
931
- // Create our bytes
932
- pb.F_BytesRepeated = [][]byte{nil}
933
-
934
- d, err := Marshal(pb)
935
- if err != nil {
936
- t.Error(err)
937
- }
938
-
939
- pbd := new(GoTest)
940
- if err := Unmarshal(d, pbd); err != nil {
941
- t.Error(err)
942
- }
943
-
944
- if len(pbd.F_BytesRepeated) != 1 || pbd.F_BytesRepeated[0] == nil {
945
- t.Error("Unexpected value for repeated bytes field")
946
- }
947
-}
948
-
949
-// All required fields set, defaults provided, all repeated fields given two values.
950
-func TestSkippingUnrecognizedFields(t *testing.T) {
951
- o := old()
952
- pb := initGoTestField()
953
-
954
- // Marshal it normally.
955
- o.Marshal(pb)
956
-
957
- // Now new a GoSkipTest record.
958
- skip := &GoSkipTest{
959
- SkipInt32: Int32(32),
960
- SkipFixed32: Uint32(3232),
961
- SkipFixed64: Uint64(6464),
962
- SkipString: String("skipper"),
963
- Skipgroup: &GoSkipTest_SkipGroup{
964
- GroupInt32: Int32(75),
965
- GroupString: String("wxyz"),
966
- },
967
- }
968
-
969
- // Marshal it into same buffer.
970
- o.Marshal(skip)
971
-
972
- pbd := new(GoTestField)
973
- o.Unmarshal(pbd)
974
-
975
- // The __unrecognized field should be a marshaling of GoSkipTest
976
- skipd := new(GoSkipTest)
977
-
978
- o.SetBuf(pbd.XXX_unrecognized)
979
- o.Unmarshal(skipd)
980
-
981
- if *skipd.SkipInt32 != *skip.SkipInt32 {
982
- t.Error("skip int32", skipd.SkipInt32)
983
- }
984
- if *skipd.SkipFixed32 != *skip.SkipFixed32 {
985
- t.Error("skip fixed32", skipd.SkipFixed32)
986
- }
987
- if *skipd.SkipFixed64 != *skip.SkipFixed64 {
988
- t.Error("skip fixed64", skipd.SkipFixed64)
989
- }
990
- if *skipd.SkipString != *skip.SkipString {
991
- t.Error("skip string", *skipd.SkipString)
992
- }
993
- if *skipd.Skipgroup.GroupInt32 != *skip.Skipgroup.GroupInt32 {
994
- t.Error("skip group int32", skipd.Skipgroup.GroupInt32)
995
- }
996
- if *skipd.Skipgroup.GroupString != *skip.Skipgroup.GroupString {
997
- t.Error("skip group string", *skipd.Skipgroup.GroupString)
998
- }
999
-}
1000
-
1001
-// Check that unrecognized fields of a submessage are preserved.
1002
-func TestSubmessageUnrecognizedFields(t *testing.T) {
1003
- nm := &NewMessage{
1004
- Nested: &NewMessage_Nested{
1005
- Name: String("Nigel"),
1006
- FoodGroup: String("carbs"),
1007
- },
1008
- }
1009
- b, err := Marshal(nm)
1010
- if err != nil {
1011
- t.Fatalf("Marshal of NewMessage: %v", err)
1012
- }
1013
-
1014
- // Unmarshal into an OldMessage.
1015
- om := new(OldMessage)
1016
- if err := Unmarshal(b, om); err != nil {
1017
- t.Fatalf("Unmarshal to OldMessage: %v", err)
1018
- }
1019
- exp := &OldMessage{
1020
- Nested: &OldMessage_Nested{
1021
- Name: String("Nigel"),
1022
- // normal protocol buffer users should not do this
1023
- XXX_unrecognized: []byte("\x12\x05carbs"),
1024
- },
1025
- }
1026
- if !Equal(om, exp) {
1027
- t.Errorf("om = %v, want %v", om, exp)
1028
- }
1029
-
1030
- // Clone the OldMessage.
1031
- om = Clone(om).(*OldMessage)
1032
- if !Equal(om, exp) {
1033
- t.Errorf("Clone(om) = %v, want %v", om, exp)
1034
- }
1035
-
1036
- // Marshal the OldMessage, then unmarshal it into an empty NewMessage.
1037
- if b, err = Marshal(om); err != nil {
1038
- t.Fatalf("Marshal of OldMessage: %v", err)
1039
- }
1040
- t.Logf("Marshal(%v) -> %q", om, b)
1041
- nm2 := new(NewMessage)
1042
- if err := Unmarshal(b, nm2); err != nil {
1043
- t.Fatalf("Unmarshal to NewMessage: %v", err)
1044
- }
1045
- if !Equal(nm, nm2) {
1046
- t.Errorf("NewMessage round-trip: %v => %v", nm, nm2)
1047
- }
1048
-}
1049
-
1050
-// Check that we can grow an array (repeated field) to have many elements.
1051
-// This test doesn't depend only on our encoding; for variety, it makes sure
1052
-// we create, encode, and decode the correct contents explicitly. It's therefore
1053
-// a bit messier.
1054
-// This test also uses (and hence tests) the Marshal/Unmarshal functions
1055
-// instead of the methods.
1056
-func TestBigRepeated(t *testing.T) {
1057
- pb := initGoTest(true)
1058
-
1059
- // Create the arrays
1060
- const N = 50 // Internally the library starts much smaller.
1061
- pb.Repeatedgroup = make([]*GoTest_RepeatedGroup, N)
1062
- pb.F_Sint64Repeated = make([]int64, N)
1063
- pb.F_Sint32Repeated = make([]int32, N)
1064
- pb.F_BytesRepeated = make([][]byte, N)
1065
- pb.F_StringRepeated = make([]string, N)
1066
- pb.F_DoubleRepeated = make([]float64, N)
1067
- pb.F_FloatRepeated = make([]float32, N)
1068
- pb.F_Uint64Repeated = make([]uint64, N)
1069
- pb.F_Uint32Repeated = make([]uint32, N)
1070
- pb.F_Fixed64Repeated = make([]uint64, N)
1071
- pb.F_Fixed32Repeated = make([]uint32, N)
1072
- pb.F_Int64Repeated = make([]int64, N)
1073
- pb.F_Int32Repeated = make([]int32, N)
1074
- pb.F_BoolRepeated = make([]bool, N)
1075
- pb.RepeatedField = make([]*GoTestField, N)
1076
-
1077
- // Fill in the arrays with checkable values.
1078
- igtf := initGoTestField()
1079
- igtrg := initGoTest_RepeatedGroup()
1080
- for i := 0; i < N; i++ {
1081
- pb.Repeatedgroup[i] = igtrg
1082
- pb.F_Sint64Repeated[i] = int64(i)
1083
- pb.F_Sint32Repeated[i] = int32(i)
1084
- s := fmt.Sprint(i)
1085
- pb.F_BytesRepeated[i] = []byte(s)
1086
- pb.F_StringRepeated[i] = s
1087
- pb.F_DoubleRepeated[i] = float64(i)
1088
- pb.F_FloatRepeated[i] = float32(i)
1089
- pb.F_Uint64Repeated[i] = uint64(i)
1090
- pb.F_Uint32Repeated[i] = uint32(i)
1091
- pb.F_Fixed64Repeated[i] = uint64(i)
1092
- pb.F_Fixed32Repeated[i] = uint32(i)
1093
- pb.F_Int64Repeated[i] = int64(i)
1094
- pb.F_Int32Repeated[i] = int32(i)
1095
- pb.F_BoolRepeated[i] = i%2 == 0
1096
- pb.RepeatedField[i] = igtf
1097
- }
1098
-
1099
- // Marshal.
1100
- buf, _ := Marshal(pb)
1101
-
1102
- // Now test Unmarshal by recreating the original buffer.
1103
- pbd := new(GoTest)
1104
- Unmarshal(buf, pbd)
1105
-
1106
- // Check the checkable values
1107
- for i := uint64(0); i < N; i++ {
1108
- if pbd.Repeatedgroup[i] == nil { // TODO: more checking?
1109
- t.Error("pbd.Repeatedgroup bad")
1110
- }
1111
- var x uint64
1112
- x = uint64(pbd.F_Sint64Repeated[i])
1113
- if x != i {
1114
- t.Error("pbd.F_Sint64Repeated bad", x, i)
1115
- }
1116
- x = uint64(pbd.F_Sint32Repeated[i])
1117
- if x != i {
1118
- t.Error("pbd.F_Sint32Repeated bad", x, i)
1119
- }
1120
- s := fmt.Sprint(i)
1121
- equalbytes(pbd.F_BytesRepeated[i], []byte(s), t)
1122
- if pbd.F_StringRepeated[i] != s {
1123
- t.Error("pbd.F_Sint32Repeated bad", pbd.F_StringRepeated[i], i)
1124
- }
1125
- x = uint64(pbd.F_DoubleRepeated[i])
1126
- if x != i {
1127
- t.Error("pbd.F_DoubleRepeated bad", x, i)
1128
- }
1129
- x = uint64(pbd.F_FloatRepeated[i])
1130
- if x != i {
1131
- t.Error("pbd.F_FloatRepeated bad", x, i)
1132
- }
1133
- x = pbd.F_Uint64Repeated[i]
1134
- if x != i {
1135
- t.Error("pbd.F_Uint64Repeated bad", x, i)
1136
- }
1137
- x = uint64(pbd.F_Uint32Repeated[i])
1138
- if x != i {
1139
- t.Error("pbd.F_Uint32Repeated bad", x, i)
1140
- }
1141
- x = pbd.F_Fixed64Repeated[i]
1142
- if x != i {
1143
- t.Error("pbd.F_Fixed64Repeated bad", x, i)
1144
- }
1145
- x = uint64(pbd.F_Fixed32Repeated[i])
1146
- if x != i {
1147
- t.Error("pbd.F_Fixed32Repeated bad", x, i)
1148
- }
1149
- x = uint64(pbd.F_Int64Repeated[i])
1150
- if x != i {
1151
- t.Error("pbd.F_Int64Repeated bad", x, i)
1152
- }
1153
- x = uint64(pbd.F_Int32Repeated[i])
1154
- if x != i {
1155
- t.Error("pbd.F_Int32Repeated bad", x, i)
1156
- }
1157
- if pbd.F_BoolRepeated[i] != (i%2 == 0) {
1158
- t.Error("pbd.F_BoolRepeated bad", x, i)
1159
- }
1160
- if pbd.RepeatedField[i] == nil { // TODO: more checking?
1161
- t.Error("pbd.RepeatedField bad")
1162
- }
1163
- }
1164
-}
1165
-
1166
-// Verify we give a useful message when decoding to the wrong structure type.
1167
-func TestTypeMismatch(t *testing.T) {
1168
- pb1 := initGoTest(true)
1169
-
1170
- // Marshal
1171
- o := old()
1172
- o.Marshal(pb1)
1173
-
1174
- // Now Unmarshal it to the wrong type.
1175
- pb2 := initGoTestField()
1176
- err := o.Unmarshal(pb2)
1177
- if err == nil {
1178
- t.Error("expected error, got no error")
1179
- } else if !strings.Contains(err.Error(), "bad wiretype") {
1180
- t.Error("expected bad wiretype error, got", err)
1181
- }
1182
-}
1183
-
1184
-func encodeDecode(t *testing.T, in, out Message, msg string) {
1185
- buf, err := Marshal(in)
1186
- if err != nil {
1187
- t.Fatalf("failed marshaling %v: %v", msg, err)
1188
- }
1189
- if err := Unmarshal(buf, out); err != nil {
1190
- t.Fatalf("failed unmarshaling %v: %v", msg, err)
1191
- }
1192
-}
1193
-
1194
-func TestPackedNonPackedDecoderSwitching(t *testing.T) {
1195
- np, p := new(NonPackedTest), new(PackedTest)
1196
-
1197
- // non-packed -> packed
1198
- np.A = []int32{0, 1, 1, 2, 3, 5}
1199
- encodeDecode(t, np, p, "non-packed -> packed")
1200
- if !reflect.DeepEqual(np.A, p.B) {
1201
- t.Errorf("failed non-packed -> packed; np.A=%+v, p.B=%+v", np.A, p.B)
1202
- }
1203
-
1204
- // packed -> non-packed
1205
- np.Reset()
1206
- p.B = []int32{3, 1, 4, 1, 5, 9}
1207
- encodeDecode(t, p, np, "packed -> non-packed")
1208
- if !reflect.DeepEqual(p.B, np.A) {
1209
- t.Errorf("failed packed -> non-packed; p.B=%+v, np.A=%+v", p.B, np.A)
1210
- }
1211
-}
1212
-
1213
-func TestProto1RepeatedGroup(t *testing.T) {
1214
- pb := &MessageList{
1215
- Message: []*MessageList_Message{
1216
- {
1217
- Name: String("blah"),
1218
- Count: Int32(7),
1219
- },
1220
- // NOTE: pb.Message[1] is a nil
1221
- nil,
1222
- },
1223
- }
1224
-
1225
- o := old()
1226
- if err := o.Marshal(pb); err != ErrRepeatedHasNil {
1227
- t.Fatalf("unexpected or no error when marshaling: %v", err)
1228
- }
1229
-}
1230
-
1231
-// Test that enums work. Checks for a bug introduced by making enums
1232
-// named types instead of int32: newInt32FromUint64 would crash with
1233
-// a type mismatch in reflect.PointTo.
1234
-func TestEnum(t *testing.T) {
1235
- pb := new(GoEnum)
1236
- pb.Foo = FOO_FOO1.Enum()
1237
- o := old()
1238
- if err := o.Marshal(pb); err != nil {
1239
- t.Fatal("error encoding enum:", err)
1240
- }
1241
- pb1 := new(GoEnum)
1242
- if err := o.Unmarshal(pb1); err != nil {
1243
- t.Fatal("error decoding enum:", err)
1244
- }
1245
- if *pb1.Foo != FOO_FOO1 {
1246
- t.Error("expected 7 but got ", *pb1.Foo)
1247
- }
1248
-}
1249
-
1250
-// Enum types have String methods. Check that enum fields can be printed.
1251
-// We don't care what the value actually is, just as long as it doesn't crash.
1252
-func TestPrintingNilEnumFields(t *testing.T) {
1253
- pb := new(GoEnum)
1254
- fmt.Sprintf("%+v", pb)
1255
-}
1256
-
1257
-// Verify that absent required fields cause Marshal/Unmarshal to return errors.
1258
-func TestRequiredFieldEnforcement(t *testing.T) {
1259
- pb := new(GoTestField)
1260
- _, err := Marshal(pb)
1261
- if err == nil {
1262
- t.Error("marshal: expected error, got nil")
1263
- } else if strings.Index(err.Error(), "Label") < 0 {
1264
- t.Errorf("marshal: bad error type: %v", err)
1265
- }
1266
-
1267
- // A slightly sneaky, yet valid, proto. It encodes the same required field twice,
1268
- // so simply counting the required fields is insufficient.
1269
- // field 1, encoding 2, value "hi"
1270
- buf := []byte("\x0A\x02hi\x0A\x02hi")
1271
- err = Unmarshal(buf, pb)
1272
- if err == nil {
1273
- t.Error("unmarshal: expected error, got nil")
1274
- } else if strings.Index(err.Error(), "{Unknown}") < 0 {
1275
- t.Errorf("unmarshal: bad error type: %v", err)
1276
- }
1277
-}
1278
-
1279
-func TestTypedNilMarshal(t *testing.T) {
1280
- // A typed nil should return ErrNil and not crash.
1281
- _, err := Marshal((*GoEnum)(nil))
1282
- if err != ErrNil {
1283
- t.Errorf("Marshal: got err %v, want ErrNil", err)
1284
- }
1285
-}
1286
-
1287
-// A type that implements the Marshaler interface, but is not nillable.
1288
-type nonNillableInt uint64
1289
-
1290
-func (nni nonNillableInt) Marshal() ([]byte, error) {
1291
- return EncodeVarint(uint64(nni)), nil
1292
-}
1293
-
1294
-type NNIMessage struct {
1295
- nni nonNillableInt
1296
-}
1297
-
1298
-func (*NNIMessage) Reset() {}
1299
-func (*NNIMessage) String() string { return "" }
1300
-func (*NNIMessage) ProtoMessage() {}
1301
-
1302
-// A type that implements the Marshaler interface and is nillable.
1303
-type nillableMessage struct {
1304
- x uint64
1305
-}
1306
-
1307
-func (nm *nillableMessage) Marshal() ([]byte, error) {
1308
- return EncodeVarint(nm.x), nil
1309
-}
1310
-
1311
-type NMMessage struct {
1312
- nm *nillableMessage
1313
-}
1314
-
1315
-func (*NMMessage) Reset() {}
1316
-func (*NMMessage) String() string { return "" }
1317
-func (*NMMessage) ProtoMessage() {}
1318
-
1319
-// Verify a type that uses the Marshaler interface, but has a nil pointer.
1320
-func TestNilMarshaler(t *testing.T) {
1321
- // Try a struct with a Marshaler field that is nil.
1322
- // It should be directly marshable.
1323
- nmm := new(NMMessage)
1324
- if _, err := Marshal(nmm); err != nil {
1325
- t.Error("unexpected error marshaling nmm: ", err)
1326
- }
1327
-
1328
- // Try a struct with a Marshaler field that is not nillable.
1329
- nnim := new(NNIMessage)
1330
- nnim.nni = 7
1331
- var _ Marshaler = nnim.nni // verify it is truly a Marshaler
1332
- if _, err := Marshal(nnim); err != nil {
1333
- t.Error("unexpected error marshaling nnim: ", err)
1334
- }
1335
-}
1336
-
1337
-func TestAllSetDefaults(t *testing.T) {
1338
- // Exercise SetDefaults with all scalar field types.
1339
- m := &Defaults{
1340
- // NaN != NaN, so override that here.
1341
- F_Nan: Float32(1.7),
1342
- }
1343
- expected := &Defaults{
1344
- F_Bool: Bool(true),
1345
- F_Int32: Int32(32),
1346
- F_Int64: Int64(64),
1347
- F_Fixed32: Uint32(320),
1348
- F_Fixed64: Uint64(640),
1349
- F_Uint32: Uint32(3200),
1350
- F_Uint64: Uint64(6400),
1351
- F_Float: Float32(314159),
1352
- F_Double: Float64(271828),
1353
- F_String: String(`hello, "world!"` + "\n"),
1354
- F_Bytes: []byte("Bignose"),
1355
- F_Sint32: Int32(-32),
1356
- F_Sint64: Int64(-64),
1357
- F_Enum: Defaults_GREEN.Enum(),
1358
- F_Pinf: Float32(float32(math.Inf(1))),
1359
- F_Ninf: Float32(float32(math.Inf(-1))),
1360
- F_Nan: Float32(1.7),
1361
- }
1362
- SetDefaults(m)
1363
- if !Equal(m, expected) {
1364
- t.Errorf(" got %v\nwant %v", m, expected)
1365
- }
1366
-}
1367
-
1368
-func TestSetDefaultsWithSetField(t *testing.T) {
1369
- // Check that a set value is not overridden.
1370
- m := &Defaults{
1371
- F_Int32: Int32(12),
1372
- }
1373
- SetDefaults(m)
1374
- if v := m.GetF_Int32(); v != 12 {
1375
- t.Errorf("m.FInt32 = %v, want 12", v)
1376
- }
1377
-}
1378
-
1379
-func TestSetDefaultsWithSubMessage(t *testing.T) {
1380
- m := &OtherMessage{
1381
- Key: Int64(123),
1382
- Inner: &InnerMessage{
1383
- Host: String("gopher"),
1384
- },
1385
- }
1386
- expected := &OtherMessage{
1387
- Key: Int64(123),
1388
- Inner: &InnerMessage{
1389
- Host: String("gopher"),
1390
- Port: Int32(4000),
1391
- },
1392
- }
1393
- SetDefaults(m)
1394
- if !Equal(m, expected) {
1395
- t.Errorf("\n got %v\nwant %v", m, expected)
1396
- }
1397
-}
1398
-
1399
-func TestSetDefaultsWithRepeatedSubMessage(t *testing.T) {
1400
- m := &MyMessage{
1401
- RepInner: []*InnerMessage{{}},
1402
- }
1403
- expected := &MyMessage{
1404
- RepInner: []*InnerMessage{{
1405
- Port: Int32(4000),
1406
- }},
1407
- }
1408
- SetDefaults(m)
1409
- if !Equal(m, expected) {
1410
- t.Errorf("\n got %v\nwant %v", m, expected)
1411
- }
1412
-}
1413
-
1414
-func TestMaximumTagNumber(t *testing.T) {
1415
- m := &MaxTag{
1416
- LastField: String("natural goat essence"),
1417
- }
1418
- buf, err := Marshal(m)
1419
- if err != nil {
1420
- t.Fatalf("proto.Marshal failed: %v", err)
1421
- }
1422
- m2 := new(MaxTag)
1423
- if err := Unmarshal(buf, m2); err != nil {
1424
- t.Fatalf("proto.Unmarshal failed: %v", err)
1425
- }
1426
- if got, want := m2.GetLastField(), *m.LastField; got != want {
1427
- t.Errorf("got %q, want %q", got, want)
1428
- }
1429
-}
1430
-
1431
-func TestJSON(t *testing.T) {
1432
- m := &MyMessage{
1433
- Count: Int32(4),
1434
- Pet: []string{"bunny", "kitty"},
1435
- Inner: &InnerMessage{
1436
- Host: String("cauchy"),
1437
- },
1438
- Bikeshed: MyMessage_GREEN.Enum(),
1439
- }
1440
- const expected = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":1}`
1441
-
1442
- b, err := json.Marshal(m)
1443
- if err != nil {
1444
- t.Fatalf("json.Marshal failed: %v", err)
1445
- }
1446
- s := string(b)
1447
- if s != expected {
1448
- t.Errorf("got %s\nwant %s", s, expected)
1449
- }
1450
-
1451
- received := new(MyMessage)
1452
- if err := json.Unmarshal(b, received); err != nil {
1453
- t.Fatalf("json.Unmarshal failed: %v", err)
1454
- }
1455
- if !Equal(received, m) {
1456
- t.Fatalf("got %s, want %s", received, m)
1457
- }
1458
-
1459
- // Test unmarshalling of JSON with symbolic enum name.
1460
- const old = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":"GREEN"}`
1461
- received.Reset()
1462
- if err := json.Unmarshal([]byte(old), received); err != nil {
1463
- t.Fatalf("json.Unmarshal failed: %v", err)
1464
- }
1465
- if !Equal(received, m) {
1466
- t.Fatalf("got %s, want %s", received, m)
1467
- }
1468
-}
1469
-
1470
-func TestBadWireType(t *testing.T) {
1471
- b := []byte{7<<3 | 6} // field 7, wire type 6
1472
- pb := new(OtherMessage)
1473
- if err := Unmarshal(b, pb); err == nil {
1474
- t.Errorf("Unmarshal did not fail")
1475
- } else if !strings.Contains(err.Error(), "unknown wire type") {
1476
- t.Errorf("wrong error: %v", err)
1477
- }
1478
-}
1479
-
1480
-func TestBytesWithInvalidLength(t *testing.T) {
1481
- // If a byte sequence has an invalid (negative) length, Unmarshal should not panic.
1482
- b := []byte{2<<3 | WireBytes, 0xff, 0xff, 0xff, 0xff, 0xff, 0}
1483
- Unmarshal(b, new(MyMessage))
1484
-}
1485
-
1486
-func TestLengthOverflow(t *testing.T) {
1487
- // Overflowing a length should not panic.
1488
- b := []byte{2<<3 | WireBytes, 1, 1, 3<<3 | WireBytes, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x01}
1489
- Unmarshal(b, new(MyMessage))
1490
-}
1491
-
1492
-func TestVarintOverflow(t *testing.T) {
1493
- // Overflowing a 64-bit length should not be allowed.
1494
- b := []byte{1<<3 | WireVarint, 0x01, 3<<3 | WireBytes, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01}
1495
- if err := Unmarshal(b, new(MyMessage)); err == nil {
1496
- t.Fatalf("Overflowed uint64 length without error")
1497
- }
1498
-}
1499
-
1500
-func TestUnmarshalFuzz(t *testing.T) {
1501
- const N = 1000
1502
- seed := time.Now().UnixNano()
1503
- t.Logf("RNG seed is %d", seed)
1504
- rng := rand.New(rand.NewSource(seed))
1505
- buf := make([]byte, 20)
1506
- for i := 0; i < N; i++ {
1507
- for j := range buf {
1508
- buf[j] = byte(rng.Intn(256))
1509
- }
1510
- fuzzUnmarshal(t, buf)
1511
- }
1512
-}
1513
-
1514
-func TestMergeMessages(t *testing.T) {
1515
- pb := &MessageList{Message: []*MessageList_Message{{Name: String("x"), Count: Int32(1)}}}
1516
- data, err := Marshal(pb)
1517
- if err != nil {
1518
- t.Fatalf("Marshal: %v", err)
1519
- }
1520
-
1521
- pb1 := new(MessageList)
1522
- if err := Unmarshal(data, pb1); err != nil {
1523
- t.Fatalf("first Unmarshal: %v", err)
1524
- }
1525
- if err := Unmarshal(data, pb1); err != nil {
1526
- t.Fatalf("second Unmarshal: %v", err)
1527
- }
1528
- if len(pb1.Message) != 1 {
1529
- t.Errorf("two Unmarshals produced %d Messages, want 1", len(pb1.Message))
1530
- }
1531
-
1532
- pb2 := new(MessageList)
1533
- if err := UnmarshalMerge(data, pb2); err != nil {
1534
- t.Fatalf("first UnmarshalMerge: %v", err)
1535
- }
1536
- if err := UnmarshalMerge(data, pb2); err != nil {
1537
- t.Fatalf("second UnmarshalMerge: %v", err)
1538
- }
1539
- if len(pb2.Message) != 2 {
1540
- t.Errorf("two UnmarshalMerges produced %d Messages, want 2", len(pb2.Message))
1541
- }
1542
-}
1543
-
1544
-func TestExtensionMarshalOrder(t *testing.T) {
1545
- m := &MyMessage{Count: Int(123)}
1546
- if err := SetExtension(m, E_Ext_More, &Ext{Data: String("alpha")}); err != nil {
1547
- t.Fatalf("SetExtension: %v", err)
1548
- }
1549
- if err := SetExtension(m, E_Ext_Text, String("aleph")); err != nil {
1550
- t.Fatalf("SetExtension: %v", err)
1551
- }
1552
- if err := SetExtension(m, E_Ext_Number, Int32(1)); err != nil {
1553
- t.Fatalf("SetExtension: %v", err)
1554
- }
1555
-
1556
- // Serialize m several times, and check we get the same bytes each time.
1557
- var orig []byte
1558
- for i := 0; i < 100; i++ {
1559
- b, err := Marshal(m)
1560
- if err != nil {
1561
- t.Fatalf("Marshal: %v", err)
1562
- }
1563
- if i == 0 {
1564
- orig = b
1565
- continue
1566
- }
1567
- if !bytes.Equal(b, orig) {
1568
- t.Errorf("Bytes differ on attempt #%d", i)
1569
- }
1570
- }
1571
-}
1572
-
1573
-// Many extensions, because small maps might not iterate differently on each iteration.
1574
-var exts = []*ExtensionDesc{
1575
- E_X201,
1576
- E_X202,
1577
- E_X203,
1578
- E_X204,
1579
- E_X205,
1580
- E_X206,
1581
- E_X207,
1582
- E_X208,
1583
- E_X209,
1584
- E_X210,
1585
- E_X211,
1586
- E_X212,
1587
- E_X213,
1588
- E_X214,
1589
- E_X215,
1590
- E_X216,
1591
- E_X217,
1592
- E_X218,
1593
- E_X219,
1594
- E_X220,
1595
- E_X221,
1596
- E_X222,
1597
- E_X223,
1598
- E_X224,
1599
- E_X225,
1600
- E_X226,
1601
- E_X227,
1602
- E_X228,
1603
- E_X229,
1604
- E_X230,
1605
- E_X231,
1606
- E_X232,
1607
- E_X233,
1608
- E_X234,
1609
- E_X235,
1610
- E_X236,
1611
- E_X237,
1612
- E_X238,
1613
- E_X239,
1614
- E_X240,
1615
- E_X241,
1616
- E_X242,
1617
- E_X243,
1618
- E_X244,
1619
- E_X245,
1620
- E_X246,
1621
- E_X247,
1622
- E_X248,
1623
- E_X249,
1624
- E_X250,
1625
-}
1626
-
1627
-func TestMessageSetMarshalOrder(t *testing.T) {
1628
- m := &MyMessageSet{}
1629
- for _, x := range exts {
1630
- if err := SetExtension(m, x, &Empty{}); err != nil {
1631
- t.Fatalf("SetExtension: %v", err)
1632
- }
1633
- }
1634
-
1635
- buf, err := Marshal(m)
1636
- if err != nil {
1637
- t.Fatalf("Marshal: %v", err)
1638
- }
1639
-
1640
- // Serialize m several times, and check we get the same bytes each time.
1641
- for i := 0; i < 10; i++ {
1642
- b1, err := Marshal(m)
1643
- if err != nil {
1644
- t.Fatalf("Marshal: %v", err)
1645
- }
1646
- if !bytes.Equal(b1, buf) {
1647
- t.Errorf("Bytes differ on re-Marshal #%d", i)
1648
- }
1649
-
1650
- m2 := &MyMessageSet{}
1651
- if err := Unmarshal(buf, m2); err != nil {
1652
- t.Errorf("Unmarshal: %v", err)
1653
- }
1654
- b2, err := Marshal(m2)
1655
- if err != nil {
1656
- t.Errorf("re-Marshal: %v", err)
1657
- }
1658
- if !bytes.Equal(b2, buf) {
1659
- t.Errorf("Bytes differ on round-trip #%d", i)
1660
- }
1661
- }
1662
-}
1663
-
1664
-func TestUnmarshalMergesMessages(t *testing.T) {
1665
- // If a nested message occurs twice in the input,
1666
- // the fields should be merged when decoding.
1667
- a := &OtherMessage{
1668
- Key: Int64(123),
1669
- Inner: &InnerMessage{
1670
- Host: String("polhode"),
1671
- Port: Int32(1234),
1672
- },
1673
- }
1674
- aData, err := Marshal(a)
1675
- if err != nil {
1676
- t.Fatalf("Marshal(a): %v", err)
1677
- }
1678
- b := &OtherMessage{
1679
- Weight: Float32(1.2),
1680
- Inner: &InnerMessage{
1681
- Host: String("herpolhode"),
1682
- Connected: Bool(true),
1683
- },
1684
- }
1685
- bData, err := Marshal(b)
1686
- if err != nil {
1687
- t.Fatalf("Marshal(b): %v", err)
1688
- }
1689
- want := &OtherMessage{
1690
- Key: Int64(123),
1691
- Weight: Float32(1.2),
1692
- Inner: &InnerMessage{
1693
- Host: String("herpolhode"),
1694
- Port: Int32(1234),
1695
- Connected: Bool(true),
1696
- },
1697
- }
1698
- got := new(OtherMessage)
1699
- if err := Unmarshal(append(aData, bData...), got); err != nil {
1700
- t.Fatalf("Unmarshal: %v", err)
1701
- }
1702
- if !Equal(got, want) {
1703
- t.Errorf("\n got %v\nwant %v", got, want)
1704
- }
1705
-}
1706
-
1707
-func TestEncodingSizes(t *testing.T) {
1708
- tests := []struct {
1709
- m Message
1710
- n int
1711
- }{
1712
- {&Defaults{F_Int32: Int32(math.MaxInt32)}, 6},
1713
- {&Defaults{F_Int32: Int32(math.MinInt32)}, 6},
1714
- {&Defaults{F_Uint32: Uint32(math.MaxUint32)}, 6},
1715
- }
1716
- for _, test := range tests {
1717
- b, err := Marshal(test.m)
1718
- if err != nil {
1719
- t.Errorf("Marshal(%v): %v", test.m, err)
1720
- continue
1721
- }
1722
- if len(b) != test.n {
1723
- t.Errorf("Marshal(%v) yielded %d bytes, want %d bytes", test.m, len(b), test.n)
1724
- }
1725
- }
1726
-}
1727
-
1728
-func TestRequiredNotSetError(t *testing.T) {
1729
- pb := initGoTest(false)
1730
- pb.RequiredField.Label = nil
1731
- pb.F_Int32Required = nil
1732
- pb.F_Int64Required = nil
1733
-
1734
- expected := "0807" + // field 1, encoding 0, value 7
1735
- "2206" + "120474797065" + // field 4, encoding 2 (GoTestField)
1736
- "5001" + // field 10, encoding 0, value 1
1737
- "6d20000000" + // field 13, encoding 5, value 0x20
1738
- "714000000000000000" + // field 14, encoding 1, value 0x40
1739
- "78a019" + // field 15, encoding 0, value 0xca0 = 3232
1740
- "8001c032" + // field 16, encoding 0, value 0x1940 = 6464
1741
- "8d0100004a45" + // field 17, encoding 5, value 3232.0
1742
- "9101000000000040b940" + // field 18, encoding 1, value 6464.0
1743
- "9a0106" + "737472696e67" + // field 19, encoding 2, string "string"
1744
- "b304" + // field 70, encoding 3, start group
1745
- "ba0408" + "7265717569726564" + // field 71, encoding 2, string "required"
1746
- "b404" + // field 70, encoding 4, end group
1747
- "aa0605" + "6279746573" + // field 101, encoding 2, string "bytes"
1748
- "b0063f" + // field 102, encoding 0, 0x3f zigzag32
1749
- "b8067f" // field 103, encoding 0, 0x7f zigzag64
1750
-
1751
- o := old()
1752
- bytes, err := Marshal(pb)
1753
- if _, ok := err.(*RequiredNotSetError); !ok {
1754
- fmt.Printf("marshal-1 err = %v, want *RequiredNotSetError", err)
1755
- o.DebugPrint("", bytes)
1756
- t.Fatalf("expected = %s", expected)
1757
- }
1758
- if strings.Index(err.Error(), "RequiredField.Label") < 0 {
1759
- t.Errorf("marshal-1 wrong err msg: %v", err)
1760
- }
1761
- if !equal(bytes, expected, t) {
1762
- o.DebugPrint("neq 1", bytes)
1763
- t.Fatalf("expected = %s", expected)
1764
- }
1765
-
1766
- // Now test Unmarshal by recreating the original buffer.
1767
- pbd := new(GoTest)
1768
- err = Unmarshal(bytes, pbd)
1769
- if _, ok := err.(*RequiredNotSetError); !ok {
1770
- t.Fatalf("unmarshal err = %v, want *RequiredNotSetError", err)
1771
- o.DebugPrint("", bytes)
1772
- t.Fatalf("string = %s", expected)
1773
- }
1774
- if strings.Index(err.Error(), "RequiredField.{Unknown}") < 0 {
1775
- t.Errorf("unmarshal wrong err msg: %v", err)
1776
- }
1777
- bytes, err = Marshal(pbd)
1778
- if _, ok := err.(*RequiredNotSetError); !ok {
1779
- t.Errorf("marshal-2 err = %v, want *RequiredNotSetError", err)
1780
- o.DebugPrint("", bytes)
1781
- t.Fatalf("string = %s", expected)
1782
- }
1783
- if strings.Index(err.Error(), "RequiredField.Label") < 0 {
1784
- t.Errorf("marshal-2 wrong err msg: %v", err)
1785
- }
1786
- if !equal(bytes, expected, t) {
1787
- o.DebugPrint("neq 2", bytes)
1788
- t.Fatalf("string = %s", expected)
1789
- }
1790
-}
1791
-
1792
-func fuzzUnmarshal(t *testing.T, data []byte) {
1793
- defer func() {
1794
- if e := recover(); e != nil {
1795
- t.Errorf("These bytes caused a panic: %+v", data)
1796
- t.Logf("Stack:\n%s", debug.Stack())
1797
- t.FailNow()
1798
- }
1799
- }()
1800
-
1801
- pb := new(MyMessage)
1802
- Unmarshal(data, pb)
1803
-}
1804
-
1805
-// Benchmarks
1806
-
1807
-func testMsg() *GoTest {
1808
- pb := initGoTest(true)
1809
- const N = 1000 // Internally the library starts much smaller.
1810
- pb.F_Int32Repeated = make([]int32, N)
1811
- pb.F_DoubleRepeated = make([]float64, N)
1812
- for i := 0; i < N; i++ {
1813
- pb.F_Int32Repeated[i] = int32(i)
1814
- pb.F_DoubleRepeated[i] = float64(i)
1815
- }
1816
- return pb
1817
-}
1818
-
1819
-func bytesMsg() *GoTest {
1820
- pb := initGoTest(true)
1821
- buf := make([]byte, 4000)
1822
- for i := range buf {
1823
- buf[i] = byte(i)
1824
- }
1825
- pb.F_BytesDefaulted = buf
1826
- return pb
1827
-}
1828
-
1829
-func benchmarkMarshal(b *testing.B, pb Message, marshal func(Message) ([]byte, error)) {
1830
- d, _ := marshal(pb)
1831
- b.SetBytes(int64(len(d)))
1832
- b.ResetTimer()
1833
- for i := 0; i < b.N; i++ {
1834
- marshal(pb)
1835
- }
1836
-}
1837
-
1838
-func benchmarkBufferMarshal(b *testing.B, pb Message) {
1839
- p := NewBuffer(nil)
1840
- benchmarkMarshal(b, pb, func(pb0 Message) ([]byte, error) {
1841
- p.Reset()
1842
- err := p.Marshal(pb0)
1843
- return p.Bytes(), err
1844
- })
1845
-}
1846
-
1847
-func benchmarkSize(b *testing.B, pb Message) {
1848
- benchmarkMarshal(b, pb, func(pb0 Message) ([]byte, error) {
1849
- Size(pb)
1850
- return nil, nil
1851
- })
1852
-}
1853
-
1854
-func newOf(pb Message) Message {
1855
- in := reflect.ValueOf(pb)
1856
- if in.IsNil() {
1857
- return pb
1858
- }
1859
- return reflect.New(in.Type().Elem()).Interface().(Message)
1860
-}
1861
-
1862
-func benchmarkUnmarshal(b *testing.B, pb Message, unmarshal func([]byte, Message) error) {
1863
- d, _ := Marshal(pb)
1864
- b.SetBytes(int64(len(d)))
1865
- pbd := newOf(pb)
1866
-
1867
- b.ResetTimer()
1868
- for i := 0; i < b.N; i++ {
1869
- unmarshal(d, pbd)
1870
- }
1871
-}
1872
-
1873
-func benchmarkBufferUnmarshal(b *testing.B, pb Message) {
1874
- p := NewBuffer(nil)
1875
- benchmarkUnmarshal(b, pb, func(d []byte, pb0 Message) error {
1876
- p.SetBuf(d)
1877
- return p.Unmarshal(pb0)
1878
- })
1879
-}
1880
-
1881
-// Benchmark{Marshal,BufferMarshal,Size,Unmarshal,BufferUnmarshal}{,Bytes}
1882
-
1883
-func BenchmarkMarshal(b *testing.B) {
1884
- benchmarkMarshal(b, testMsg(), Marshal)
1885
-}
1886
-
1887
-func BenchmarkBufferMarshal(b *testing.B) {
1888
- benchmarkBufferMarshal(b, testMsg())
1889
-}
1890
-
1891
-func BenchmarkSize(b *testing.B) {
1892
- benchmarkSize(b, testMsg())
1893
-}
1894
-
1895
-func BenchmarkUnmarshal(b *testing.B) {
1896
- benchmarkUnmarshal(b, testMsg(), Unmarshal)
1897
-}
1898
-
1899
-func BenchmarkBufferUnmarshal(b *testing.B) {
1900
- benchmarkBufferUnmarshal(b, testMsg())
1901
-}
1902
-
1903
-func BenchmarkMarshalBytes(b *testing.B) {
1904
- benchmarkMarshal(b, bytesMsg(), Marshal)
1905
-}
1906
-
1907
-func BenchmarkBufferMarshalBytes(b *testing.B) {
1908
- benchmarkBufferMarshal(b, bytesMsg())
1909
-}
1910
-
1911
-func BenchmarkSizeBytes(b *testing.B) {
1912
- benchmarkSize(b, bytesMsg())
1913
-}
1914
-
1915
-func BenchmarkUnmarshalBytes(b *testing.B) {
1916
- benchmarkUnmarshal(b, bytesMsg(), Unmarshal)
1917
-}
1918
-
1919
-func BenchmarkBufferUnmarshalBytes(b *testing.B) {
1920
- benchmarkBufferUnmarshal(b, bytesMsg())
1921
-}
1922
-
1923
-func BenchmarkUnmarshalUnrecognizedFields(b *testing.B) {
1924
- b.StopTimer()
1925
- pb := initGoTestField()
1926
- skip := &GoSkipTest{
1927
- SkipInt32: Int32(32),
1928
- SkipFixed32: Uint32(3232),
1929
- SkipFixed64: Uint64(6464),
1930
- SkipString: String("skipper"),
1931
- Skipgroup: &GoSkipTest_SkipGroup{
1932
- GroupInt32: Int32(75),
1933
- GroupString: String("wxyz"),
1934
- },
1935
- }
1936
-
1937
- pbd := new(GoTestField)
1938
- p := NewBuffer(nil)
1939
- p.Marshal(pb)
1940
- p.Marshal(skip)
1941
- p2 := NewBuffer(nil)
1942
-
1943
- b.StartTimer()
1944
- for i := 0; i < b.N; i++ {
1945
- p2.SetBuf(p.Bytes())
1946
- p2.Unmarshal(pbd)
1947
- }
1948
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/clone_test.go
deleted
-186
@@ -1,186 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2011 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto_test
33
-
34
-import (
35
- "testing"
36
-
37
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
38
-
39
- pb "./testdata"
40
-)
41
-
42
-var cloneTestMessage = &pb.MyMessage{
43
- Count: proto.Int32(42),
44
- Name: proto.String("Dave"),
45
- Pet: []string{"bunny", "kitty", "horsey"},
46
- Inner: &pb.InnerMessage{
47
- Host: proto.String("niles"),
48
- Port: proto.Int32(9099),
49
- Connected: proto.Bool(true),
50
- },
51
- Others: []*pb.OtherMessage{
52
- {
53
- Value: []byte("some bytes"),
54
- },
55
- },
56
- Somegroup: &pb.MyMessage_SomeGroup{
57
- GroupField: proto.Int32(6),
58
- },
59
- RepBytes: [][]byte{[]byte("sham"), []byte("wow")},
60
-}
61
-
62
-func init() {
63
- ext := &pb.Ext{
64
- Data: proto.String("extension"),
65
- }
66
- if err := proto.SetExtension(cloneTestMessage, pb.E_Ext_More, ext); err != nil {
67
- panic("SetExtension: " + err.Error())
68
- }
69
-}
70
-
71
-func TestClone(t *testing.T) {
72
- m := proto.Clone(cloneTestMessage).(*pb.MyMessage)
73
- if !proto.Equal(m, cloneTestMessage) {
74
- t.Errorf("Clone(%v) = %v", cloneTestMessage, m)
75
- }
76
-
77
- // Verify it was a deep copy.
78
- *m.Inner.Port++
79
- if proto.Equal(m, cloneTestMessage) {
80
- t.Error("Mutating clone changed the original")
81
- }
82
-}
83
-
84
-func TestCloneNil(t *testing.T) {
85
- var m *pb.MyMessage
86
- if c := proto.Clone(m); !proto.Equal(m, c) {
87
- t.Errorf("Clone(%v) = %v", m, c)
88
- }
89
-}
90
-
91
-var mergeTests = []struct {
92
- src, dst, want proto.Message
93
-}{
94
- {
95
- src: &pb.MyMessage{
96
- Count: proto.Int32(42),
97
- },
98
- dst: &pb.MyMessage{
99
- Name: proto.String("Dave"),
100
- },
101
- want: &pb.MyMessage{
102
- Count: proto.Int32(42),
103
- Name: proto.String("Dave"),
104
- },
105
- },
106
- {
107
- src: &pb.MyMessage{
108
- Inner: &pb.InnerMessage{
109
- Host: proto.String("hey"),
110
- Connected: proto.Bool(true),
111
- },
112
- Pet: []string{"horsey"},
113
- Others: []*pb.OtherMessage{
114
- {
115
- Value: []byte("some bytes"),
116
- },
117
- },
118
- },
119
- dst: &pb.MyMessage{
120
- Inner: &pb.InnerMessage{
121
- Host: proto.String("niles"),
122
- Port: proto.Int32(9099),
123
- },
124
- Pet: []string{"bunny", "kitty"},
125
- Others: []*pb.OtherMessage{
126
- {
127
- Key: proto.Int64(31415926535),
128
- },
129
- {
130
- // Explicitly test a src=nil field
131
- Inner: nil,
132
- },
133
- },
134
- },
135
- want: &pb.MyMessage{
136
- Inner: &pb.InnerMessage{
137
- Host: proto.String("hey"),
138
- Connected: proto.Bool(true),
139
- Port: proto.Int32(9099),
140
- },
141
- Pet: []string{"bunny", "kitty", "horsey"},
142
- Others: []*pb.OtherMessage{
143
- {
144
- Key: proto.Int64(31415926535),
145
- },
146
- {},
147
- {
148
- Value: []byte("some bytes"),
149
- },
150
- },
151
- },
152
- },
153
- {
154
- src: &pb.MyMessage{
155
- RepBytes: [][]byte{[]byte("wow")},
156
- },
157
- dst: &pb.MyMessage{
158
- Somegroup: &pb.MyMessage_SomeGroup{
159
- GroupField: proto.Int32(6),
160
- },
161
- RepBytes: [][]byte{[]byte("sham")},
162
- },
163
- want: &pb.MyMessage{
164
- Somegroup: &pb.MyMessage_SomeGroup{
165
- GroupField: proto.Int32(6),
166
- },
167
- RepBytes: [][]byte{[]byte("sham"), []byte("wow")},
168
- },
169
- },
170
- // Check that a scalar bytes field replaces rather than appends.
171
- {
172
- src: &pb.OtherMessage{Value: []byte("foo")},
173
- dst: &pb.OtherMessage{Value: []byte("bar")},
174
- want: &pb.OtherMessage{Value: []byte("foo")},
175
- },
176
-}
177
-
178
-func TestMerge(t *testing.T) {
179
- for _, m := range mergeTests {
180
- got := proto.Clone(m.dst)
181
- proto.Merge(got, m.src)
182
- if !proto.Equal(got, m.want) {
183
- t.Errorf("Merge(%v, %v)\n got %v\nwant %v\n", m.dst, m.src, got, m.want)
184
- }
185
- }
186
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/encode.go
deleted
-961
@@ -1,961 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto
33
-
34
-/*
35
- * Routines for encoding data into the wire format for protocol buffers.
36
- */
37
-
38
-import (
39
- "errors"
40
- "fmt"
41
- "reflect"
42
- "sort"
43
-)
44
-
45
-// RequiredNotSetError is the error returned if Marshal is called with
46
-// a protocol buffer struct whose required fields have not
47
-// all been initialized. It is also the error returned if Unmarshal is
48
-// called with an encoded protocol buffer that does not include all the
49
-// required fields.
50
-//
51
-// When printed, RequiredNotSetError reports the first unset required field in a
52
-// message. If the field cannot be precisely determined, it is reported as
53
-// "{Unknown}".
54
-type RequiredNotSetError struct {
55
- field string
56
-}
57
-
58
-func (e *RequiredNotSetError) Error() string {
59
- return fmt.Sprintf("proto: required field %q not set", e.field)
60
-}
61
-
62
-var (
63
- // ErrRepeatedHasNil is the error returned if Marshal is called with
64
- // a struct with a repeated field containing a nil element.
65
- ErrRepeatedHasNil = errors.New("proto: repeated field has nil element")
66
-
67
- // ErrNil is the error returned if Marshal is called with nil.
68
- ErrNil = errors.New("proto: Marshal called with nil")
69
-)
70
-
71
-// The fundamental encoders that put bytes on the wire.
72
-// Those that take integer types all accept uint64 and are
73
-// therefore of type valueEncoder.
74
-
75
-const maxVarintBytes = 10 // maximum length of a varint
76
-
77
-// EncodeVarint returns the varint encoding of x.
78
-// This is the format for the
79
-// int32, int64, uint32, uint64, bool, and enum
80
-// protocol buffer types.
81
-// Not used by the package itself, but helpful to clients
82
-// wishing to use the same encoding.
83
-func EncodeVarint(x uint64) []byte {
84
- var buf [maxVarintBytes]byte
85
- var n int
86
- for n = 0; x > 127; n++ {
87
- buf[n] = 0x80 | uint8(x&0x7F)
88
- x >>= 7
89
- }
90
- buf[n] = uint8(x)
91
- n++
92
- return buf[0:n]
93
-}
94
-
95
-// EncodeVarint writes a varint-encoded integer to the Buffer.
96
-// This is the format for the
97
-// int32, int64, uint32, uint64, bool, and enum
98
-// protocol buffer types.
99
-func (p *Buffer) EncodeVarint(x uint64) error {
100
- for x >= 1<<7 {
101
- p.buf = append(p.buf, uint8(x&0x7f|0x80))
102
- x >>= 7
103
- }
104
- p.buf = append(p.buf, uint8(x))
105
- return nil
106
-}
107
-
108
-func sizeVarint(x uint64) (n int) {
109
- for {
110
- n++
111
- x >>= 7
112
- if x == 0 {
113
- break
114
- }
115
- }
116
- return n
117
-}
118
-
119
-// EncodeFixed64 writes a 64-bit integer to the Buffer.
120
-// This is the format for the
121
-// fixed64, sfixed64, and double protocol buffer types.
122
-func (p *Buffer) EncodeFixed64(x uint64) error {
123
- p.buf = append(p.buf,
124
- uint8(x),
125
- uint8(x>>8),
126
- uint8(x>>16),
127
- uint8(x>>24),
128
- uint8(x>>32),
129
- uint8(x>>40),
130
- uint8(x>>48),
131
- uint8(x>>56))
132
- return nil
133
-}
134
-
135
-func sizeFixed64(x uint64) int {
136
- return 8
137
-}
138
-
139
-// EncodeFixed32 writes a 32-bit integer to the Buffer.
140
-// This is the format for the
141
-// fixed32, sfixed32, and float protocol buffer types.
142
-func (p *Buffer) EncodeFixed32(x uint64) error {
143
- p.buf = append(p.buf,
144
- uint8(x),
145
- uint8(x>>8),
146
- uint8(x>>16),
147
- uint8(x>>24))
148
- return nil
149
-}
150
-
151
-func sizeFixed32(x uint64) int {
152
- return 4
153
-}
154
-
155
-// EncodeZigzag64 writes a zigzag-encoded 64-bit integer
156
-// to the Buffer.
157
-// This is the format used for the sint64 protocol buffer type.
158
-func (p *Buffer) EncodeZigzag64(x uint64) error {
159
- // use signed number to get arithmetic right shift.
160
- return p.EncodeVarint(uint64((x << 1) ^ uint64((int64(x) >> 63))))
161
-}
162
-
163
-func sizeZigzag64(x uint64) int {
164
- return sizeVarint(uint64((x << 1) ^ uint64((int64(x) >> 63))))
165
-}
166
-
167
-// EncodeZigzag32 writes a zigzag-encoded 32-bit integer
168
-// to the Buffer.
169
-// This is the format used for the sint32 protocol buffer type.
170
-func (p *Buffer) EncodeZigzag32(x uint64) error {
171
- // use signed number to get arithmetic right shift.
172
- return p.EncodeVarint(uint64((uint32(x) << 1) ^ uint32((int32(x) >> 31))))
173
-}
174
-
175
-func sizeZigzag32(x uint64) int {
176
- return sizeVarint(uint64((uint32(x) << 1) ^ uint32((int32(x) >> 31))))
177
-}
178
-
179
-// EncodeRawBytes writes a count-delimited byte buffer to the Buffer.
180
-// This is the format used for the bytes protocol buffer
181
-// type and for embedded messages.
182
-func (p *Buffer) EncodeRawBytes(b []byte) error {
183
- p.EncodeVarint(uint64(len(b)))
184
- p.buf = append(p.buf, b...)
185
- return nil
186
-}
187
-
188
-func sizeRawBytes(b []byte) int {
189
- return sizeVarint(uint64(len(b))) +
190
- len(b)
191
-}
192
-
193
-// EncodeStringBytes writes an encoded string to the Buffer.
194
-// This is the format used for the proto2 string type.
195
-func (p *Buffer) EncodeStringBytes(s string) error {
196
- p.EncodeVarint(uint64(len(s)))
197
- p.buf = append(p.buf, s...)
198
- return nil
199
-}
200
-
201
-func sizeStringBytes(s string) int {
202
- return sizeVarint(uint64(len(s))) +
203
- len(s)
204
-}
205
-
206
-// Marshaler is the interface representing objects that can marshal themselves.
207
-type Marshaler interface {
208
- Marshal() ([]byte, error)
209
-}
210
-
211
-// Marshal takes the protocol buffer
212
-// and encodes it into the wire format, returning the data.
213
-func Marshal(pb Message) ([]byte, error) {
214
- // Can the object marshal itself?
215
- if m, ok := pb.(Marshaler); ok {
216
- return m.Marshal()
217
- }
218
- p := NewBuffer(nil)
219
- err := p.Marshal(pb)
220
- var state errorState
221
- if err != nil && !state.shouldContinue(err, nil) {
222
- return nil, err
223
- }
224
- if p.buf == nil && err == nil {
225
- // Return a non-nil slice on success.
226
- return []byte{}, nil
227
- }
228
- return p.buf, err
229
-}
230
-
231
-// Marshal takes the protocol buffer
232
-// and encodes it into the wire format, writing the result to the
233
-// Buffer.
234
-func (p *Buffer) Marshal(pb Message) error {
235
- // Can the object marshal itself?
236
- if m, ok := pb.(Marshaler); ok {
237
- data, err := m.Marshal()
238
- if err != nil {
239
- return err
240
- }
241
- p.buf = append(p.buf, data...)
242
- return nil
243
- }
244
-
245
- t, base, err := getbase(pb)
246
- if structPointer_IsNil(base) {
247
- return ErrNil
248
- }
249
- if err == nil {
250
- err = p.enc_struct(t.Elem(), GetProperties(t.Elem()), base)
251
- }
252
-
253
- if collectStats {
254
- stats.Encode++
255
- }
256
-
257
- return err
258
-}
259
-
260
-// Size returns the encoded size of a protocol buffer.
261
-func Size(pb Message) (n int) {
262
- // Can the object marshal itself? If so, Size is slow.
263
- // TODO: add Size to Marshaler, or add a Sizer interface.
264
- if m, ok := pb.(Marshaler); ok {
265
- b, _ := m.Marshal()
266
- return len(b)
267
- }
268
-
269
- t, base, err := getbase(pb)
270
- if structPointer_IsNil(base) {
271
- return 0
272
- }
273
- if err == nil {
274
- n = size_struct(t.Elem(), GetProperties(t.Elem()), base)
275
- }
276
-
277
- if collectStats {
278
- stats.Size++
279
- }
280
-
281
- return
282
-}
283
-
284
-// Individual type encoders.
285
-
286
-// Encode a bool.
287
-func (o *Buffer) enc_bool(p *Properties, base structPointer) error {
288
- v := *structPointer_Bool(base, p.field)
289
- if v == nil {
290
- return ErrNil
291
- }
292
- x := 0
293
- if *v {
294
- x = 1
295
- }
296
- o.buf = append(o.buf, p.tagcode...)
297
- p.valEnc(o, uint64(x))
298
- return nil
299
-}
300
-
301
-func size_bool(p *Properties, base structPointer) int {
302
- v := *structPointer_Bool(base, p.field)
303
- if v == nil {
304
- return 0
305
- }
306
- return len(p.tagcode) + 1 // each bool takes exactly one byte
307
-}
308
-
309
-// Encode an int32.
310
-func (o *Buffer) enc_int32(p *Properties, base structPointer) error {
311
- v := structPointer_Word32(base, p.field)
312
- if word32_IsNil(v) {
313
- return ErrNil
314
- }
315
- x := word32_Get(v)
316
- o.buf = append(o.buf, p.tagcode...)
317
- p.valEnc(o, uint64(x))
318
- return nil
319
-}
320
-
321
-func size_int32(p *Properties, base structPointer) (n int) {
322
- v := structPointer_Word32(base, p.field)
323
- if word32_IsNil(v) {
324
- return 0
325
- }
326
- x := word32_Get(v)
327
- n += len(p.tagcode)
328
- n += p.valSize(uint64(x))
329
- return
330
-}
331
-
332
-// Encode an int64.
333
-func (o *Buffer) enc_int64(p *Properties, base structPointer) error {
334
- v := structPointer_Word64(base, p.field)
335
- if word64_IsNil(v) {
336
- return ErrNil
337
- }
338
- x := word64_Get(v)
339
- o.buf = append(o.buf, p.tagcode...)
340
- p.valEnc(o, x)
341
- return nil
342
-}
343
-
344
-func size_int64(p *Properties, base structPointer) (n int) {
345
- v := structPointer_Word64(base, p.field)
346
- if word64_IsNil(v) {
347
- return 0
348
- }
349
- x := word64_Get(v)
350
- n += len(p.tagcode)
351
- n += p.valSize(x)
352
- return
353
-}
354
-
355
-// Encode a string.
356
-func (o *Buffer) enc_string(p *Properties, base structPointer) error {
357
- v := *structPointer_String(base, p.field)
358
- if v == nil {
359
- return ErrNil
360
- }
361
- x := *v
362
- o.buf = append(o.buf, p.tagcode...)
363
- o.EncodeStringBytes(x)
364
- return nil
365
-}
366
-
367
-func size_string(p *Properties, base structPointer) (n int) {
368
- v := *structPointer_String(base, p.field)
369
- if v == nil {
370
- return 0
371
- }
372
- x := *v
373
- n += len(p.tagcode)
374
- n += sizeStringBytes(x)
375
- return
376
-}
377
-
378
-// All protocol buffer fields are nillable, but be careful.
379
-func isNil(v reflect.Value) bool {
380
- switch v.Kind() {
381
- case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
382
- return v.IsNil()
383
- }
384
- return false
385
-}
386
-
387
-// Encode a message struct.
388
-func (o *Buffer) enc_struct_message(p *Properties, base structPointer) error {
389
- var state errorState
390
- structp := structPointer_GetStructPointer(base, p.field)
391
- if structPointer_IsNil(structp) {
392
- return ErrNil
393
- }
394
-
395
- // Can the object marshal itself?
396
- if p.isMarshaler {
397
- m := structPointer_Interface(structp, p.stype).(Marshaler)
398
- data, err := m.Marshal()
399
- if err != nil && !state.shouldContinue(err, nil) {
400
- return err
401
- }
402
- o.buf = append(o.buf, p.tagcode...)
403
- o.EncodeRawBytes(data)
404
- return nil
405
- }
406
-
407
- o.buf = append(o.buf, p.tagcode...)
408
- return o.enc_len_struct(p.stype, p.sprop, structp, &state)
409
-}
410
-
411
-func size_struct_message(p *Properties, base structPointer) int {
412
- structp := structPointer_GetStructPointer(base, p.field)
413
- if structPointer_IsNil(structp) {
414
- return 0
415
- }
416
-
417
- // Can the object marshal itself?
418
- if p.isMarshaler {
419
- m := structPointer_Interface(structp, p.stype).(Marshaler)
420
- data, _ := m.Marshal()
421
- n0 := len(p.tagcode)
422
- n1 := sizeRawBytes(data)
423
- return n0 + n1
424
- }
425
-
426
- n0 := len(p.tagcode)
427
- n1 := size_struct(p.stype, p.sprop, structp)
428
- n2 := sizeVarint(uint64(n1)) // size of encoded length
429
- return n0 + n1 + n2
430
-}
431
-
432
-// Encode a group struct.
433
-func (o *Buffer) enc_struct_group(p *Properties, base structPointer) error {
434
- var state errorState
435
- b := structPointer_GetStructPointer(base, p.field)
436
- if structPointer_IsNil(b) {
437
- return ErrNil
438
- }
439
-
440
- o.EncodeVarint(uint64((p.Tag << 3) | WireStartGroup))
441
- err := o.enc_struct(p.stype, p.sprop, b)
442
- if err != nil && !state.shouldContinue(err, nil) {
443
- return err
444
- }
445
- o.EncodeVarint(uint64((p.Tag << 3) | WireEndGroup))
446
- return state.err
447
-}
448
-
449
-func size_struct_group(p *Properties, base structPointer) (n int) {
450
- b := structPointer_GetStructPointer(base, p.field)
451
- if structPointer_IsNil(b) {
452
- return 0
453
- }
454
-
455
- n += sizeVarint(uint64((p.Tag << 3) | WireStartGroup))
456
- n += size_struct(p.stype, p.sprop, b)
457
- n += sizeVarint(uint64((p.Tag << 3) | WireEndGroup))
458
- return
459
-}
460
-
461
-// Encode a slice of bools ([]bool).
462
-func (o *Buffer) enc_slice_bool(p *Properties, base structPointer) error {
463
- s := *structPointer_BoolSlice(base, p.field)
464
- l := len(s)
465
- if l == 0 {
466
- return ErrNil
467
- }
468
- for _, x := range s {
469
- o.buf = append(o.buf, p.tagcode...)
470
- v := uint64(0)
471
- if x {
472
- v = 1
473
- }
474
- p.valEnc(o, v)
475
- }
476
- return nil
477
-}
478
-
479
-func size_slice_bool(p *Properties, base structPointer) int {
480
- s := *structPointer_BoolSlice(base, p.field)
481
- l := len(s)
482
- if l == 0 {
483
- return 0
484
- }
485
- return l * (len(p.tagcode) + 1) // each bool takes exactly one byte
486
-}
487
-
488
-// Encode a slice of bools ([]bool) in packed format.
489
-func (o *Buffer) enc_slice_packed_bool(p *Properties, base structPointer) error {
490
- s := *structPointer_BoolSlice(base, p.field)
491
- l := len(s)
492
- if l == 0 {
493
- return ErrNil
494
- }
495
- o.buf = append(o.buf, p.tagcode...)
496
- o.EncodeVarint(uint64(l)) // each bool takes exactly one byte
497
- for _, x := range s {
498
- v := uint64(0)
499
- if x {
500
- v = 1
501
- }
502
- p.valEnc(o, v)
503
- }
504
- return nil
505
-}
506
-
507
-func size_slice_packed_bool(p *Properties, base structPointer) (n int) {
508
- s := *structPointer_BoolSlice(base, p.field)
509
- l := len(s)
510
- if l == 0 {
511
- return 0
512
- }
513
- n += len(p.tagcode)
514
- n += sizeVarint(uint64(l))
515
- n += l // each bool takes exactly one byte
516
- return
517
-}
518
-
519
-// Encode a slice of bytes ([]byte).
520
-func (o *Buffer) enc_slice_byte(p *Properties, base structPointer) error {
521
- s := *structPointer_Bytes(base, p.field)
522
- if s == nil {
523
- return ErrNil
524
- }
525
- o.buf = append(o.buf, p.tagcode...)
526
- o.EncodeRawBytes(s)
527
- return nil
528
-}
529
-
530
-func size_slice_byte(p *Properties, base structPointer) (n int) {
531
- s := *structPointer_Bytes(base, p.field)
532
- if s == nil {
533
- return 0
534
- }
535
- n += len(p.tagcode)
536
- n += sizeRawBytes(s)
537
- return
538
-}
539
-
540
-// Encode a slice of int32s ([]int32).
541
-func (o *Buffer) enc_slice_int32(p *Properties, base structPointer) error {
542
- s := structPointer_Word32Slice(base, p.field)
543
- l := s.Len()
544
- if l == 0 {
545
- return ErrNil
546
- }
547
- for i := 0; i < l; i++ {
548
- o.buf = append(o.buf, p.tagcode...)
549
- x := s.Index(i)
550
- p.valEnc(o, uint64(x))
551
- }
552
- return nil
553
-}
554
-
555
-func size_slice_int32(p *Properties, base structPointer) (n int) {
556
- s := structPointer_Word32Slice(base, p.field)
557
- l := s.Len()
558
- if l == 0 {
559
- return 0
560
- }
561
- for i := 0; i < l; i++ {
562
- n += len(p.tagcode)
563
- x := s.Index(i)
564
- n += p.valSize(uint64(x))
565
- }
566
- return
567
-}
568
-
569
-// Encode a slice of int32s ([]int32) in packed format.
570
-func (o *Buffer) enc_slice_packed_int32(p *Properties, base structPointer) error {
571
- s := structPointer_Word32Slice(base, p.field)
572
- l := s.Len()
573
- if l == 0 {
574
- return ErrNil
575
- }
576
- // TODO: Reuse a Buffer.
577
- buf := NewBuffer(nil)
578
- for i := 0; i < l; i++ {
579
- p.valEnc(buf, uint64(s.Index(i)))
580
- }
581
-
582
- o.buf = append(o.buf, p.tagcode...)
583
- o.EncodeVarint(uint64(len(buf.buf)))
584
- o.buf = append(o.buf, buf.buf...)
585
- return nil
586
-}
587
-
588
-func size_slice_packed_int32(p *Properties, base structPointer) (n int) {
589
- s := structPointer_Word32Slice(base, p.field)
590
- l := s.Len()
591
- if l == 0 {
592
- return 0
593
- }
594
- var bufSize int
595
- for i := 0; i < l; i++ {
596
- bufSize += p.valSize(uint64(s.Index(i)))
597
- }
598
-
599
- n += len(p.tagcode)
600
- n += sizeVarint(uint64(bufSize))
601
- n += bufSize
602
- return
603
-}
604
-
605
-// Encode a slice of int64s ([]int64).
606
-func (o *Buffer) enc_slice_int64(p *Properties, base structPointer) error {
607
- s := structPointer_Word64Slice(base, p.field)
608
- l := s.Len()
609
- if l == 0 {
610
- return ErrNil
611
- }
612
- for i := 0; i < l; i++ {
613
- o.buf = append(o.buf, p.tagcode...)
614
- p.valEnc(o, s.Index(i))
615
- }
616
- return nil
617
-}
618
-
619
-func size_slice_int64(p *Properties, base structPointer) (n int) {
620
- s := structPointer_Word64Slice(base, p.field)
621
- l := s.Len()
622
- if l == 0 {
623
- return 0
624
- }
625
- for i := 0; i < l; i++ {
626
- n += len(p.tagcode)
627
- n += p.valSize(s.Index(i))
628
- }
629
- return
630
-}
631
-
632
-// Encode a slice of int64s ([]int64) in packed format.
633
-func (o *Buffer) enc_slice_packed_int64(p *Properties, base structPointer) error {
634
- s := structPointer_Word64Slice(base, p.field)
635
- l := s.Len()
636
- if l == 0 {
637
- return ErrNil
638
- }
639
- // TODO: Reuse a Buffer.
640
- buf := NewBuffer(nil)
641
- for i := 0; i < l; i++ {
642
- p.valEnc(buf, s.Index(i))
643
- }
644
-
645
- o.buf = append(o.buf, p.tagcode...)
646
- o.EncodeVarint(uint64(len(buf.buf)))
647
- o.buf = append(o.buf, buf.buf...)
648
- return nil
649
-}
650
-
651
-func size_slice_packed_int64(p *Properties, base structPointer) (n int) {
652
- s := structPointer_Word64Slice(base, p.field)
653
- l := s.Len()
654
- if l == 0 {
655
- return 0
656
- }
657
- var bufSize int
658
- for i := 0; i < l; i++ {
659
- bufSize += p.valSize(s.Index(i))
660
- }
661
-
662
- n += len(p.tagcode)
663
- n += sizeVarint(uint64(bufSize))
664
- n += bufSize
665
- return
666
-}
667
-
668
-// Encode a slice of slice of bytes ([][]byte).
669
-func (o *Buffer) enc_slice_slice_byte(p *Properties, base structPointer) error {
670
- ss := *structPointer_BytesSlice(base, p.field)
671
- l := len(ss)
672
- if l == 0 {
673
- return ErrNil
674
- }
675
- for i := 0; i < l; i++ {
676
- o.buf = append(o.buf, p.tagcode...)
677
- o.EncodeRawBytes(ss[i])
678
- }
679
- return nil
680
-}
681
-
682
-func size_slice_slice_byte(p *Properties, base structPointer) (n int) {
683
- ss := *structPointer_BytesSlice(base, p.field)
684
- l := len(ss)
685
- if l == 0 {
686
- return 0
687
- }
688
- n += l * len(p.tagcode)
689
- for i := 0; i < l; i++ {
690
- n += sizeRawBytes(ss[i])
691
- }
692
- return
693
-}
694
-
695
-// Encode a slice of strings ([]string).
696
-func (o *Buffer) enc_slice_string(p *Properties, base structPointer) error {
697
- ss := *structPointer_StringSlice(base, p.field)
698
- l := len(ss)
699
- for i := 0; i < l; i++ {
700
- o.buf = append(o.buf, p.tagcode...)
701
- o.EncodeStringBytes(ss[i])
702
- }
703
- return nil
704
-}
705
-
706
-func size_slice_string(p *Properties, base structPointer) (n int) {
707
- ss := *structPointer_StringSlice(base, p.field)
708
- l := len(ss)
709
- n += l * len(p.tagcode)
710
- for i := 0; i < l; i++ {
711
- n += sizeStringBytes(ss[i])
712
- }
713
- return
714
-}
715
-
716
-// Encode a slice of message structs ([]*struct).
717
-func (o *Buffer) enc_slice_struct_message(p *Properties, base structPointer) error {
718
- var state errorState
719
- s := structPointer_StructPointerSlice(base, p.field)
720
- l := s.Len()
721
-
722
- for i := 0; i < l; i++ {
723
- structp := s.Index(i)
724
- if structPointer_IsNil(structp) {
725
- return ErrRepeatedHasNil
726
- }
727
-
728
- // Can the object marshal itself?
729
- if p.isMarshaler {
730
- m := structPointer_Interface(structp, p.stype).(Marshaler)
731
- data, err := m.Marshal()
732
- if err != nil && !state.shouldContinue(err, nil) {
733
- return err
734
- }
735
- o.buf = append(o.buf, p.tagcode...)
736
- o.EncodeRawBytes(data)
737
- continue
738
- }
739
-
740
- o.buf = append(o.buf, p.tagcode...)
741
- err := o.enc_len_struct(p.stype, p.sprop, structp, &state)
742
- if err != nil && !state.shouldContinue(err, nil) {
743
- if err == ErrNil {
744
- return ErrRepeatedHasNil
745
- }
746
- return err
747
- }
748
- }
749
- return state.err
750
-}
751
-
752
-func size_slice_struct_message(p *Properties, base structPointer) (n int) {
753
- s := structPointer_StructPointerSlice(base, p.field)
754
- l := s.Len()
755
- n += l * len(p.tagcode)
756
- for i := 0; i < l; i++ {
757
- structp := s.Index(i)
758
- if structPointer_IsNil(structp) {
759
- return // return the size up to this point
760
- }
761
-
762
- // Can the object marshal itself?
763
- if p.isMarshaler {
764
- m := structPointer_Interface(structp, p.stype).(Marshaler)
765
- data, _ := m.Marshal()
766
- n += len(p.tagcode)
767
- n += sizeRawBytes(data)
768
- continue
769
- }
770
-
771
- n0 := size_struct(p.stype, p.sprop, structp)
772
- n1 := sizeVarint(uint64(n0)) // size of encoded length
773
- n += n0 + n1
774
- }
775
- return
776
-}
777
-
778
-// Encode a slice of group structs ([]*struct).
779
-func (o *Buffer) enc_slice_struct_group(p *Properties, base structPointer) error {
780
- var state errorState
781
- s := structPointer_StructPointerSlice(base, p.field)
782
- l := s.Len()
783
-
784
- for i := 0; i < l; i++ {
785
- b := s.Index(i)
786
- if structPointer_IsNil(b) {
787
- return ErrRepeatedHasNil
788
- }
789
-
790
- o.EncodeVarint(uint64((p.Tag << 3) | WireStartGroup))
791
-
792
- err := o.enc_struct(p.stype, p.sprop, b)
793
-
794
- if err != nil && !state.shouldContinue(err, nil) {
795
- if err == ErrNil {
796
- return ErrRepeatedHasNil
797
- }
798
- return err
799
- }
800
-
801
- o.EncodeVarint(uint64((p.Tag << 3) | WireEndGroup))
802
- }
803
- return state.err
804
-}
805
-
806
-func size_slice_struct_group(p *Properties, base structPointer) (n int) {
807
- s := structPointer_StructPointerSlice(base, p.field)
808
- l := s.Len()
809
-
810
- n += l * sizeVarint(uint64((p.Tag<<3)|WireStartGroup))
811
- n += l * sizeVarint(uint64((p.Tag<<3)|WireEndGroup))
812
- for i := 0; i < l; i++ {
813
- b := s.Index(i)
814
- if structPointer_IsNil(b) {
815
- return // return size up to this point
816
- }
817
-
818
- n += size_struct(p.stype, p.sprop, b)
819
- }
820
- return
821
-}
822
-
823
-// Encode an extension map.
824
-func (o *Buffer) enc_map(p *Properties, base structPointer) error {
825
- v := *structPointer_ExtMap(base, p.field)
826
- if err := encodeExtensionMap(v); err != nil {
827
- return err
828
- }
829
- // Fast-path for common cases: zero or one extensions.
830
- if len(v) <= 1 {
831
- for _, e := range v {
832
- o.buf = append(o.buf, e.enc...)
833
- }
834
- return nil
835
- }
836
-
837
- // Sort keys to provide a deterministic encoding.
838
- keys := make([]int, 0, len(v))
839
- for k := range v {
840
- keys = append(keys, int(k))
841
- }
842
- sort.Ints(keys)
843
-
844
- for _, k := range keys {
845
- o.buf = append(o.buf, v[int32(k)].enc...)
846
- }
847
- return nil
848
-}
849
-
850
-func size_map(p *Properties, base structPointer) int {
851
- v := *structPointer_ExtMap(base, p.field)
852
- return sizeExtensionMap(v)
853
-}
854
-
855
-// Encode a struct.
856
-func (o *Buffer) enc_struct(t reflect.Type, prop *StructProperties, base structPointer) error {
857
- var state errorState
858
- // Encode fields in tag order so that decoders may use optimizations
859
- // that depend on the ordering.
860
- // http://code.google.com/apis/protocolbuffers/docs/encoding.html#order
861
- for _, i := range prop.order {
862
- p := prop.Prop[i]
863
- if p.enc != nil {
864
- err := p.enc(o, p, base)
865
- if err != nil {
866
- if err == ErrNil {
867
- if p.Required && state.err == nil {
868
- state.err = &RequiredNotSetError{p.Name}
869
- }
870
- } else if !state.shouldContinue(err, p) {
871
- return err
872
- }
873
- }
874
- }
875
- }
876
-
877
- // Add unrecognized fields at the end.
878
- if prop.unrecField.IsValid() {
879
- v := *structPointer_Bytes(base, prop.unrecField)
880
- if len(v) > 0 {
881
- o.buf = append(o.buf, v...)
882
- }
883
- }
884
-
885
- return state.err
886
-}
887
-
888
-func size_struct(t reflect.Type, prop *StructProperties, base structPointer) (n int) {
889
- for _, i := range prop.order {
890
- p := prop.Prop[i]
891
- if p.size != nil {
892
- n += p.size(p, base)
893
- }
894
- }
895
-
896
- // Add unrecognized fields at the end.
897
- if prop.unrecField.IsValid() {
898
- v := *structPointer_Bytes(base, prop.unrecField)
899
- n += len(v)
900
- }
901
-
902
- return
903
-}
904
-
905
-var zeroes [20]byte // longer than any conceivable sizeVarint
906
-
907
-// Encode a struct, preceded by its encoded length (as a varint).
908
-func (o *Buffer) enc_len_struct(t reflect.Type, prop *StructProperties, base structPointer, state *errorState) error {
909
- iLen := len(o.buf)
910
- o.buf = append(o.buf, 0, 0, 0, 0) // reserve four bytes for length
911
- iMsg := len(o.buf)
912
- err := o.enc_struct(t, prop, base)
913
- if err != nil && !state.shouldContinue(err, nil) {
914
- return err
915
- }
916
- lMsg := len(o.buf) - iMsg
917
- lLen := sizeVarint(uint64(lMsg))
918
- switch x := lLen - (iMsg - iLen); {
919
- case x > 0: // actual length is x bytes larger than the space we reserved
920
- // Move msg x bytes right.
921
- o.buf = append(o.buf, zeroes[:x]...)
922
- copy(o.buf[iMsg+x:], o.buf[iMsg:iMsg+lMsg])
923
- case x < 0: // actual length is x bytes smaller than the space we reserved
924
- // Move msg x bytes left.
925
- copy(o.buf[iMsg+x:], o.buf[iMsg:iMsg+lMsg])
926
- o.buf = o.buf[:len(o.buf)+x] // x is negative
927
- }
928
- // Encode the length in the reserved space.
929
- o.buf = o.buf[:iLen]
930
- o.EncodeVarint(uint64(lMsg))
931
- o.buf = o.buf[:len(o.buf)+lMsg]
932
- return state.err
933
-}
934
-
935
-// errorState maintains the first error that occurs and updates that error
936
-// with additional context.
937
-type errorState struct {
938
- err error
939
-}
940
-
941
-// shouldContinue reports whether encoding should continue upon encountering the
942
-// given error. If the error is RequiredNotSetError, shouldContinue returns true
943
-// and, if this is the first appearance of that error, remembers it for future
944
-// reporting.
945
-//
946
-// If prop is not nil, it may update any error with additional context about the
947
-// field with the error.
948
-func (s *errorState) shouldContinue(err error, prop *Properties) bool {
949
- // Ignore unset required fields.
950
- reqNotSet, ok := err.(*RequiredNotSetError)
951
- if !ok {
952
- return false
953
- }
954
- if s.err == nil {
955
- if prop != nil {
956
- err = &RequiredNotSetError{prop.Name + "." + reqNotSet.field}
957
- }
958
- s.err = err
959
- }
960
- return true
961
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/equal.go
deleted
-241
@@ -1,241 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2011 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-// Protocol buffer comparison.
33
-// TODO: MessageSet.
34
-
35
-package proto
36
-
37
-import (
38
- "bytes"
39
- "log"
40
- "reflect"
41
- "strings"
42
-)
43
-
44
-/*
45
-Equal returns true iff protocol buffers a and b are equal.
46
-The arguments must both be pointers to protocol buffer structs.
47
-
48
-Equality is defined in this way:
49
- - Two messages are equal iff they are the same type,
50
- corresponding fields are equal, unknown field sets
51
- are equal, and extensions sets are equal.
52
- - Two set scalar fields are equal iff their values are equal.
53
- If the fields are of a floating-point type, remember that
54
- NaN != x for all x, including NaN.
55
- - Two repeated fields are equal iff their lengths are the same,
56
- and their corresponding elements are equal (a "bytes" field,
57
- although represented by []byte, is not a repeated field)
58
- - Two unset fields are equal.
59
- - Two unknown field sets are equal if their current
60
- encoded state is equal. (TODO)
61
- - Two extension sets are equal iff they have corresponding
62
- elements that are pairwise equal.
63
- - Every other combination of things are not equal.
64
-
65
-The return value is undefined if a and b are not protocol buffers.
66
-*/
67
-func Equal(a, b Message) bool {
68
- if a == nil || b == nil {
69
- return a == b
70
- }
71
- v1, v2 := reflect.ValueOf(a), reflect.ValueOf(b)
72
- if v1.Type() != v2.Type() {
73
- return false
74
- }
75
- if v1.Kind() == reflect.Ptr {
76
- if v1.IsNil() {
77
- return v2.IsNil()
78
- }
79
- if v2.IsNil() {
80
- return false
81
- }
82
- v1, v2 = v1.Elem(), v2.Elem()
83
- }
84
- if v1.Kind() != reflect.Struct {
85
- return false
86
- }
87
- return equalStruct(v1, v2)
88
-}
89
-
90
-// v1 and v2 are known to have the same type.
91
-func equalStruct(v1, v2 reflect.Value) bool {
92
- for i := 0; i < v1.NumField(); i++ {
93
- f := v1.Type().Field(i)
94
- if strings.HasPrefix(f.Name, "XXX_") {
95
- continue
96
- }
97
- f1, f2 := v1.Field(i), v2.Field(i)
98
- if f.Type.Kind() == reflect.Ptr {
99
- if n1, n2 := f1.IsNil(), f2.IsNil(); n1 && n2 {
100
- // both unset
101
- continue
102
- } else if n1 != n2 {
103
- // set/unset mismatch
104
- return false
105
- }
106
- b1, ok := f1.Interface().(raw)
107
- if ok {
108
- b2 := f2.Interface().(raw)
109
- // RawMessage
110
- if !bytes.Equal(b1.Bytes(), b2.Bytes()) {
111
- return false
112
- }
113
- continue
114
- }
115
- f1, f2 = f1.Elem(), f2.Elem()
116
- }
117
- if !equalAny(f1, f2) {
118
- return false
119
- }
120
- }
121
-
122
- if em1 := v1.FieldByName("XXX_extensions"); em1.IsValid() {
123
- em2 := v2.FieldByName("XXX_extensions")
124
- if !equalExtensions(v1.Type(), em1.Interface().(map[int32]Extension), em2.Interface().(map[int32]Extension)) {
125
- return false
126
- }
127
- }
128
-
129
- uf := v1.FieldByName("XXX_unrecognized")
130
- if !uf.IsValid() {
131
- return true
132
- }
133
-
134
- u1 := uf.Bytes()
135
- u2 := v2.FieldByName("XXX_unrecognized").Bytes()
136
- if !bytes.Equal(u1, u2) {
137
- return false
138
- }
139
-
140
- return true
141
-}
142
-
143
-// v1 and v2 are known to have the same type.
144
-func equalAny(v1, v2 reflect.Value) bool {
145
- if v1.Type() == protoMessageType {
146
- m1, _ := v1.Interface().(Message)
147
- m2, _ := v2.Interface().(Message)
148
- return Equal(m1, m2)
149
- }
150
- switch v1.Kind() {
151
- case reflect.Bool:
152
- return v1.Bool() == v2.Bool()
153
- case reflect.Float32, reflect.Float64:
154
- return v1.Float() == v2.Float()
155
- case reflect.Int32, reflect.Int64:
156
- return v1.Int() == v2.Int()
157
- case reflect.Ptr:
158
- return equalAny(v1.Elem(), v2.Elem())
159
- case reflect.Slice:
160
- if v1.Type().Elem().Kind() == reflect.Uint8 {
161
- // short circuit: []byte
162
- if v1.IsNil() != v2.IsNil() {
163
- return false
164
- }
165
- return bytes.Equal(v1.Interface().([]byte), v2.Interface().([]byte))
166
- }
167
-
168
- if v1.Len() != v2.Len() {
169
- return false
170
- }
171
- for i := 0; i < v1.Len(); i++ {
172
- if !equalAny(v1.Index(i), v2.Index(i)) {
173
- return false
174
- }
175
- }
176
- return true
177
- case reflect.String:
178
- return v1.Interface().(string) == v2.Interface().(string)
179
- case reflect.Struct:
180
- return equalStruct(v1, v2)
181
- case reflect.Uint32, reflect.Uint64:
182
- return v1.Uint() == v2.Uint()
183
- }
184
-
185
- // unknown type, so not a protocol buffer
186
- log.Printf("proto: don't know how to compare %v", v1)
187
- return false
188
-}
189
-
190
-// base is the struct type that the extensions are based on.
191
-// em1 and em2 are extension maps.
192
-func equalExtensions(base reflect.Type, em1, em2 map[int32]Extension) bool {
193
- if len(em1) != len(em2) {
194
- return false
195
- }
196
-
197
- for extNum, e1 := range em1 {
198
- e2, ok := em2[extNum]
199
- if !ok {
200
- return false
201
- }
202
-
203
- m1, m2 := e1.value, e2.value
204
-
205
- if m1 != nil && m2 != nil {
206
- // Both are unencoded.
207
- if !equalAny(reflect.ValueOf(m1), reflect.ValueOf(m2)) {
208
- return false
209
- }
210
- continue
211
- }
212
-
213
- // At least one is encoded. To do a semantically correct comparison
214
- // we need to unmarshal them first.
215
- var desc *ExtensionDesc
216
- if m := extensionMaps[base]; m != nil {
217
- desc = m[extNum]
218
- }
219
- if desc == nil {
220
- log.Printf("proto: don't know how to compare extension %d of %v", extNum, base)
221
- continue
222
- }
223
- var err error
224
- if m1 == nil {
225
- m1, err = decodeExtension(e1.enc, desc)
226
- }
227
- if m2 == nil && err == nil {
228
- m2, err = decodeExtension(e2.enc, desc)
229
- }
230
- if err != nil {
231
- // The encoded form is invalid.
232
- log.Printf("proto: badly encoded extension %d of %v: %v", extNum, base, err)
233
- return false
234
- }
235
- if !equalAny(reflect.ValueOf(m1), reflect.ValueOf(m2)) {
236
- return false
237
- }
238
- }
239
-
240
- return true
241
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/equal_test.go
deleted
-166
@@ -1,166 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2011 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto_test
33
-
34
-import (
35
- "testing"
36
-
37
- pb "./testdata"
38
- . "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
39
-)
40
-
41
-// Four identical base messages.
42
-// The init function adds extensions to some of them.
43
-var messageWithoutExtension = &pb.MyMessage{Count: Int32(7)}
44
-var messageWithExtension1a = &pb.MyMessage{Count: Int32(7)}
45
-var messageWithExtension1b = &pb.MyMessage{Count: Int32(7)}
46
-var messageWithExtension2 = &pb.MyMessage{Count: Int32(7)}
47
-
48
-// Two messages with non-message extensions.
49
-var messageWithInt32Extension1 = &pb.MyMessage{Count: Int32(8)}
50
-var messageWithInt32Extension2 = &pb.MyMessage{Count: Int32(8)}
51
-
52
-func init() {
53
- ext1 := &pb.Ext{Data: String("Kirk")}
54
- ext2 := &pb.Ext{Data: String("Picard")}
55
-
56
- // messageWithExtension1a has ext1, but never marshals it.
57
- if err := SetExtension(messageWithExtension1a, pb.E_Ext_More, ext1); err != nil {
58
- panic("SetExtension on 1a failed: " + err.Error())
59
- }
60
-
61
- // messageWithExtension1b is the unmarshaled form of messageWithExtension1a.
62
- if err := SetExtension(messageWithExtension1b, pb.E_Ext_More, ext1); err != nil {
63
- panic("SetExtension on 1b failed: " + err.Error())
64
- }
65
- buf, err := Marshal(messageWithExtension1b)
66
- if err != nil {
67
- panic("Marshal of 1b failed: " + err.Error())
68
- }
69
- messageWithExtension1b.Reset()
70
- if err := Unmarshal(buf, messageWithExtension1b); err != nil {
71
- panic("Unmarshal of 1b failed: " + err.Error())
72
- }
73
-
74
- // messageWithExtension2 has ext2.
75
- if err := SetExtension(messageWithExtension2, pb.E_Ext_More, ext2); err != nil {
76
- panic("SetExtension on 2 failed: " + err.Error())
77
- }
78
-
79
- if err := SetExtension(messageWithInt32Extension1, pb.E_Ext_Number, Int32(23)); err != nil {
80
- panic("SetExtension on Int32-1 failed: " + err.Error())
81
- }
82
- if err := SetExtension(messageWithInt32Extension1, pb.E_Ext_Number, Int32(24)); err != nil {
83
- panic("SetExtension on Int32-2 failed: " + err.Error())
84
- }
85
-}
86
-
87
-var EqualTests = []struct {
88
- desc string
89
- a, b Message
90
- exp bool
91
-}{
92
- {"different types", &pb.GoEnum{}, &pb.GoTestField{}, false},
93
- {"equal empty", &pb.GoEnum{}, &pb.GoEnum{}, true},
94
- {"nil vs nil", nil, nil, true},
95
- {"typed nil vs typed nil", (*pb.GoEnum)(nil), (*pb.GoEnum)(nil), true},
96
- {"typed nil vs empty", (*pb.GoEnum)(nil), &pb.GoEnum{}, false},
97
- {"different typed nil", (*pb.GoEnum)(nil), (*pb.GoTestField)(nil), false},
98
-
99
- {"one set field, one unset field", &pb.GoTestField{Label: String("foo")}, &pb.GoTestField{}, false},
100
- {"one set field zero, one unset field", &pb.GoTest{Param: Int32(0)}, &pb.GoTest{}, false},
101
- {"different set fields", &pb.GoTestField{Label: String("foo")}, &pb.GoTestField{Label: String("bar")}, false},
102
- {"equal set", &pb.GoTestField{Label: String("foo")}, &pb.GoTestField{Label: String("foo")}, true},
103
-
104
- {"repeated, one set", &pb.GoTest{F_Int32Repeated: []int32{2, 3}}, &pb.GoTest{}, false},
105
- {"repeated, different length", &pb.GoTest{F_Int32Repeated: []int32{2, 3}}, &pb.GoTest{F_Int32Repeated: []int32{2}}, false},
106
- {"repeated, different value", &pb.GoTest{F_Int32Repeated: []int32{2}}, &pb.GoTest{F_Int32Repeated: []int32{3}}, false},
107
- {"repeated, equal", &pb.GoTest{F_Int32Repeated: []int32{2, 4}}, &pb.GoTest{F_Int32Repeated: []int32{2, 4}}, true},
108
- {"repeated, nil equal nil", &pb.GoTest{F_Int32Repeated: nil}, &pb.GoTest{F_Int32Repeated: nil}, true},
109
- {"repeated, nil equal empty", &pb.GoTest{F_Int32Repeated: nil}, &pb.GoTest{F_Int32Repeated: []int32{}}, true},
110
- {"repeated, empty equal nil", &pb.GoTest{F_Int32Repeated: []int32{}}, &pb.GoTest{F_Int32Repeated: nil}, true},
111
-
112
- {
113
- "nested, different",
114
- &pb.GoTest{RequiredField: &pb.GoTestField{Label: String("foo")}},
115
- &pb.GoTest{RequiredField: &pb.GoTestField{Label: String("bar")}},
116
- false,
117
- },
118
- {
119
- "nested, equal",
120
- &pb.GoTest{RequiredField: &pb.GoTestField{Label: String("wow")}},
121
- &pb.GoTest{RequiredField: &pb.GoTestField{Label: String("wow")}},
122
- true,
123
- },
124
-
125
- {"bytes", &pb.OtherMessage{Value: []byte("foo")}, &pb.OtherMessage{Value: []byte("foo")}, true},
126
- {"bytes, empty", &pb.OtherMessage{Value: []byte{}}, &pb.OtherMessage{Value: []byte{}}, true},
127
- {"bytes, empty vs nil", &pb.OtherMessage{Value: []byte{}}, &pb.OtherMessage{Value: nil}, false},
128
- {
129
- "repeated bytes",
130
- &pb.MyMessage{RepBytes: [][]byte{[]byte("sham"), []byte("wow")}},
131
- &pb.MyMessage{RepBytes: [][]byte{[]byte("sham"), []byte("wow")}},
132
- true,
133
- },
134
-
135
- {"extension vs. no extension", messageWithoutExtension, messageWithExtension1a, false},
136
- {"extension vs. same extension", messageWithExtension1a, messageWithExtension1b, true},
137
- {"extension vs. different extension", messageWithExtension1a, messageWithExtension2, false},
138
-
139
- {"int32 extension vs. itself", messageWithInt32Extension1, messageWithInt32Extension1, true},
140
- {"int32 extension vs. a different int32", messageWithInt32Extension1, messageWithInt32Extension2, false},
141
-
142
- {
143
- "message with group",
144
- &pb.MyMessage{
145
- Count: Int32(1),
146
- Somegroup: &pb.MyMessage_SomeGroup{
147
- GroupField: Int32(5),
148
- },
149
- },
150
- &pb.MyMessage{
151
- Count: Int32(1),
152
- Somegroup: &pb.MyMessage_SomeGroup{
153
- GroupField: Int32(5),
154
- },
155
- },
156
- true,
157
- },
158
-}
159
-
160
-func TestEqual(t *testing.T) {
161
- for _, tc := range EqualTests {
162
- if res := Equal(tc.a, tc.b); res != tc.exp {
163
- t.Errorf("%v: Equal(%v, %v) = %v, want %v", tc.desc, tc.a, tc.b, res, tc.exp)
164
- }
165
- }
166
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/extensions_test.go
deleted
-60
@@ -1,60 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2014 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto_test
33
-
34
-import (
35
- "testing"
36
-
37
- pb "./testdata"
38
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
39
-)
40
-
41
-func TestGetExtensionsWithMissingExtensions(t *testing.T) {
42
- msg := &pb.MyMessage{}
43
- ext1 := &pb.Ext{}
44
- if err := proto.SetExtension(msg, pb.E_Ext_More, ext1); err != nil {
45
- t.Fatalf("Could not set ext1: %s", ext1)
46
- }
47
- exts, err := proto.GetExtensions(msg, []*proto.ExtensionDesc{
48
- pb.E_Ext_More,
49
- pb.E_Ext_Text,
50
- })
51
- if err != nil {
52
- t.Fatalf("GetExtensions() failed: %s", err)
53
- }
54
- if exts[0] != ext1 {
55
- t.Errorf("ext1 not in returned extensions: %T %v", exts[0], exts[0])
56
- }
57
- if exts[1] != nil {
58
- t.Errorf("ext2 in returned extensions: %T %v", exts[1], exts[1])
59
- }
60
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/lib.go
deleted
-740
@@ -1,740 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-/*
33
- Package proto converts data structures to and from the wire format of
34
- protocol buffers. It works in concert with the Go source code generated
35
- for .proto files by the protocol compiler.
36
-
37
- A summary of the properties of the protocol buffer interface
38
- for a protocol buffer variable v:
39
-
40
- - Names are turned from camel_case to CamelCase for export.
41
- - There are no methods on v to set fields; just treat
42
- them as structure fields.
43
- - There are getters that return a field's value if set,
44
- and return the field's default value if unset.
45
- The getters work even if the receiver is a nil message.
46
- - The zero value for a struct is its correct initialization state.
47
- All desired fields must be set before marshaling.
48
- - A Reset() method will restore a protobuf struct to its zero state.
49
- - Non-repeated fields are pointers to the values; nil means unset.
50
- That is, optional or required field int32 f becomes F *int32.
51
- - Repeated fields are slices.
52
- - Helper functions are available to aid the setting of fields.
53
- Helpers for getting values are superseded by the
54
- GetFoo methods and their use is deprecated.
55
- msg.Foo = proto.String("hello") // set field
56
- - Constants are defined to hold the default values of all fields that
57
- have them. They have the form Default_StructName_FieldName.
58
- Because the getter methods handle defaulted values,
59
- direct use of these constants should be rare.
60
- - Enums are given type names and maps from names to values.
61
- Enum values are prefixed with the enum's type name. Enum types have
62
- a String method, and a Enum method to assist in message construction.
63
- - Nested groups and enums have type names prefixed with the name of
64
- the surrounding message type.
65
- - Extensions are given descriptor names that start with E_,
66
- followed by an underscore-delimited list of the nested messages
67
- that contain it (if any) followed by the CamelCased name of the
68
- extension field itself. HasExtension, ClearExtension, GetExtension
69
- and SetExtension are functions for manipulating extensions.
70
- - Marshal and Unmarshal are functions to encode and decode the wire format.
71
-
72
- The simplest way to describe this is to see an example.
73
- Given file test.proto, containing
74
-
75
- package example;
76
-
77
- enum FOO { X = 17; };
78
-
79
- message Test {
80
- required string label = 1;
81
- optional int32 type = 2 [default=77];
82
- repeated int64 reps = 3;
83
- optional group OptionalGroup = 4 {
84
- required string RequiredField = 5;
85
- }
86
- }
87
-
88
- The resulting file, test.pb.go, is:
89
-
90
- package example
91
-
92
- import "code.google.com/p/gogoprotobuf/proto"
93
-
94
- type FOO int32
95
- const (
96
- FOO_X FOO = 17
97
- )
98
- var FOO_name = map[int32]string{
99
- 17: "X",
100
- }
101
- var FOO_value = map[string]int32{
102
- "X": 17,
103
- }
104
-
105
- func (x FOO) Enum() *FOO {
106
- p := new(FOO)
107
- *p = x
108
- return p
109
- }
110
- func (x FOO) String() string {
111
- return proto.EnumName(FOO_name, int32(x))
112
- }
113
-
114
- type Test struct {
115
- Label *string `protobuf:"bytes,1,req,name=label" json:"label,omitempty"`
116
- Type *int32 `protobuf:"varint,2,opt,name=type,def=77" json:"type,omitempty"`
117
- Reps []int64 `protobuf:"varint,3,rep,name=reps" json:"reps,omitempty"`
118
- Optionalgroup *Test_OptionalGroup `protobuf:"group,4,opt,name=OptionalGroup" json:"optionalgroup,omitempty"`
119
- XXX_unrecognized []byte `json:"-"`
120
- }
121
- func (this *Test) Reset() { *this = Test{} }
122
- func (this *Test) String() string { return proto.CompactTextString(this) }
123
- const Default_Test_Type int32 = 77
124
-
125
- func (this *Test) GetLabel() string {
126
- if this != nil && this.Label != nil {
127
- return *this.Label
128
- }
129
- return ""
130
- }
131
-
132
- func (this *Test) GetType() int32 {
133
- if this != nil && this.Type != nil {
134
- return *this.Type
135
- }
136
- return Default_Test_Type
137
- }
138
-
139
- func (this *Test) GetOptionalgroup() *Test_OptionalGroup {
140
- if this != nil {
141
- return this.Optionalgroup
142
- }
143
- return nil
144
- }
145
-
146
- type Test_OptionalGroup struct {
147
- RequiredField *string `protobuf:"bytes,5,req" json:"RequiredField,omitempty"`
148
- XXX_unrecognized []byte `json:"-"`
149
- }
150
- func (this *Test_OptionalGroup) Reset() { *this = Test_OptionalGroup{} }
151
- func (this *Test_OptionalGroup) String() string { return proto.CompactTextString(this) }
152
-
153
- func (this *Test_OptionalGroup) GetRequiredField() string {
154
- if this != nil && this.RequiredField != nil {
155
- return *this.RequiredField
156
- }
157
- return ""
158
- }
159
-
160
- func init() {
161
- proto.RegisterEnum("example.FOO", FOO_name, FOO_value)
162
- }
163
-
164
- To create and play with a Test object:
165
-
166
- package main
167
-
168
- import (
169
- "log"
170
-
171
- "code.google.com/p/gogoprotobuf/proto"
172
- "./example.pb"
173
- )
174
-
175
- func main() {
176
- test := &example.Test{
177
- Label: proto.String("hello"),
178
- Type: proto.Int32(17),
179
- Optionalgroup: &example.Test_OptionalGroup{
180
- RequiredField: proto.String("good bye"),
181
- },
182
- }
183
- data, err := proto.Marshal(test)
184
- if err != nil {
185
- log.Fatal("marshaling error: ", err)
186
- }
187
- newTest := new(example.Test)
188
- err = proto.Unmarshal(data, newTest)
189
- if err != nil {
190
- log.Fatal("unmarshaling error: ", err)
191
- }
192
- // Now test and newTest contain the same data.
193
- if test.GetLabel() != newTest.GetLabel() {
194
- log.Fatalf("data mismatch %q != %q", test.GetLabel(), newTest.GetLabel())
195
- }
196
- // etc.
197
- }
198
-*/
199
-package proto
200
-
201
-import (
202
- "encoding/json"
203
- "fmt"
204
- "log"
205
- "reflect"
206
- "strconv"
207
- "sync"
208
-)
209
-
210
-// Message is implemented by generated protocol buffer messages.
211
-type Message interface {
212
- Reset()
213
- String() string
214
- ProtoMessage()
215
-}
216
-
217
-// Stats records allocation details about the protocol buffer encoders
218
-// and decoders. Useful for tuning the library itself.
219
-type Stats struct {
220
- Emalloc uint64 // mallocs in encode
221
- Dmalloc uint64 // mallocs in decode
222
- Encode uint64 // number of encodes
223
- Decode uint64 // number of decodes
224
- Chit uint64 // number of cache hits
225
- Cmiss uint64 // number of cache misses
226
- Size uint64 // number of sizes
227
-}
228
-
229
-// Set to true to enable stats collection.
230
-const collectStats = false
231
-
232
-var stats Stats
233
-
234
-// GetStats returns a copy of the global Stats structure.
235
-func GetStats() Stats { return stats }
236
-
237
-// A Buffer is a buffer manager for marshaling and unmarshaling
238
-// protocol buffers. It may be reused between invocations to
239
-// reduce memory usage. It is not necessary to use a Buffer;
240
-// the global functions Marshal and Unmarshal create a
241
-// temporary Buffer and are fine for most applications.
242
-type Buffer struct {
243
- buf []byte // encode/decode byte stream
244
- index int // write point
245
-
246
- // pools of basic types to amortize allocation.
247
- bools []bool
248
- uint32s []uint32
249
- uint64s []uint64
250
-
251
- // extra pools, only used with pointer_reflect.go
252
- int32s []int32
253
- int64s []int64
254
- float32s []float32
255
- float64s []float64
256
-}
257
-
258
-// NewBuffer allocates a new Buffer and initializes its internal data to
259
-// the contents of the argument slice.
260
-func NewBuffer(e []byte) *Buffer {
261
- return &Buffer{buf: e}
262
-}
263
-
264
-// Reset resets the Buffer, ready for marshaling a new protocol buffer.
265
-func (p *Buffer) Reset() {
266
- p.buf = p.buf[0:0] // for reading/writing
267
- p.index = 0 // for reading
268
-}
269
-
270
-// SetBuf replaces the internal buffer with the slice,
271
-// ready for unmarshaling the contents of the slice.
272
-func (p *Buffer) SetBuf(s []byte) {
273
- p.buf = s
274
- p.index = 0
275
-}
276
-
277
-// Bytes returns the contents of the Buffer.
278
-func (p *Buffer) Bytes() []byte { return p.buf }
279
-
280
-/*
281
- * Helper routines for simplifying the creation of optional fields of basic type.
282
- */
283
-
284
-// Bool is a helper routine that allocates a new bool value
285
-// to store v and returns a pointer to it.
286
-func Bool(v bool) *bool {
287
- return &v
288
-}
289
-
290
-// Int32 is a helper routine that allocates a new int32 value
291
-// to store v and returns a pointer to it.
292
-func Int32(v int32) *int32 {
293
- return &v
294
-}
295
-
296
-// Int is a helper routine that allocates a new int32 value
297
-// to store v and returns a pointer to it, but unlike Int32
298
-// its argument value is an int.
299
-func Int(v int) *int32 {
300
- p := new(int32)
301
- *p = int32(v)
302
- return p
303
-}
304
-
305
-// Int64 is a helper routine that allocates a new int64 value
306
-// to store v and returns a pointer to it.
307
-func Int64(v int64) *int64 {
308
- return &v
309
-}
310
-
311
-// Float32 is a helper routine that allocates a new float32 value
312
-// to store v and returns a pointer to it.
313
-func Float32(v float32) *float32 {
314
- return &v
315
-}
316
-
317
-// Float64 is a helper routine that allocates a new float64 value
318
-// to store v and returns a pointer to it.
319
-func Float64(v float64) *float64 {
320
- return &v
321
-}
322
-
323
-// Uint32 is a helper routine that allocates a new uint32 value
324
-// to store v and returns a pointer to it.
325
-func Uint32(v uint32) *uint32 {
326
- p := new(uint32)
327
- *p = v
328
- return p
329
-}
330
-
331
-// Uint64 is a helper routine that allocates a new uint64 value
332
-// to store v and returns a pointer to it.
333
-func Uint64(v uint64) *uint64 {
334
- return &v
335
-}
336
-
337
-// String is a helper routine that allocates a new string value
338
-// to store v and returns a pointer to it.
339
-func String(v string) *string {
340
- return &v
341
-}
342
-
343
-// EnumName is a helper function to simplify printing protocol buffer enums
344
-// by name. Given an enum map and a value, it returns a useful string.
345
-func EnumName(m map[int32]string, v int32) string {
346
- s, ok := m[v]
347
- if ok {
348
- return s
349
- }
350
- return strconv.Itoa(int(v))
351
-}
352
-
353
-// UnmarshalJSONEnum is a helper function to simplify recovering enum int values
354
-// from their JSON-encoded representation. Given a map from the enum's symbolic
355
-// names to its int values, and a byte buffer containing the JSON-encoded
356
-// value, it returns an int32 that can be cast to the enum type by the caller.
357
-//
358
-// The function can deal with both JSON representations, numeric and symbolic.
359
-func UnmarshalJSONEnum(m map[string]int32, data []byte, enumName string) (int32, error) {
360
- if data[0] == '"' {
361
- // New style: enums are strings.
362
- var repr string
363
- if err := json.Unmarshal(data, &repr); err != nil {
364
- return -1, err
365
- }
366
- val, ok := m[repr]
367
- if !ok {
368
- return 0, fmt.Errorf("unrecognized enum %s value %q", enumName, repr)
369
- }
370
- return val, nil
371
- }
372
- // Old style: enums are ints.
373
- var val int32
374
- if err := json.Unmarshal(data, &val); err != nil {
375
- return 0, fmt.Errorf("cannot unmarshal %#q into enum %s", data, enumName)
376
- }
377
- return val, nil
378
-}
379
-
380
-// DebugPrint dumps the encoded data in b in a debugging format with a header
381
-// including the string s. Used in testing but made available for general debugging.
382
-func (o *Buffer) DebugPrint(s string, b []byte) {
383
- var u uint64
384
-
385
- obuf := o.buf
386
- index := o.index
387
- o.buf = b
388
- o.index = 0
389
- depth := 0
390
-
391
- fmt.Printf("\n--- %s ---\n", s)
392
-
393
-out:
394
- for {
395
- for i := 0; i < depth; i++ {
396
- fmt.Print(" ")
397
- }
398
-
399
- index := o.index
400
- if index == len(o.buf) {
401
- break
402
- }
403
-
404
- op, err := o.DecodeVarint()
405
- if err != nil {
406
- fmt.Printf("%3d: fetching op err %v\n", index, err)
407
- break out
408
- }
409
- tag := op >> 3
410
- wire := op & 7
411
-
412
- switch wire {
413
- default:
414
- fmt.Printf("%3d: t=%3d unknown wire=%d\n",
415
- index, tag, wire)
416
- break out
417
-
418
- case WireBytes:
419
- var r []byte
420
-
421
- r, err = o.DecodeRawBytes(false)
422
- if err != nil {
423
- break out
424
- }
425
- fmt.Printf("%3d: t=%3d bytes [%d]", index, tag, len(r))
426
- if len(r) <= 6 {
427
- for i := 0; i < len(r); i++ {
428
- fmt.Printf(" %.2x", r[i])
429
- }
430
- } else {
431
- for i := 0; i < 3; i++ {
432
- fmt.Printf(" %.2x", r[i])
433
- }
434
- fmt.Printf(" ..")
435
- for i := len(r) - 3; i < len(r); i++ {
436
- fmt.Printf(" %.2x", r[i])
437
- }
438
- }
439
- fmt.Printf("\n")
440
-
441
- case WireFixed32:
442
- u, err = o.DecodeFixed32()
443
- if err != nil {
444
- fmt.Printf("%3d: t=%3d fix32 err %v\n", index, tag, err)
445
- break out
446
- }
447
- fmt.Printf("%3d: t=%3d fix32 %d\n", index, tag, u)
448
-
449
- case WireFixed64:
450
- u, err = o.DecodeFixed64()
451
- if err != nil {
452
- fmt.Printf("%3d: t=%3d fix64 err %v\n", index, tag, err)
453
- break out
454
- }
455
- fmt.Printf("%3d: t=%3d fix64 %d\n", index, tag, u)
456
- break
457
-
458
- case WireVarint:
459
- u, err = o.DecodeVarint()
460
- if err != nil {
461
- fmt.Printf("%3d: t=%3d varint err %v\n", index, tag, err)
462
- break out
463
- }
464
- fmt.Printf("%3d: t=%3d varint %d\n", index, tag, u)
465
-
466
- case WireStartGroup:
467
- if err != nil {
468
- fmt.Printf("%3d: t=%3d start err %v\n", index, tag, err)
469
- break out
470
- }
471
- fmt.Printf("%3d: t=%3d start\n", index, tag)
472
- depth++
473
-
474
- case WireEndGroup:
475
- depth--
476
- if err != nil {
477
- fmt.Printf("%3d: t=%3d end err %v\n", index, tag, err)
478
- break out
479
- }
480
- fmt.Printf("%3d: t=%3d end\n", index, tag)
481
- }
482
- }
483
-
484
- if depth != 0 {
485
- fmt.Printf("%3d: start-end not balanced %d\n", o.index, depth)
486
- }
487
- fmt.Printf("\n")
488
-
489
- o.buf = obuf
490
- o.index = index
491
-}
492
-
493
-// SetDefaults sets unset protocol buffer fields to their default values.
494
-// It only modifies fields that are both unset and have defined defaults.
495
-// It recursively sets default values in any non-nil sub-messages.
496
-func SetDefaults(pb Message) {
497
- setDefaults(reflect.ValueOf(pb), true, false)
498
-}
499
-
500
-// v is a pointer to a struct.
501
-func setDefaults(v reflect.Value, recur, zeros bool) {
502
- v = v.Elem()
503
-
504
- defaultMu.RLock()
505
- dm, ok := defaults[v.Type()]
506
- defaultMu.RUnlock()
507
- if !ok {
508
- dm = buildDefaultMessage(v.Type())
509
- defaultMu.Lock()
510
- defaults[v.Type()] = dm
511
- defaultMu.Unlock()
512
- }
513
-
514
- for _, sf := range dm.scalars {
515
- f := v.Field(sf.index)
516
- if !f.IsNil() {
517
- // field already set
518
- continue
519
- }
520
- dv := sf.value
521
- if dv == nil && !zeros {
522
- // no explicit default, and don't want to set zeros
523
- continue
524
- }
525
- fptr := f.Addr().Interface() // **T
526
- // TODO: Consider batching the allocations we do here.
527
- switch sf.kind {
528
- case reflect.Bool:
529
- b := new(bool)
530
- if dv != nil {
531
- *b = dv.(bool)
532
- }
533
- *(fptr.(**bool)) = b
534
- case reflect.Float32:
535
- f := new(float32)
536
- if dv != nil {
537
- *f = dv.(float32)
538
- }
539
- *(fptr.(**float32)) = f
540
- case reflect.Float64:
541
- f := new(float64)
542
- if dv != nil {
543
- *f = dv.(float64)
544
- }
545
- *(fptr.(**float64)) = f
546
- case reflect.Int32:
547
- // might be an enum
548
- if ft := f.Type(); ft != int32PtrType {
549
- // enum
550
- f.Set(reflect.New(ft.Elem()))
551
- if dv != nil {
552
- f.Elem().SetInt(int64(dv.(int32)))
553
- }
554
- } else {
555
- // int32 field
556
- i := new(int32)
557
- if dv != nil {
558
- *i = dv.(int32)
559
- }
560
- *(fptr.(**int32)) = i
561
- }
562
- case reflect.Int64:
563
- i := new(int64)
564
- if dv != nil {
565
- *i = dv.(int64)
566
- }
567
- *(fptr.(**int64)) = i
568
- case reflect.String:
569
- s := new(string)
570
- if dv != nil {
571
- *s = dv.(string)
572
- }
573
- *(fptr.(**string)) = s
574
- case reflect.Uint8:
575
- // exceptional case: []byte
576
- var b []byte
577
- if dv != nil {
578
- db := dv.([]byte)
579
- b = make([]byte, len(db))
580
- copy(b, db)
581
- } else {
582
- b = []byte{}
583
- }
584
- *(fptr.(*[]byte)) = b
585
- case reflect.Uint32:
586
- u := new(uint32)
587
- if dv != nil {
588
- *u = dv.(uint32)
589
- }
590
- *(fptr.(**uint32)) = u
591
- case reflect.Uint64:
592
- u := new(uint64)
593
- if dv != nil {
594
- *u = dv.(uint64)
595
- }
596
- *(fptr.(**uint64)) = u
597
- default:
598
- log.Printf("proto: can't set default for field %v (sf.kind=%v)", f, sf.kind)
599
- }
600
- }
601
-
602
- for _, ni := range dm.nested {
603
- f := v.Field(ni)
604
- if f.IsNil() {
605
- continue
606
- }
607
- // f is *T or []*T
608
- if f.Kind() == reflect.Ptr {
609
- setDefaults(f, recur, zeros)
610
- } else {
611
- for i := 0; i < f.Len(); i++ {
612
- e := f.Index(i)
613
- if e.IsNil() {
614
- continue
615
- }
616
- setDefaults(e, recur, zeros)
617
- }
618
- }
619
- }
620
-}
621
-
622
-var (
623
- // defaults maps a protocol buffer struct type to a slice of the fields,
624
- // with its scalar fields set to their proto-declared non-zero default values.
625
- defaultMu sync.RWMutex
626
- defaults = make(map[reflect.Type]defaultMessage)
627
-
628
- int32PtrType = reflect.TypeOf((*int32)(nil))
629
-)
630
-
631
-// defaultMessage represents information about the default values of a message.
632
-type defaultMessage struct {
633
- scalars []scalarField
634
- nested []int // struct field index of nested messages
635
-}
636
-
637
-type scalarField struct {
638
- index int // struct field index
639
- kind reflect.Kind // element type (the T in *T or []T)
640
- value interface{} // the proto-declared default value, or nil
641
-}
642
-
643
-func ptrToStruct(t reflect.Type) bool {
644
- return t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Struct
645
-}
646
-
647
-// t is a struct type.
648
-func buildDefaultMessage(t reflect.Type) (dm defaultMessage) {
649
- sprop := GetProperties(t)
650
- for _, prop := range sprop.Prop {
651
- fi, ok := sprop.decoderTags.get(prop.Tag)
652
- if !ok {
653
- // XXX_unrecognized
654
- continue
655
- }
656
- ft := t.Field(fi).Type
657
-
658
- // nested messages
659
- if ptrToStruct(ft) || (ft.Kind() == reflect.Slice && ptrToStruct(ft.Elem())) {
660
- dm.nested = append(dm.nested, fi)
661
- continue
662
- }
663
-
664
- sf := scalarField{
665
- index: fi,
666
- kind: ft.Elem().Kind(),
667
- }
668
-
669
- // scalar fields without defaults
670
- if prop.Default == "" {
671
- dm.scalars = append(dm.scalars, sf)
672
- continue
673
- }
674
-
675
- // a scalar field: either *T or []byte
676
- switch ft.Elem().Kind() {
677
- case reflect.Bool:
678
- x, err := strconv.ParseBool(prop.Default)
679
- if err != nil {
680
- log.Printf("proto: bad default bool %q: %v", prop.Default, err)
681
- continue
682
- }
683
- sf.value = x
684
- case reflect.Float32:
685
- x, err := strconv.ParseFloat(prop.Default, 32)
686
- if err != nil {
687
- log.Printf("proto: bad default float32 %q: %v", prop.Default, err)
688
- continue
689
- }
690
- sf.value = float32(x)
691
- case reflect.Float64:
692
- x, err := strconv.ParseFloat(prop.Default, 64)
693
- if err != nil {
694
- log.Printf("proto: bad default float64 %q: %v", prop.Default, err)
695
- continue
696
- }
697
- sf.value = x
698
- case reflect.Int32:
699
- x, err := strconv.ParseInt(prop.Default, 10, 32)
700
- if err != nil {
701
- log.Printf("proto: bad default int32 %q: %v", prop.Default, err)
702
- continue
703
- }
704
- sf.value = int32(x)
705
- case reflect.Int64:
706
- x, err := strconv.ParseInt(prop.Default, 10, 64)
707
- if err != nil {
708
- log.Printf("proto: bad default int64 %q: %v", prop.Default, err)
709
- continue
710
- }
711
- sf.value = x
712
- case reflect.String:
713
- sf.value = prop.Default
714
- case reflect.Uint8:
715
- // []byte (not *uint8)
716
- sf.value = []byte(prop.Default)
717
- case reflect.Uint32:
718
- x, err := strconv.ParseUint(prop.Default, 10, 32)
719
- if err != nil {
720
- log.Printf("proto: bad default uint32 %q: %v", prop.Default, err)
721
- continue
722
- }
723
- sf.value = uint32(x)
724
- case reflect.Uint64:
725
- x, err := strconv.ParseUint(prop.Default, 10, 64)
726
- if err != nil {
727
- log.Printf("proto: bad default uint64 %q: %v", prop.Default, err)
728
- continue
729
- }
730
- sf.value = x
731
- default:
732
- log.Printf("proto: unhandled def kind %v", ft.Elem().Kind())
733
- continue
734
- }
735
-
736
- dm.scalars = append(dm.scalars, sf)
737
- }
738
-
739
- return dm
740
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/message_set.go
deleted
-216
@@ -1,216 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto
33
-
34
-/*
35
- * Support for message sets.
36
- */
37
-
38
-import (
39
- "errors"
40
- "reflect"
41
- "sort"
42
-)
43
-
44
-// ErrNoMessageTypeId occurs when a protocol buffer does not have a message type ID.
45
-// A message type ID is required for storing a protocol buffer in a message set.
46
-var ErrNoMessageTypeId = errors.New("proto does not have a message type ID")
47
-
48
-// The first two types (_MessageSet_Item and MessageSet)
49
-// model what the protocol compiler produces for the following protocol message:
50
-// message MessageSet {
51
-// repeated group Item = 1 {
52
-// required int32 type_id = 2;
53
-// required string message = 3;
54
-// };
55
-// }
56
-// That is the MessageSet wire format. We can't use a proto to generate these
57
-// because that would introduce a circular dependency between it and this package.
58
-//
59
-// When a proto1 proto has a field that looks like:
60
-// optional message<MessageSet> info = 3;
61
-// the protocol compiler produces a field in the generated struct that looks like:
62
-// Info *_proto_.MessageSet `protobuf:"bytes,3,opt,name=info"`
63
-// The package is automatically inserted so there is no need for that proto file to
64
-// import this package.
65
-
66
-type _MessageSet_Item struct {
67
- TypeId *int32 `protobuf:"varint,2,req,name=type_id"`
68
- Message []byte `protobuf:"bytes,3,req,name=message"`
69
-}
70
-
71
-type MessageSet struct {
72
- Item []*_MessageSet_Item `protobuf:"group,1,rep"`
73
- XXX_unrecognized []byte
74
- // TODO: caching?
75
-}
76
-
77
-// Make sure MessageSet is a Message.
78
-var _ Message = (*MessageSet)(nil)
79
-
80
-// messageTypeIder is an interface satisfied by a protocol buffer type
81
-// that may be stored in a MessageSet.
82
-type messageTypeIder interface {
83
- MessageTypeId() int32
84
-}
85
-
86
-func (ms *MessageSet) find(pb Message) *_MessageSet_Item {
87
- mti, ok := pb.(messageTypeIder)
88
- if !ok {
89
- return nil
90
- }
91
- id := mti.MessageTypeId()
92
- for _, item := range ms.Item {
93
- if *item.TypeId == id {
94
- return item
95
- }
96
- }
97
- return nil
98
-}
99
-
100
-func (ms *MessageSet) Has(pb Message) bool {
101
- if ms.find(pb) != nil {
102
- return true
103
- }
104
- return false
105
-}
106
-
107
-func (ms *MessageSet) Unmarshal(pb Message) error {
108
- if item := ms.find(pb); item != nil {
109
- return Unmarshal(item.Message, pb)
110
- }
111
- if _, ok := pb.(messageTypeIder); !ok {
112
- return ErrNoMessageTypeId
113
- }
114
- return nil // TODO: return error instead?
115
-}
116
-
117
-func (ms *MessageSet) Marshal(pb Message) error {
118
- msg, err := Marshal(pb)
119
- if err != nil {
120
- return err
121
- }
122
- if item := ms.find(pb); item != nil {
123
- // reuse existing item
124
- item.Message = msg
125
- return nil
126
- }
127
-
128
- mti, ok := pb.(messageTypeIder)
129
- if !ok {
130
- return ErrNoMessageTypeId
131
- }
132
-
133
- mtid := mti.MessageTypeId()
134
- ms.Item = append(ms.Item, &_MessageSet_Item{
135
- TypeId: &mtid,
136
- Message: msg,
137
- })
138
- return nil
139
-}
140
-
141
-func (ms *MessageSet) Reset() { *ms = MessageSet{} }
142
-func (ms *MessageSet) String() string { return CompactTextString(ms) }
143
-func (*MessageSet) ProtoMessage() {}
144
-
145
-// Support for the message_set_wire_format message option.
146
-
147
-func skipVarint(buf []byte) []byte {
148
- i := 0
149
- for ; buf[i]&0x80 != 0; i++ {
150
- }
151
- return buf[i+1:]
152
-}
153
-
154
-// MarshalMessageSet encodes the extension map represented by m in the message set wire format.
155
-// It is called by generated Marshal methods on protocol buffer messages with the message_set_wire_format option.
156
-func MarshalMessageSet(m map[int32]Extension) ([]byte, error) {
157
- if err := encodeExtensionMap(m); err != nil {
158
- return nil, err
159
- }
160
-
161
- // Sort extension IDs to provide a deterministic encoding.
162
- // See also enc_map in encode.go.
163
- ids := make([]int, 0, len(m))
164
- for id := range m {
165
- ids = append(ids, int(id))
166
- }
167
- sort.Ints(ids)
168
-
169
- ms := &MessageSet{Item: make([]*_MessageSet_Item, 0, len(m))}
170
- for _, id := range ids {
171
- e := m[int32(id)]
172
- // Remove the wire type and field number varint, as well as the length varint.
173
- msg := skipVarint(skipVarint(e.enc))
174
-
175
- ms.Item = append(ms.Item, &_MessageSet_Item{
176
- TypeId: Int32(int32(id)),
177
- Message: msg,
178
- })
179
- }
180
- return Marshal(ms)
181
-}
182
-
183
-// UnmarshalMessageSet decodes the extension map encoded in buf in the message set wire format.
184
-// It is called by generated Unmarshal methods on protocol buffer messages with the message_set_wire_format option.
185
-func UnmarshalMessageSet(buf []byte, m map[int32]Extension) error {
186
- ms := new(MessageSet)
187
- if err := Unmarshal(buf, ms); err != nil {
188
- return err
189
- }
190
- for _, item := range ms.Item {
191
- // restore wire type and field number varint, plus length varint.
192
- b := EncodeVarint(uint64(*item.TypeId)<<3 | WireBytes)
193
- b = append(b, EncodeVarint(uint64(len(item.Message)))...)
194
- b = append(b, item.Message...)
195
-
196
- m[*item.TypeId] = Extension{enc: b}
197
- }
198
- return nil
199
-}
200
-
201
-// A global registry of types that can be used in a MessageSet.
202
-
203
-var messageSetMap = make(map[int32]messageSetDesc)
204
-
205
-type messageSetDesc struct {
206
- t reflect.Type // pointer to struct
207
- name string
208
-}
209
-
210
-// RegisterMessageSetType is called from the generated code.
211
-func RegisterMessageSetType(i messageTypeIder, name string) {
212
- messageSetMap[i.MessageTypeId()] = messageSetDesc{
213
- t: reflect.TypeOf(i),
214
- name: name,
215
- }
216
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/pointer_reflect.go
deleted
-384
@@ -1,384 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2012 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-// +build appengine,!appenginevm
33
-
34
-// This file contains an implementation of proto field accesses using package reflect.
35
-// It is slower than the code in pointer_unsafe.go but it avoids package unsafe and can
36
-// be used on App Engine.
37
-
38
-package proto
39
-
40
-import (
41
- "math"
42
- "reflect"
43
-)
44
-
45
-// A structPointer is a pointer to a struct.
46
-type structPointer struct {
47
- v reflect.Value
48
-}
49
-
50
-// toStructPointer returns a structPointer equivalent to the given reflect value.
51
-// The reflect value must itself be a pointer to a struct.
52
-func toStructPointer(v reflect.Value) structPointer {
53
- return structPointer{v}
54
-}
55
-
56
-// IsNil reports whether p is nil.
57
-func structPointer_IsNil(p structPointer) bool {
58
- return p.v.IsNil()
59
-}
60
-
61
-// Interface returns the struct pointer as an interface value.
62
-func structPointer_Interface(p structPointer, _ reflect.Type) interface{} {
63
- return p.v.Interface()
64
-}
65
-
66
-// A field identifies a field in a struct, accessible from a structPointer.
67
-// In this implementation, a field is identified by the sequence of field indices
68
-// passed to reflect's FieldByIndex.
69
-type field []int
70
-
71
-// toField returns a field equivalent to the given reflect field.
72
-func toField(f *reflect.StructField) field {
73
- return f.Index
74
-}
75
-
76
-// invalidField is an invalid field identifier.
77
-var invalidField = field(nil)
78
-
79
-// IsValid reports whether the field identifier is valid.
80
-func (f field) IsValid() bool { return f != nil }
81
-
82
-// field returns the given field in the struct as a reflect value.
83
-func structPointer_field(p structPointer, f field) reflect.Value {
84
- // Special case: an extension map entry with a value of type T
85
- // passes a *T to the struct-handling code with a zero field,
86
- // expecting that it will be treated as equivalent to *struct{ X T },
87
- // which has the same memory layout. We have to handle that case
88
- // specially, because reflect will panic if we call FieldByIndex on a
89
- // non-struct.
90
- if f == nil {
91
- return p.v.Elem()
92
- }
93
-
94
- return p.v.Elem().FieldByIndex(f)
95
-}
96
-
97
-// ifield returns the given field in the struct as an interface value.
98
-func structPointer_ifield(p structPointer, f field) interface{} {
99
- return structPointer_field(p, f).Addr().Interface()
100
-}
101
-
102
-// Bytes returns the address of a []byte field in the struct.
103
-func structPointer_Bytes(p structPointer, f field) *[]byte {
104
- return structPointer_ifield(p, f).(*[]byte)
105
-}
106
-
107
-// BytesSlice returns the address of a [][]byte field in the struct.
108
-func structPointer_BytesSlice(p structPointer, f field) *[][]byte {
109
- return structPointer_ifield(p, f).(*[][]byte)
110
-}
111
-
112
-// Bool returns the address of a *bool field in the struct.
113
-func structPointer_Bool(p structPointer, f field) **bool {
114
- return structPointer_ifield(p, f).(**bool)
115
-}
116
-
117
-// BoolSlice returns the address of a []bool field in the struct.
118
-func structPointer_BoolSlice(p structPointer, f field) *[]bool {
119
- return structPointer_ifield(p, f).(*[]bool)
120
-}
121
-
122
-// String returns the address of a *string field in the struct.
123
-func structPointer_String(p structPointer, f field) **string {
124
- return structPointer_ifield(p, f).(**string)
125
-}
126
-
127
-// StringSlice returns the address of a []string field in the struct.
128
-func structPointer_StringSlice(p structPointer, f field) *[]string {
129
- return structPointer_ifield(p, f).(*[]string)
130
-}
131
-
132
-// ExtMap returns the address of an extension map field in the struct.
133
-func structPointer_ExtMap(p structPointer, f field) *map[int32]Extension {
134
- return structPointer_ifield(p, f).(*map[int32]Extension)
135
-}
136
-
137
-// SetStructPointer writes a *struct field in the struct.
138
-func structPointer_SetStructPointer(p structPointer, f field, q structPointer) {
139
- structPointer_field(p, f).Set(q.v)
140
-}
141
-
142
-// GetStructPointer reads a *struct field in the struct.
143
-func structPointer_GetStructPointer(p structPointer, f field) structPointer {
144
- return structPointer{structPointer_field(p, f)}
145
-}
146
-
147
-// StructPointerSlice the address of a []*struct field in the struct.
148
-func structPointer_StructPointerSlice(p structPointer, f field) structPointerSlice {
149
- return structPointerSlice{structPointer_field(p, f)}
150
-}
151
-
152
-// A structPointerSlice represents the address of a slice of pointers to structs
153
-// (themselves messages or groups). That is, v.Type() is *[]*struct{...}.
154
-type structPointerSlice struct {
155
- v reflect.Value
156
-}
157
-
158
-func (p structPointerSlice) Len() int { return p.v.Len() }
159
-func (p structPointerSlice) Index(i int) structPointer { return structPointer{p.v.Index(i)} }
160
-func (p structPointerSlice) Append(q structPointer) {
161
- p.v.Set(reflect.Append(p.v, q.v))
162
-}
163
-
164
-var (
165
- int32Type = reflect.TypeOf(int32(0))
166
- uint32Type = reflect.TypeOf(uint32(0))
167
- float32Type = reflect.TypeOf(float32(0))
168
- int64Type = reflect.TypeOf(int64(0))
169
- uint64Type = reflect.TypeOf(uint64(0))
170
- float64Type = reflect.TypeOf(float64(0))
171
-)
172
-
173
-// A word32 represents a field of type *int32, *uint32, *float32, or *enum.
174
-// That is, v.Type() is *int32, *uint32, *float32, or *enum and v is assignable.
175
-type word32 struct {
176
- v reflect.Value
177
-}
178
-
179
-// IsNil reports whether p is nil.
180
-func word32_IsNil(p word32) bool {
181
- return p.v.IsNil()
182
-}
183
-
184
-// Set sets p to point at a newly allocated word with bits set to x.
185
-func word32_Set(p word32, o *Buffer, x uint32) {
186
- t := p.v.Type().Elem()
187
- switch t {
188
- case int32Type:
189
- if len(o.int32s) == 0 {
190
- o.int32s = make([]int32, uint32PoolSize)
191
- }
192
- o.int32s[0] = int32(x)
193
- p.v.Set(reflect.ValueOf(&o.int32s[0]))
194
- o.int32s = o.int32s[1:]
195
- return
196
- case uint32Type:
197
- if len(o.uint32s) == 0 {
198
- o.uint32s = make([]uint32, uint32PoolSize)
199
- }
200
- o.uint32s[0] = x
201
- p.v.Set(reflect.ValueOf(&o.uint32s[0]))
202
- o.uint32s = o.uint32s[1:]
203
- return
204
- case float32Type:
205
- if len(o.float32s) == 0 {
206
- o.float32s = make([]float32, uint32PoolSize)
207
- }
208
- o.float32s[0] = math.Float32frombits(x)
209
- p.v.Set(reflect.ValueOf(&o.float32s[0]))
210
- o.float32s = o.float32s[1:]
211
- return
212
- }
213
-
214
- // must be enum
215
- p.v.Set(reflect.New(t))
216
- p.v.Elem().SetInt(int64(int32(x)))
217
-}
218
-
219
-// Get gets the bits pointed at by p, as a uint32.
220
-func word32_Get(p word32) uint32 {
221
- elem := p.v.Elem()
222
- switch elem.Kind() {
223
- case reflect.Int32:
224
- return uint32(elem.Int())
225
- case reflect.Uint32:
226
- return uint32(elem.Uint())
227
- case reflect.Float32:
228
- return math.Float32bits(float32(elem.Float()))
229
- }
230
- panic("unreachable")
231
-}
232
-
233
-// Word32 returns a reference to a *int32, *uint32, *float32, or *enum field in the struct.
234
-func structPointer_Word32(p structPointer, f field) word32 {
235
- return word32{structPointer_field(p, f)}
236
-}
237
-
238
-// A word32Slice is a slice of 32-bit values.
239
-// That is, v.Type() is []int32, []uint32, []float32, or []enum.
240
-type word32Slice struct {
241
- v reflect.Value
242
-}
243
-
244
-func (p word32Slice) Append(x uint32) {
245
- n, m := p.v.Len(), p.v.Cap()
246
- if n < m {
247
- p.v.SetLen(n + 1)
248
- } else {
249
- t := p.v.Type().Elem()
250
- p.v.Set(reflect.Append(p.v, reflect.Zero(t)))
251
- }
252
- elem := p.v.Index(n)
253
- switch elem.Kind() {
254
- case reflect.Int32:
255
- elem.SetInt(int64(int32(x)))
256
- case reflect.Uint32:
257
- elem.SetUint(uint64(x))
258
- case reflect.Float32:
259
- elem.SetFloat(float64(math.Float32frombits(x)))
260
- }
261
-}
262
-
263
-func (p word32Slice) Len() int {
264
- return p.v.Len()
265
-}
266
-
267
-func (p word32Slice) Index(i int) uint32 {
268
- elem := p.v.Index(i)
269
- switch elem.Kind() {
270
- case reflect.Int32:
271
- return uint32(elem.Int())
272
- case reflect.Uint32:
273
- return uint32(elem.Uint())
274
- case reflect.Float32:
275
- return math.Float32bits(float32(elem.Float()))
276
- }
277
- panic("unreachable")
278
-}
279
-
280
-// Word32Slice returns a reference to a []int32, []uint32, []float32, or []enum field in the struct.
281
-func structPointer_Word32Slice(p structPointer, f field) word32Slice {
282
- return word32Slice{structPointer_field(p, f)}
283
-}
284
-
285
-// word64 is like word32 but for 64-bit values.
286
-type word64 struct {
287
- v reflect.Value
288
-}
289
-
290
-func word64_Set(p word64, o *Buffer, x uint64) {
291
- t := p.v.Type().Elem()
292
- switch t {
293
- case int64Type:
294
- if len(o.int64s) == 0 {
295
- o.int64s = make([]int64, uint64PoolSize)
296
- }
297
- o.int64s[0] = int64(x)
298
- p.v.Set(reflect.ValueOf(&o.int64s[0]))
299
- o.int64s = o.int64s[1:]
300
- return
301
- case uint64Type:
302
- if len(o.uint64s) == 0 {
303
- o.uint64s = make([]uint64, uint64PoolSize)
304
- }
305
- o.uint64s[0] = x
306
- p.v.Set(reflect.ValueOf(&o.uint64s[0]))
307
- o.uint64s = o.uint64s[1:]
308
- return
309
- case float64Type:
310
- if len(o.float64s) == 0 {
311
- o.float64s = make([]float64, uint64PoolSize)
312
- }
313
- o.float64s[0] = math.Float64frombits(x)
314
- p.v.Set(reflect.ValueOf(&o.float64s[0]))
315
- o.float64s = o.float64s[1:]
316
- return
317
- }
318
- panic("unreachable")
319
-}
320
-
321
-func word64_IsNil(p word64) bool {
322
- return p.v.IsNil()
323
-}
324
-
325
-func word64_Get(p word64) uint64 {
326
- elem := p.v.Elem()
327
- switch elem.Kind() {
328
- case reflect.Int64:
329
- return uint64(elem.Int())
330
- case reflect.Uint64:
331
- return elem.Uint()
332
- case reflect.Float64:
333
- return math.Float64bits(elem.Float())
334
- }
335
- panic("unreachable")
336
-}
337
-
338
-func structPointer_Word64(p structPointer, f field) word64 {
339
- return word64{structPointer_field(p, f)}
340
-}
341
-
342
-type word64Slice struct {
343
- v reflect.Value
344
-}
345
-
346
-func (p word64Slice) Append(x uint64) {
347
- n, m := p.v.Len(), p.v.Cap()
348
- if n < m {
349
- p.v.SetLen(n + 1)
350
- } else {
351
- t := p.v.Type().Elem()
352
- p.v.Set(reflect.Append(p.v, reflect.Zero(t)))
353
- }
354
- elem := p.v.Index(n)
355
- switch elem.Kind() {
356
- case reflect.Int64:
357
- elem.SetInt(int64(int64(x)))
358
- case reflect.Uint64:
359
- elem.SetUint(uint64(x))
360
- case reflect.Float64:
361
- elem.SetFloat(float64(math.Float64frombits(x)))
362
- }
363
-}
364
-
365
-func (p word64Slice) Len() int {
366
- return p.v.Len()
367
-}
368
-
369
-func (p word64Slice) Index(i int) uint64 {
370
- elem := p.v.Index(i)
371
- switch elem.Kind() {
372
- case reflect.Int64:
373
- return uint64(elem.Int())
374
- case reflect.Uint64:
375
- return uint64(elem.Uint())
376
- case reflect.Float64:
377
- return math.Float64bits(float64(elem.Float()))
378
- }
379
- panic("unreachable")
380
-}
381
-
382
-func structPointer_Word64Slice(p structPointer, f field) word64Slice {
383
- return word64Slice{structPointer_field(p, f)}
384
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/pointer_unsafe.go
deleted
-218
@@ -1,218 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2012 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-// +build !appengine appenginevm
33
-
34
-// This file contains the implementation of the proto field accesses using package unsafe.
35
-
36
-package proto
37
-
38
-import (
39
- "reflect"
40
- "unsafe"
41
-)
42
-
43
-// NOTE: These type_Foo functions would more idiomatically be methods,
44
-// but Go does not allow methods on pointer types, and we must preserve
45
-// some pointer type for the garbage collector. We use these
46
-// funcs with clunky names as our poor approximation to methods.
47
-//
48
-// An alternative would be
49
-// type structPointer struct { p unsafe.Pointer }
50
-// but that does not registerize as well.
51
-
52
-// A structPointer is a pointer to a struct.
53
-type structPointer unsafe.Pointer
54
-
55
-// toStructPointer returns a structPointer equivalent to the given reflect value.
56
-func toStructPointer(v reflect.Value) structPointer {
57
- return structPointer(unsafe.Pointer(v.Pointer()))
58
-}
59
-
60
-// IsNil reports whether p is nil.
61
-func structPointer_IsNil(p structPointer) bool {
62
- return p == nil
63
-}
64
-
65
-// Interface returns the struct pointer, assumed to have element type t,
66
-// as an interface value.
67
-func structPointer_Interface(p structPointer, t reflect.Type) interface{} {
68
- return reflect.NewAt(t, unsafe.Pointer(p)).Interface()
69
-}
70
-
71
-// A field identifies a field in a struct, accessible from a structPointer.
72
-// In this implementation, a field is identified by its byte offset from the start of the struct.
73
-type field uintptr
74
-
75
-// toField returns a field equivalent to the given reflect field.
76
-func toField(f *reflect.StructField) field {
77
- return field(f.Offset)
78
-}
79
-
80
-// invalidField is an invalid field identifier.
81
-const invalidField = ^field(0)
82
-
83
-// IsValid reports whether the field identifier is valid.
84
-func (f field) IsValid() bool {
85
- return f != ^field(0)
86
-}
87
-
88
-// Bytes returns the address of a []byte field in the struct.
89
-func structPointer_Bytes(p structPointer, f field) *[]byte {
90
- return (*[]byte)(unsafe.Pointer(uintptr(p) + uintptr(f)))
91
-}
92
-
93
-// BytesSlice returns the address of a [][]byte field in the struct.
94
-func structPointer_BytesSlice(p structPointer, f field) *[][]byte {
95
- return (*[][]byte)(unsafe.Pointer(uintptr(p) + uintptr(f)))
96
-}
97
-
98
-// Bool returns the address of a *bool field in the struct.
99
-func structPointer_Bool(p structPointer, f field) **bool {
100
- return (**bool)(unsafe.Pointer(uintptr(p) + uintptr(f)))
101
-}
102
-
103
-// BoolSlice returns the address of a []bool field in the struct.
104
-func structPointer_BoolSlice(p structPointer, f field) *[]bool {
105
- return (*[]bool)(unsafe.Pointer(uintptr(p) + uintptr(f)))
106
-}
107
-
108
-// String returns the address of a *string field in the struct.
109
-func structPointer_String(p structPointer, f field) **string {
110
- return (**string)(unsafe.Pointer(uintptr(p) + uintptr(f)))
111
-}
112
-
113
-// StringSlice returns the address of a []string field in the struct.
114
-func structPointer_StringSlice(p structPointer, f field) *[]string {
115
- return (*[]string)(unsafe.Pointer(uintptr(p) + uintptr(f)))
116
-}
117
-
118
-// ExtMap returns the address of an extension map field in the struct.
119
-func structPointer_ExtMap(p structPointer, f field) *map[int32]Extension {
120
- return (*map[int32]Extension)(unsafe.Pointer(uintptr(p) + uintptr(f)))
121
-}
122
-
123
-// SetStructPointer writes a *struct field in the struct.
124
-func structPointer_SetStructPointer(p structPointer, f field, q structPointer) {
125
- *(*structPointer)(unsafe.Pointer(uintptr(p) + uintptr(f))) = q
126
-}
127
-
128
-// GetStructPointer reads a *struct field in the struct.
129
-func structPointer_GetStructPointer(p structPointer, f field) structPointer {
130
- return *(*structPointer)(unsafe.Pointer(uintptr(p) + uintptr(f)))
131
-}
132
-
133
-// StructPointerSlice the address of a []*struct field in the struct.
134
-func structPointer_StructPointerSlice(p structPointer, f field) *structPointerSlice {
135
- return (*structPointerSlice)(unsafe.Pointer(uintptr(p) + uintptr(f)))
136
-}
137
-
138
-// A structPointerSlice represents a slice of pointers to structs (themselves submessages or groups).
139
-type structPointerSlice []structPointer
140
-
141
-func (v *structPointerSlice) Len() int { return len(*v) }
142
-func (v *structPointerSlice) Index(i int) structPointer { return (*v)[i] }
143
-func (v *structPointerSlice) Append(p structPointer) { *v = append(*v, p) }
144
-
145
-// A word32 is the address of a "pointer to 32-bit value" field.
146
-type word32 **uint32
147
-
148
-// IsNil reports whether *v is nil.
149
-func word32_IsNil(p word32) bool {
150
- return *p == nil
151
-}
152
-
153
-// Set sets *v to point at a newly allocated word set to x.
154
-func word32_Set(p word32, o *Buffer, x uint32) {
155
- if len(o.uint32s) == 0 {
156
- o.uint32s = make([]uint32, uint32PoolSize)
157
- }
158
- o.uint32s[0] = x
159
- *p = &o.uint32s[0]
160
- o.uint32s = o.uint32s[1:]
161
-}
162
-
163
-// Get gets the value pointed at by *v.
164
-func word32_Get(p word32) uint32 {
165
- return **p
166
-}
167
-
168
-// Word32 returns the address of a *int32, *uint32, *float32, or *enum field in the struct.
169
-func structPointer_Word32(p structPointer, f field) word32 {
170
- return word32((**uint32)(unsafe.Pointer(uintptr(p) + uintptr(f))))
171
-}
172
-
173
-// A word32Slice is a slice of 32-bit values.
174
-type word32Slice []uint32
175
-
176
-func (v *word32Slice) Append(x uint32) { *v = append(*v, x) }
177
-func (v *word32Slice) Len() int { return len(*v) }
178
-func (v *word32Slice) Index(i int) uint32 { return (*v)[i] }
179
-
180
-// Word32Slice returns the address of a []int32, []uint32, []float32, or []enum field in the struct.
181
-func structPointer_Word32Slice(p structPointer, f field) *word32Slice {
182
- return (*word32Slice)(unsafe.Pointer(uintptr(p) + uintptr(f)))
183
-}
184
-
185
-// word64 is like word32 but for 64-bit values.
186
-type word64 **uint64
187
-
188
-func word64_Set(p word64, o *Buffer, x uint64) {
189
- if len(o.uint64s) == 0 {
190
- o.uint64s = make([]uint64, uint64PoolSize)
191
- }
192
- o.uint64s[0] = x
193
- *p = &o.uint64s[0]
194
- o.uint64s = o.uint64s[1:]
195
-}
196
-
197
-func word64_IsNil(p word64) bool {
198
- return *p == nil
199
-}
200
-
201
-func word64_Get(p word64) uint64 {
202
- return **p
203
-}
204
-
205
-func structPointer_Word64(p structPointer, f field) word64 {
206
- return word64((**uint64)(unsafe.Pointer(uintptr(p) + uintptr(f))))
207
-}
208
-
209
-// word64Slice is like word32Slice but for 64-bit values.
210
-type word64Slice []uint64
211
-
212
-func (v *word64Slice) Append(x uint64) { *v = append(*v, x) }
213
-func (v *word64Slice) Len() int { return len(*v) }
214
-func (v *word64Slice) Index(i int) uint64 { return (*v)[i] }
215
-
216
-func structPointer_Word64Slice(p structPointer, f field) *word64Slice {
217
- return (*word64Slice)(unsafe.Pointer(uintptr(p) + uintptr(f)))
218
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/properties.go
deleted
-670
@@ -1,670 +0,0 @@
1
-// Extensions for Protocol Buffers to create more go like structures.
2
-//
3
-// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
4
-// http://code.google.com/p/gogoprotobuf/gogoproto
5
-//
6
-// Go support for Protocol Buffers - Google's data interchange format
7
-//
8
-// Copyright 2010 The Go Authors. All rights reserved.
9
-// http://code.google.com/p/goprotobuf/
10
-//
11
-// Redistribution and use in source and binary forms, with or without
12
-// modification, are permitted provided that the following conditions are
13
-// met:
14
-//
15
-// * Redistributions of source code must retain the above copyright
16
-// notice, this list of conditions and the following disclaimer.
17
-// * Redistributions in binary form must reproduce the above
18
-// copyright notice, this list of conditions and the following disclaimer
19
-// in the documentation and/or other materials provided with the
20
-// distribution.
21
-// * Neither the name of Google Inc. nor the names of its
22
-// contributors may be used to endorse or promote products derived from
23
-// this software without specific prior written permission.
24
-//
25
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
-
37
-package proto
38
-
39
-/*
40
- * Routines for encoding data into the wire format for protocol buffers.
41
- */
42
-
43
-import (
44
- "fmt"
45
- "os"
46
- "reflect"
47
- "sort"
48
- "strconv"
49
- "strings"
50
- "sync"
51
-)
52
-
53
-const debug bool = false
54
-
55
-// Constants that identify the encoding of a value on the wire.
56
-const (
57
- WireVarint = 0
58
- WireFixed64 = 1
59
- WireBytes = 2
60
- WireStartGroup = 3
61
- WireEndGroup = 4
62
- WireFixed32 = 5
63
-)
64
-
65
-const startSize = 10 // initial slice/string sizes
66
-
67
-// Encoders are defined in encode.go
68
-// An encoder outputs the full representation of a field, including its
69
-// tag and encoder type.
70
-type encoder func(p *Buffer, prop *Properties, base structPointer) error
71
-
72
-// A valueEncoder encodes a single integer in a particular encoding.
73
-type valueEncoder func(o *Buffer, x uint64) error
74
-
75
-// Sizers are defined in encode.go
76
-// A sizer returns the encoded size of a field, including its tag and encoder
77
-// type.
78
-type sizer func(prop *Properties, base structPointer) int
79
-
80
-// A valueSizer returns the encoded size of a single integer in a particular
81
-// encoding.
82
-type valueSizer func(x uint64) int
83
-
84
-// Decoders are defined in decode.go
85
-// A decoder creates a value from its wire representation.
86
-// Unrecognized subelements are saved in unrec.
87
-type decoder func(p *Buffer, prop *Properties, base structPointer) error
88
-
89
-// A valueDecoder decodes a single integer in a particular encoding.
90
-type valueDecoder func(o *Buffer) (x uint64, err error)
91
-
92
-// tagMap is an optimization over map[int]int for typical protocol buffer
93
-// use-cases. Encoded protocol buffers are often in tag order with small tag
94
-// numbers.
95
-type tagMap struct {
96
- fastTags []int
97
- slowTags map[int]int
98
-}
99
-
100
-// tagMapFastLimit is the upper bound on the tag number that will be stored in
101
-// the tagMap slice rather than its map.
102
-const tagMapFastLimit = 1024
103
-
104
-func (p *tagMap) get(t int) (int, bool) {
105
- if t > 0 && t < tagMapFastLimit {
106
- if t >= len(p.fastTags) {
107
- return 0, false
108
- }
109
- fi := p.fastTags[t]
110
- return fi, fi >= 0
111
- }
112
- fi, ok := p.slowTags[t]
113
- return fi, ok
114
-}
115
-
116
-func (p *tagMap) put(t int, fi int) {
117
- if t > 0 && t < tagMapFastLimit {
118
- for len(p.fastTags) < t+1 {
119
- p.fastTags = append(p.fastTags, -1)
120
- }
121
- p.fastTags[t] = fi
122
- return
123
- }
124
- if p.slowTags == nil {
125
- p.slowTags = make(map[int]int)
126
- }
127
- p.slowTags[t] = fi
128
-}
129
-
130
-// StructProperties represents properties for all the fields of a struct.
131
-// decoderTags and decoderOrigNames should only be used by the decoder.
132
-type StructProperties struct {
133
- Prop []*Properties // properties for each field
134
- reqCount int // required count
135
- decoderTags tagMap // map from proto tag to struct field number
136
- decoderOrigNames map[string]int // map from original name to struct field number
137
- order []int // list of struct field numbers in tag order
138
- unrecField field // field id of the XXX_unrecognized []byte field
139
- extendable bool // is this an extendable proto
140
-}
141
-
142
-// Implement the sorting interface so we can sort the fields in tag order, as recommended by the spec.
143
-// See encode.go, (*Buffer).enc_struct.
144
-
145
-func (sp *StructProperties) Len() int { return len(sp.order) }
146
-func (sp *StructProperties) Less(i, j int) bool {
147
- return sp.Prop[sp.order[i]].Tag < sp.Prop[sp.order[j]].Tag
148
-}
149
-func (sp *StructProperties) Swap(i, j int) { sp.order[i], sp.order[j] = sp.order[j], sp.order[i] }
150
-
151
-// Properties represents the protocol-specific behavior of a single struct field.
152
-type Properties struct {
153
- Name string // name of the field, for error messages
154
- OrigName string // original name before protocol compiler (always set)
155
- Wire string
156
- WireType int
157
- Tag int
158
- Required bool
159
- Optional bool
160
- Repeated bool
161
- Packed bool // relevant for repeated primitives only
162
- Enum string // set for enum types only
163
- Default string // default value
164
- CustomType string
165
- def_uint64 uint64
166
-
167
- enc encoder
168
- valEnc valueEncoder // set for bool and numeric types only
169
- field field
170
- tagcode []byte // encoding of EncodeVarint((Tag<<3)|WireType)
171
- tagbuf [8]byte
172
- stype reflect.Type // set for struct types only
173
- sstype reflect.Type // set for slices of structs types only
174
- ctype reflect.Type // set for custom types only
175
- sprop *StructProperties // set for struct types only
176
- isMarshaler bool
177
- isUnmarshaler bool
178
-
179
- size sizer
180
- valSize valueSizer // set for bool and numeric types only
181
-
182
- dec decoder
183
- valDec valueDecoder // set for bool and numeric types only
184
-
185
- // If this is a packable field, this will be the decoder for the packed version of the field.
186
- packedDec decoder
187
-}
188
-
189
-// String formats the properties in the protobuf struct field tag style.
190
-func (p *Properties) String() string {
191
- s := p.Wire
192
- s = ","
193
- s += strconv.Itoa(p.Tag)
194
- if p.Required {
195
- s += ",req"
196
- }
197
- if p.Optional {
198
- s += ",opt"
199
- }
200
- if p.Repeated {
201
- s += ",rep"
202
- }
203
- if p.Packed {
204
- s += ",packed"
205
- }
206
- if p.OrigName != p.Name {
207
- s += ",name=" + p.OrigName
208
- }
209
- if len(p.Enum) > 0 {
210
- s += ",enum=" + p.Enum
211
- }
212
- if len(p.Default) > 0 {
213
- s += ",def=" + p.Default
214
- }
215
- return s
216
-}
217
-
218
-// Parse populates p by parsing a string in the protobuf struct field tag style.
219
-func (p *Properties) Parse(s string) {
220
- // "bytes,49,opt,name=foo,def=hello!"
221
- fields := strings.Split(s, ",") // breaks def=, but handled below.
222
- if len(fields) < 2 {
223
- fmt.Fprintf(os.Stderr, "proto: tag has too few fields: %q\n", s)
224
- return
225
- }
226
-
227
- p.Wire = fields[0]
228
- switch p.Wire {
229
- case "varint":
230
- p.WireType = WireVarint
231
- p.valEnc = (*Buffer).EncodeVarint
232
- p.valDec = (*Buffer).DecodeVarint
233
- p.valSize = sizeVarint
234
- case "fixed32":
235
- p.WireType = WireFixed32
236
- p.valEnc = (*Buffer).EncodeFixed32
237
- p.valDec = (*Buffer).DecodeFixed32
238
- p.valSize = sizeFixed32
239
- case "fixed64":
240
- p.WireType = WireFixed64
241
- p.valEnc = (*Buffer).EncodeFixed64
242
- p.valDec = (*Buffer).DecodeFixed64
243
- p.valSize = sizeFixed64
244
- case "zigzag32":
245
- p.WireType = WireVarint
246
- p.valEnc = (*Buffer).EncodeZigzag32
247
- p.valDec = (*Buffer).DecodeZigzag32
248
- p.valSize = sizeZigzag32
249
- case "zigzag64":
250
- p.WireType = WireVarint
251
- p.valEnc = (*Buffer).EncodeZigzag64
252
- p.valDec = (*Buffer).DecodeZigzag64
253
- p.valSize = sizeZigzag64
254
- case "bytes", "group":
255
- p.WireType = WireBytes
256
- // no numeric converter for non-numeric types
257
- default:
258
- fmt.Fprintf(os.Stderr, "proto: tag has unknown wire type: %q\n", s)
259
- return
260
- }
261
-
262
- var err error
263
- p.Tag, err = strconv.Atoi(fields[1])
264
- if err != nil {
265
- return
266
- }
267
-
268
- for i := 2; i < len(fields); i++ {
269
- f := fields[i]
270
- switch {
271
- case f == "req":
272
- p.Required = true
273
- case f == "opt":
274
- p.Optional = true
275
- case f == "rep":
276
- p.Repeated = true
277
- case f == "packed":
278
- p.Packed = true
279
- case strings.HasPrefix(f, "name="):
280
- p.OrigName = f[5:]
281
- case strings.HasPrefix(f, "enum="):
282
- p.Enum = f[5:]
283
- case strings.HasPrefix(f, "def="):
284
- p.Default = f[4:] // rest of string
285
- if i+1 < len(fields) {
286
- // Commas aren't escaped, and def is always last.
287
- p.Default += "," + strings.Join(fields[i+1:], ",")
288
- break
289
- }
290
- case strings.HasPrefix(f, "embedded="):
291
- p.OrigName = strings.Split(f, "=")[1]
292
- case strings.HasPrefix(f, "customtype="):
293
- p.CustomType = strings.Split(f, "=")[1]
294
- }
295
- }
296
-}
297
-
298
-func logNoSliceEnc(t1, t2 reflect.Type) {
299
- fmt.Fprintf(os.Stderr, "proto: no slice oenc for %T = []%T\n", t1, t2)
300
-}
301
-
302
-var protoMessageType = reflect.TypeOf((*Message)(nil)).Elem()
303
-
304
-// Initialize the fields for encoding and decoding.
305
-func (p *Properties) setEncAndDec(typ reflect.Type, lockGetProp bool) {
306
- p.enc = nil
307
- p.dec = nil
308
- p.size = nil
309
- if len(p.CustomType) > 0 {
310
- p.setCustomEncAndDec(typ)
311
- p.setTag(lockGetProp)
312
- return
313
- }
314
- switch t1 := typ; t1.Kind() {
315
- default:
316
- if !p.setNonNullableEncAndDec(t1) {
317
- fmt.Fprintf(os.Stderr, "proto: no coders for %T\n", t1)
318
- }
319
- case reflect.Ptr:
320
- switch t2 := t1.Elem(); t2.Kind() {
321
- default:
322
- fmt.Fprintf(os.Stderr, "proto: no encoder function for %T -> %T\n", t1, t2)
323
- break
324
- case reflect.Bool:
325
- p.enc = (*Buffer).enc_bool
326
- p.dec = (*Buffer).dec_bool
327
- p.size = size_bool
328
- case reflect.Int32, reflect.Uint32:
329
- p.enc = (*Buffer).enc_int32
330
- p.dec = (*Buffer).dec_int32
331
- p.size = size_int32
332
- case reflect.Int64, reflect.Uint64:
333
- p.enc = (*Buffer).enc_int64
334
- p.dec = (*Buffer).dec_int64
335
- p.size = size_int64
336
- case reflect.Float32:
337
- p.enc = (*Buffer).enc_int32 // can just treat them as bits
338
- p.dec = (*Buffer).dec_int32
339
- p.size = size_int32
340
- case reflect.Float64:
341
- p.enc = (*Buffer).enc_int64 // can just treat them as bits
342
- p.dec = (*Buffer).dec_int64
343
- p.size = size_int64
344
- case reflect.String:
345
- p.enc = (*Buffer).enc_string
346
- p.dec = (*Buffer).dec_string
347
- p.size = size_string
348
- case reflect.Struct:
349
- p.stype = t1.Elem()
350
- p.isMarshaler = isMarshaler(t1)
351
- p.isUnmarshaler = isUnmarshaler(t1)
352
- if p.Wire == "bytes" {
353
- p.enc = (*Buffer).enc_struct_message
354
- p.dec = (*Buffer).dec_struct_message
355
- p.size = size_struct_message
356
- } else {
357
- p.enc = (*Buffer).enc_struct_group
358
- p.dec = (*Buffer).dec_struct_group
359
- p.size = size_struct_group
360
- }
361
- }
362
-
363
- case reflect.Slice:
364
- switch t2 := t1.Elem(); t2.Kind() {
365
- default:
366
- logNoSliceEnc(t1, t2)
367
- break
368
- case reflect.Bool:
369
- if p.Packed {
370
- p.enc = (*Buffer).enc_slice_packed_bool
371
- p.size = size_slice_packed_bool
372
- } else {
373
- p.enc = (*Buffer).enc_slice_bool
374
- p.size = size_slice_bool
375
- }
376
- p.dec = (*Buffer).dec_slice_bool
377
- p.packedDec = (*Buffer).dec_slice_packed_bool
378
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
379
- switch t2.Bits() {
380
- case 32:
381
- if p.Packed {
382
- p.enc = (*Buffer).enc_slice_packed_int32
383
- p.size = size_slice_packed_int32
384
- } else {
385
- p.enc = (*Buffer).enc_slice_int32
386
- p.size = size_slice_int32
387
- }
388
- p.dec = (*Buffer).dec_slice_int32
389
- p.packedDec = (*Buffer).dec_slice_packed_int32
390
- case 64:
391
- if p.Packed {
392
- p.enc = (*Buffer).enc_slice_packed_int64
393
- p.size = size_slice_packed_int64
394
- } else {
395
- p.enc = (*Buffer).enc_slice_int64
396
- p.size = size_slice_int64
397
- }
398
- p.dec = (*Buffer).dec_slice_int64
399
- p.packedDec = (*Buffer).dec_slice_packed_int64
400
- case 8:
401
- if t2.Kind() == reflect.Uint8 {
402
- p.enc = (*Buffer).enc_slice_byte
403
- p.dec = (*Buffer).dec_slice_byte
404
- p.size = size_slice_byte
405
- }
406
- default:
407
- logNoSliceEnc(t1, t2)
408
- break
409
- }
410
- case reflect.Float32, reflect.Float64:
411
- switch t2.Bits() {
412
- case 32:
413
- // can just treat them as bits
414
- if p.Packed {
415
- p.enc = (*Buffer).enc_slice_packed_int32
416
- p.size = size_slice_packed_int32
417
- } else {
418
- p.enc = (*Buffer).enc_slice_int32
419
- p.size = size_slice_int32
420
- }
421
- p.dec = (*Buffer).dec_slice_int32
422
- p.packedDec = (*Buffer).dec_slice_packed_int32
423
- case 64:
424
- // can just treat them as bits
425
- if p.Packed {
426
- p.enc = (*Buffer).enc_slice_packed_int64
427
- p.size = size_slice_packed_int64
428
- } else {
429
- p.enc = (*Buffer).enc_slice_int64
430
- p.size = size_slice_int64
431
- }
432
- p.dec = (*Buffer).dec_slice_int64
433
- p.packedDec = (*Buffer).dec_slice_packed_int64
434
- default:
435
- logNoSliceEnc(t1, t2)
436
- break
437
- }
438
- case reflect.String:
439
- p.enc = (*Buffer).enc_slice_string
440
- p.dec = (*Buffer).dec_slice_string
441
- p.size = size_slice_string
442
- case reflect.Ptr:
443
- switch t3 := t2.Elem(); t3.Kind() {
444
- default:
445
- fmt.Fprintf(os.Stderr, "proto: no ptr oenc for %T -> %T -> %T\n", t1, t2, t3)
446
- break
447
- case reflect.Struct:
448
- p.stype = t2.Elem()
449
- p.isMarshaler = isMarshaler(t2)
450
- p.isUnmarshaler = isUnmarshaler(t2)
451
- if p.Wire == "bytes" {
452
- p.enc = (*Buffer).enc_slice_struct_message
453
- p.dec = (*Buffer).dec_slice_struct_message
454
- p.size = size_slice_struct_message
455
- } else {
456
- p.enc = (*Buffer).enc_slice_struct_group
457
- p.dec = (*Buffer).dec_slice_struct_group
458
- p.size = size_slice_struct_group
459
- }
460
- }
461
- case reflect.Slice:
462
- switch t2.Elem().Kind() {
463
- default:
464
- fmt.Fprintf(os.Stderr, "proto: no slice elem oenc for %T -> %T -> %T\n", t1, t2, t2.Elem())
465
- break
466
- case reflect.Uint8:
467
- p.enc = (*Buffer).enc_slice_slice_byte
468
- p.dec = (*Buffer).dec_slice_slice_byte
469
- p.size = size_slice_slice_byte
470
- }
471
- case reflect.Struct:
472
- p.setSliceOfNonPointerStructs(t1)
473
- }
474
- }
475
- p.setTag(lockGetProp)
476
-}
477
-
478
-func (p *Properties) setTag(lockGetProp bool) {
479
- // precalculate tag code
480
- wire := p.WireType
481
- if p.Packed {
482
- wire = WireBytes
483
- }
484
- x := uint32(p.Tag)<<3 | uint32(wire)
485
- i := 0
486
- for i = 0; x > 127; i++ {
487
- p.tagbuf[i] = 0x80 | uint8(x&0x7F)
488
- x >>= 7
489
- }
490
- p.tagbuf[i] = uint8(x)
491
- p.tagcode = p.tagbuf[0 : i+1]
492
-
493
- if p.stype != nil {
494
- if lockGetProp {
495
- p.sprop = GetProperties(p.stype)
496
- } else {
497
- p.sprop = getPropertiesLocked(p.stype)
498
- }
499
- }
500
-}
501
-
502
-var (
503
- marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
504
- unmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem()
505
-)
506
-
507
-// isMarshaler reports whether type t implements Marshaler.
508
-func isMarshaler(t reflect.Type) bool {
509
- return t.Implements(marshalerType)
510
-}
511
-
512
-// isUnmarshaler reports whether type t implements Unmarshaler.
513
-func isUnmarshaler(t reflect.Type) bool {
514
- return t.Implements(unmarshalerType)
515
-}
516
-
517
-// Init populates the properties from a protocol buffer struct tag.
518
-func (p *Properties) Init(typ reflect.Type, name, tag string, f *reflect.StructField) {
519
- p.init(typ, name, tag, f, true)
520
-}
521
-
522
-func (p *Properties) init(typ reflect.Type, name, tag string, f *reflect.StructField, lockGetProp bool) {
523
- // "bytes,49,opt,def=hello!"
524
- p.Name = name
525
- p.OrigName = name
526
- if f != nil {
527
- p.field = toField(f)
528
- }
529
- if tag == "" {
530
- return
531
- }
532
- p.Parse(tag)
533
- p.setEncAndDec(typ, lockGetProp)
534
-}
535
-
536
-var (
537
- mutex sync.Mutex
538
- propertiesMap = make(map[reflect.Type]*StructProperties)
539
-)
540
-
541
-// GetProperties returns the list of properties for the type represented by t.
542
-func GetProperties(t reflect.Type) *StructProperties {
543
- mutex.Lock()
544
- sprop := getPropertiesLocked(t)
545
- mutex.Unlock()
546
- return sprop
547
-}
548
-
549
-// getPropertiesLocked requires that mutex is held.
550
-func getPropertiesLocked(t reflect.Type) *StructProperties {
551
- if prop, ok := propertiesMap[t]; ok {
552
- if collectStats {
553
- stats.Chit++
554
- }
555
- return prop
556
- }
557
- if collectStats {
558
- stats.Cmiss++
559
- }
560
-
561
- prop := new(StructProperties)
562
- // in case of recursive protos, fill this in now.
563
- propertiesMap[t] = prop
564
-
565
- // build properties
566
- prop.extendable = reflect.PtrTo(t).Implements(extendableProtoType)
567
- prop.unrecField = invalidField
568
- prop.Prop = make([]*Properties, t.NumField())
569
- prop.order = make([]int, t.NumField())
570
-
571
- for i := 0; i < t.NumField(); i++ {
572
- f := t.Field(i)
573
- p := new(Properties)
574
- name := f.Name
575
- p.init(f.Type, name, f.Tag.Get("protobuf"), &f, false)
576
-
577
- if f.Name == "XXX_extensions" { // special case
578
- if len(f.Tag.Get("protobuf")) > 0 {
579
- p.enc = (*Buffer).enc_ext_slice_byte
580
- p.dec = nil // not needed
581
- p.size = size_ext_slice_byte
582
- } else {
583
- p.enc = (*Buffer).enc_map
584
- p.dec = nil // not needed
585
- p.size = size_map
586
- }
587
- }
588
- if f.Name == "XXX_unrecognized" { // special case
589
- prop.unrecField = toField(&f)
590
- }
591
- prop.Prop[i] = p
592
- prop.order[i] = i
593
- if debug {
594
- print(i, " ", f.Name, " ", t.String(), " ")
595
- if p.Tag > 0 {
596
- print(p.String())
597
- }
598
- print("\n")
599
- }
600
- if p.enc == nil && !strings.HasPrefix(f.Name, "XXX_") {
601
- fmt.Fprintln(os.Stderr, "proto: no encoder for", f.Name, f.Type.String(), "[GetProperties]")
602
- }
603
- }
604
-
605
- // Re-order prop.order.
606
- sort.Sort(prop)
607
-
608
- // build required counts
609
- // build tags
610
- reqCount := 0
611
- prop.decoderOrigNames = make(map[string]int)
612
- for i, p := range prop.Prop {
613
- if strings.HasPrefix(p.Name, "XXX_") {
614
- // Internal fields should not appear in tags/origNames maps.
615
- // They are handled specially when encoding and decoding.
616
- continue
617
- }
618
- if p.Required {
619
- reqCount++
620
- }
621
- prop.decoderTags.put(p.Tag, i)
622
- prop.decoderOrigNames[p.OrigName] = i
623
- }
624
- prop.reqCount = reqCount
625
-
626
- return prop
627
-}
628
-
629
-// Return the Properties object for the x[0]'th field of the structure.
630
-func propByIndex(t reflect.Type, x []int) *Properties {
631
- if len(x) != 1 {
632
- fmt.Fprintf(os.Stderr, "proto: field index dimension %d (not 1) for type %s\n", len(x), t)
633
- return nil
634
- }
635
- prop := GetProperties(t)
636
- return prop.Prop[x[0]]
637
-}
638
-
639
-// Get the address and type of a pointer to a struct from an interface.
640
-func getbase(pb Message) (t reflect.Type, b structPointer, err error) {
641
- if pb == nil {
642
- err = ErrNil
643
- return
644
- }
645
- // get the reflect type of the pointer to the struct.
646
- t = reflect.TypeOf(pb)
647
- // get the address of the struct.
648
- value := reflect.ValueOf(pb)
649
- b = toStructPointer(value)
650
- return
651
-}
652
-
653
-// A global registry of enum types.
654
-// The generated code will register the generated maps by calling RegisterEnum.
655
-
656
-var enumValueMaps = make(map[string]map[string]int32)
657
-var enumStringMaps = make(map[string]map[int32]string)
658
-
659
-// RegisterEnum is called from the generated code to install the enum descriptor
660
-// maps into the global table to aid parsing text format protocol buffers.
661
-func RegisterEnum(typeName string, unusedNameMap map[int32]string, valueMap map[string]int32) {
662
- if _, ok := enumValueMaps[typeName]; ok {
663
- panic("proto: duplicate enum registered: " + typeName)
664
- }
665
- enumValueMaps[typeName] = valueMap
666
- if _, ok := enumStringMaps[typeName]; ok {
667
- panic("proto: duplicate enum registered: " + typeName)
668
- }
669
- enumStringMaps[typeName] = unusedNameMap
670
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/size2_test.go
deleted
-63
@@ -1,63 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2012 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto
33
-
34
-import (
35
- "testing"
36
-)
37
-
38
-// This is a separate file and package from size_test.go because that one uses
39
-// generated messages and thus may not be in package proto without having a circular
40
-// dependency, whereas this file tests unexported details of size.go.
41
-
42
-func TestVarintSize(t *testing.T) {
43
- // Check the edge cases carefully.
44
- testCases := []struct {
45
- n uint64
46
- size int
47
- }{
48
- {0, 1},
49
- {1, 1},
50
- {127, 1},
51
- {128, 2},
52
- {16383, 2},
53
- {16384, 3},
54
- {1<<63 - 1, 9},
55
- {1 << 63, 10},
56
- }
57
- for _, tc := range testCases {
58
- size := sizeVarint(tc.n)
59
- if size != tc.size {
60
- t.Errorf("sizeVarint(%d) = %d, want %d", tc.n, size, tc.size)
61
- }
62
- }
63
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/size_test.go
deleted
-118
@@ -1,118 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2012 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto_test
33
-
34
-import (
35
- "log"
36
- "testing"
37
-
38
- pb "./testdata"
39
- . "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
40
-)
41
-
42
-var messageWithExtension1 = &pb.MyMessage{Count: Int32(7)}
43
-
44
-// messageWithExtension2 is in equal_test.go.
45
-var messageWithExtension3 = &pb.MyMessage{Count: Int32(8)}
46
-
47
-func init() {
48
- if err := SetExtension(messageWithExtension1, pb.E_Ext_More, &pb.Ext{Data: String("Abbott")}); err != nil {
49
- log.Panicf("SetExtension: %v", err)
50
- }
51
- if err := SetExtension(messageWithExtension3, pb.E_Ext_More, &pb.Ext{Data: String("Costello")}); err != nil {
52
- log.Panicf("SetExtension: %v", err)
53
- }
54
-
55
- // Force messageWithExtension3 to have the extension encoded.
56
- Marshal(messageWithExtension3)
57
-
58
-}
59
-
60
-var SizeTests = []struct {
61
- desc string
62
- pb Message
63
-}{
64
- {"empty", &pb.OtherMessage{}},
65
- // Basic types.
66
- {"bool", &pb.Defaults{F_Bool: Bool(true)}},
67
- {"int32", &pb.Defaults{F_Int32: Int32(12)}},
68
- {"small int64", &pb.Defaults{F_Int64: Int64(1)}},
69
- {"big int64", &pb.Defaults{F_Int64: Int64(1 << 20)}},
70
- {"fixed32", &pb.Defaults{F_Fixed32: Uint32(71)}},
71
- {"fixed64", &pb.Defaults{F_Fixed64: Uint64(72)}},
72
- {"uint32", &pb.Defaults{F_Uint32: Uint32(123)}},
73
- {"uint64", &pb.Defaults{F_Uint64: Uint64(124)}},
74
- {"float", &pb.Defaults{F_Float: Float32(12.6)}},
75
- {"double", &pb.Defaults{F_Double: Float64(13.9)}},
76
- {"string", &pb.Defaults{F_String: String("niles")}},
77
- {"bytes", &pb.Defaults{F_Bytes: []byte("wowsa")}},
78
- {"bytes, empty", &pb.Defaults{F_Bytes: []byte{}}},
79
- {"sint32", &pb.Defaults{F_Sint32: Int32(65)}},
80
- {"sint64", &pb.Defaults{F_Sint64: Int64(67)}},
81
- {"enum", &pb.Defaults{F_Enum: pb.Defaults_BLUE.Enum()}},
82
- // Repeated.
83
- {"empty repeated bool", &pb.MoreRepeated{Bools: []bool{}}},
84
- {"repeated bool", &pb.MoreRepeated{Bools: []bool{false, true, true, false}}},
85
- {"packed repeated bool", &pb.MoreRepeated{BoolsPacked: []bool{false, true, true, false, true, true, true}}},
86
- {"repeated int32", &pb.MoreRepeated{Ints: []int32{1, 12203, 1729}}},
87
- {"repeated int32 packed", &pb.MoreRepeated{IntsPacked: []int32{1, 12203, 1729}}},
88
- {"repeated int64 packed", &pb.MoreRepeated{Int64SPacked: []int64{
89
- // Need enough large numbers to verify that the header is counting the number of bytes
90
- // for the field, not the number of elements.
91
- 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62,
92
- 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62,
93
- }}},
94
- {"repeated string", &pb.MoreRepeated{Strings: []string{"r", "ken", "gri"}}},
95
- {"repeated fixed", &pb.MoreRepeated{Fixeds: []uint32{1, 2, 3, 4}}},
96
- // Nested.
97
- {"nested", &pb.OldMessage{Nested: &pb.OldMessage_Nested{Name: String("whatever")}}},
98
- {"group", &pb.GroupOld{G: &pb.GroupOld_G{X: Int32(12345)}}},
99
- // Other things.
100
- {"unrecognized", &pb.MoreRepeated{XXX_unrecognized: []byte{13<<3 | 0, 4}}},
101
- {"extension (unencoded)", messageWithExtension1},
102
- {"extension (encoded)", messageWithExtension3},
103
-}
104
-
105
-func TestSize(t *testing.T) {
106
- for _, tc := range SizeTests {
107
- size := Size(tc.pb)
108
- b, err := Marshal(tc.pb)
109
- if err != nil {
110
- t.Errorf("%v: Marshal failed: %v", tc.desc, err)
111
- continue
112
- }
113
- if size != len(b) {
114
- t.Errorf("%v: Size(%v) = %d, want %d", tc.desc, tc.pb, size, len(b))
115
- t.Logf("%v: bytes: %#v", tc.desc, b)
116
- }
117
- }
118
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/testdata/test.pb.go
deleted
-2324
@@ -1,2324 +0,0 @@
1
-// Code generated by protoc-gen-gogo.
2
-// source: test.proto
3
-// DO NOT EDIT!
4
-
5
-/*
6
-Package testdata is a generated protocol buffer package.
7
-
8
-It is generated from these files:
9
- test.proto
10
-
11
-It has these top-level messages:
12
- GoEnum
13
- GoTestField
14
- GoTest
15
- GoSkipTest
16
- NonPackedTest
17
- PackedTest
18
- MaxTag
19
- OldMessage
20
- NewMessage
21
- InnerMessage
22
- OtherMessage
23
- MyMessage
24
- Ext
25
- MyMessageSet
26
- Empty
27
- MessageList
28
- Strings
29
- Defaults
30
- SubDefaults
31
- RepeatedEnum
32
- MoreRepeated
33
- GroupOld
34
- GroupNew
35
- FloatingPoint
36
-*/
37
-package testdata
38
-
39
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
40
-import math "math"
41
-
42
-// Reference imports to suppress errors if they are not otherwise used.
43
-var _ = proto.Marshal
44
-var _ = math.Inf
45
-
46
-type FOO int32
47
-
48
-const (
49
- FOO_FOO1 FOO = 1
50
-)
51
-
52
-var FOO_name = map[int32]string{
53
- 1: "FOO1",
54
-}
55
-var FOO_value = map[string]int32{
56
- "FOO1": 1,
57
-}
58
-
59
-func (x FOO) Enum() *FOO {
60
- p := new(FOO)
61
- *p = x
62
- return p
63
-}
64
-func (x FOO) String() string {
65
- return proto.EnumName(FOO_name, int32(x))
66
-}
67
-func (x *FOO) UnmarshalJSON(data []byte) error {
68
- value, err := proto.UnmarshalJSONEnum(FOO_value, data, "FOO")
69
- if err != nil {
70
- return err
71
- }
72
- *x = FOO(value)
73
- return nil
74
-}
75
-
76
-// An enum, for completeness.
77
-type GoTest_KIND int32
78
-
79
-const (
80
- GoTest_VOID GoTest_KIND = 0
81
- // Basic types
82
- GoTest_BOOL GoTest_KIND = 1
83
- GoTest_BYTES GoTest_KIND = 2
84
- GoTest_FINGERPRINT GoTest_KIND = 3
85
- GoTest_FLOAT GoTest_KIND = 4
86
- GoTest_INT GoTest_KIND = 5
87
- GoTest_STRING GoTest_KIND = 6
88
- GoTest_TIME GoTest_KIND = 7
89
- // Groupings
90
- GoTest_TUPLE GoTest_KIND = 8
91
- GoTest_ARRAY GoTest_KIND = 9
92
- GoTest_MAP GoTest_KIND = 10
93
- // Table types
94
- GoTest_TABLE GoTest_KIND = 11
95
- // Functions
96
- GoTest_FUNCTION GoTest_KIND = 12
97
-)
98
-
99
-var GoTest_KIND_name = map[int32]string{
100
- 0: "VOID",
101
- 1: "BOOL",
102
- 2: "BYTES",
103
- 3: "FINGERPRINT",
104
- 4: "FLOAT",
105
- 5: "INT",
106
- 6: "STRING",
107
- 7: "TIME",
108
- 8: "TUPLE",
109
- 9: "ARRAY",
110
- 10: "MAP",
111
- 11: "TABLE",
112
- 12: "FUNCTION",
113
-}
114
-var GoTest_KIND_value = map[string]int32{
115
- "VOID": 0,
116
- "BOOL": 1,
117
- "BYTES": 2,
118
- "FINGERPRINT": 3,
119
- "FLOAT": 4,
120
- "INT": 5,
121
- "STRING": 6,
122
- "TIME": 7,
123
- "TUPLE": 8,
124
- "ARRAY": 9,
125
- "MAP": 10,
126
- "TABLE": 11,
127
- "FUNCTION": 12,
128
-}
129
-
130
-func (x GoTest_KIND) Enum() *GoTest_KIND {
131
- p := new(GoTest_KIND)
132
- *p = x
133
- return p
134
-}
135
-func (x GoTest_KIND) String() string {
136
- return proto.EnumName(GoTest_KIND_name, int32(x))
137
-}
138
-func (x *GoTest_KIND) UnmarshalJSON(data []byte) error {
139
- value, err := proto.UnmarshalJSONEnum(GoTest_KIND_value, data, "GoTest_KIND")
140
- if err != nil {
141
- return err
142
- }
143
- *x = GoTest_KIND(value)
144
- return nil
145
-}
146
-
147
-type MyMessage_Color int32
148
-
149
-const (
150
- MyMessage_RED MyMessage_Color = 0
151
- MyMessage_GREEN MyMessage_Color = 1
152
- MyMessage_BLUE MyMessage_Color = 2
153
-)
154
-
155
-var MyMessage_Color_name = map[int32]string{
156
- 0: "RED",
157
- 1: "GREEN",
158
- 2: "BLUE",
159
-}
160
-var MyMessage_Color_value = map[string]int32{
161
- "RED": 0,
162
- "GREEN": 1,
163
- "BLUE": 2,
164
-}
165
-
166
-func (x MyMessage_Color) Enum() *MyMessage_Color {
167
- p := new(MyMessage_Color)
168
- *p = x
169
- return p
170
-}
171
-func (x MyMessage_Color) String() string {
172
- return proto.EnumName(MyMessage_Color_name, int32(x))
173
-}
174
-func (x *MyMessage_Color) UnmarshalJSON(data []byte) error {
175
- value, err := proto.UnmarshalJSONEnum(MyMessage_Color_value, data, "MyMessage_Color")
176
- if err != nil {
177
- return err
178
- }
179
- *x = MyMessage_Color(value)
180
- return nil
181
-}
182
-
183
-type Defaults_Color int32
184
-
185
-const (
186
- Defaults_RED Defaults_Color = 0
187
- Defaults_GREEN Defaults_Color = 1
188
- Defaults_BLUE Defaults_Color = 2
189
-)
190
-
191
-var Defaults_Color_name = map[int32]string{
192
- 0: "RED",
193
- 1: "GREEN",
194
- 2: "BLUE",
195
-}
196
-var Defaults_Color_value = map[string]int32{
197
- "RED": 0,
198
- "GREEN": 1,
199
- "BLUE": 2,
200
-}
201
-
202
-func (x Defaults_Color) Enum() *Defaults_Color {
203
- p := new(Defaults_Color)
204
- *p = x
205
- return p
206
-}
207
-func (x Defaults_Color) String() string {
208
- return proto.EnumName(Defaults_Color_name, int32(x))
209
-}
210
-func (x *Defaults_Color) UnmarshalJSON(data []byte) error {
211
- value, err := proto.UnmarshalJSONEnum(Defaults_Color_value, data, "Defaults_Color")
212
- if err != nil {
213
- return err
214
- }
215
- *x = Defaults_Color(value)
216
- return nil
217
-}
218
-
219
-type RepeatedEnum_Color int32
220
-
221
-const (
222
- RepeatedEnum_RED RepeatedEnum_Color = 1
223
-)
224
-
225
-var RepeatedEnum_Color_name = map[int32]string{
226
- 1: "RED",
227
-}
228
-var RepeatedEnum_Color_value = map[string]int32{
229
- "RED": 1,
230
-}
231
-
232
-func (x RepeatedEnum_Color) Enum() *RepeatedEnum_Color {
233
- p := new(RepeatedEnum_Color)
234
- *p = x
235
- return p
236
-}
237
-func (x RepeatedEnum_Color) String() string {
238
- return proto.EnumName(RepeatedEnum_Color_name, int32(x))
239
-}
240
-func (x *RepeatedEnum_Color) UnmarshalJSON(data []byte) error {
241
- value, err := proto.UnmarshalJSONEnum(RepeatedEnum_Color_value, data, "RepeatedEnum_Color")
242
- if err != nil {
243
- return err
244
- }
245
- *x = RepeatedEnum_Color(value)
246
- return nil
247
-}
248
-
249
-type GoEnum struct {
250
- Foo *FOO `protobuf:"varint,1,req,name=foo,enum=testdata.FOO" json:"foo,omitempty"`
251
- XXX_unrecognized []byte `json:"-"`
252
-}
253
-
254
-func (m *GoEnum) Reset() { *m = GoEnum{} }
255
-func (m *GoEnum) String() string { return proto.CompactTextString(m) }
256
-func (*GoEnum) ProtoMessage() {}
257
-
258
-func (m *GoEnum) GetFoo() FOO {
259
- if m != nil && m.Foo != nil {
260
- return *m.Foo
261
- }
262
- return FOO_FOO1
263
-}
264
-
265
-type GoTestField struct {
266
- Label *string `protobuf:"bytes,1,req" json:"Label,omitempty"`
267
- Type *string `protobuf:"bytes,2,req" json:"Type,omitempty"`
268
- XXX_unrecognized []byte `json:"-"`
269
-}
270
-
271
-func (m *GoTestField) Reset() { *m = GoTestField{} }
272
-func (m *GoTestField) String() string { return proto.CompactTextString(m) }
273
-func (*GoTestField) ProtoMessage() {}
274
-
275
-func (m *GoTestField) GetLabel() string {
276
- if m != nil && m.Label != nil {
277
- return *m.Label
278
- }
279
- return ""
280
-}
281
-
282
-func (m *GoTestField) GetType() string {
283
- if m != nil && m.Type != nil {
284
- return *m.Type
285
- }
286
- return ""
287
-}
288
-
289
-type GoTest struct {
290
- // Some typical parameters
291
- Kind *GoTest_KIND `protobuf:"varint,1,req,enum=testdata.GoTest_KIND" json:"Kind,omitempty"`
292
- Table *string `protobuf:"bytes,2,opt" json:"Table,omitempty"`
293
- Param *int32 `protobuf:"varint,3,opt" json:"Param,omitempty"`
294
- // Required, repeated and optional foreign fields.
295
- RequiredField *GoTestField `protobuf:"bytes,4,req" json:"RequiredField,omitempty"`
296
- RepeatedField []*GoTestField `protobuf:"bytes,5,rep" json:"RepeatedField,omitempty"`
297
- OptionalField *GoTestField `protobuf:"bytes,6,opt" json:"OptionalField,omitempty"`
298
- // Required fields of all basic types
299
- F_BoolRequired *bool `protobuf:"varint,10,req,name=F_Bool_required" json:"F_Bool_required,omitempty"`
300
- F_Int32Required *int32 `protobuf:"varint,11,req,name=F_Int32_required" json:"F_Int32_required,omitempty"`
301
- F_Int64Required *int64 `protobuf:"varint,12,req,name=F_Int64_required" json:"F_Int64_required,omitempty"`
302
- F_Fixed32Required *uint32 `protobuf:"fixed32,13,req,name=F_Fixed32_required" json:"F_Fixed32_required,omitempty"`
303
- F_Fixed64Required *uint64 `protobuf:"fixed64,14,req,name=F_Fixed64_required" json:"F_Fixed64_required,omitempty"`
304
- F_Uint32Required *uint32 `protobuf:"varint,15,req,name=F_Uint32_required" json:"F_Uint32_required,omitempty"`
305
- F_Uint64Required *uint64 `protobuf:"varint,16,req,name=F_Uint64_required" json:"F_Uint64_required,omitempty"`
306
- F_FloatRequired *float32 `protobuf:"fixed32,17,req,name=F_Float_required" json:"F_Float_required,omitempty"`
307
- F_DoubleRequired *float64 `protobuf:"fixed64,18,req,name=F_Double_required" json:"F_Double_required,omitempty"`
308
- F_StringRequired *string `protobuf:"bytes,19,req,name=F_String_required" json:"F_String_required,omitempty"`
309
- F_BytesRequired []byte `protobuf:"bytes,101,req,name=F_Bytes_required" json:"F_Bytes_required,omitempty"`
310
- F_Sint32Required *int32 `protobuf:"zigzag32,102,req,name=F_Sint32_required" json:"F_Sint32_required,omitempty"`
311
- F_Sint64Required *int64 `protobuf:"zigzag64,103,req,name=F_Sint64_required" json:"F_Sint64_required,omitempty"`
312
- // Repeated fields of all basic types
313
- F_BoolRepeated []bool `protobuf:"varint,20,rep,name=F_Bool_repeated" json:"F_Bool_repeated,omitempty"`
314
- F_Int32Repeated []int32 `protobuf:"varint,21,rep,name=F_Int32_repeated" json:"F_Int32_repeated,omitempty"`
315
- F_Int64Repeated []int64 `protobuf:"varint,22,rep,name=F_Int64_repeated" json:"F_Int64_repeated,omitempty"`
316
- F_Fixed32Repeated []uint32 `protobuf:"fixed32,23,rep,name=F_Fixed32_repeated" json:"F_Fixed32_repeated,omitempty"`
317
- F_Fixed64Repeated []uint64 `protobuf:"fixed64,24,rep,name=F_Fixed64_repeated" json:"F_Fixed64_repeated,omitempty"`
318
- F_Uint32Repeated []uint32 `protobuf:"varint,25,rep,name=F_Uint32_repeated" json:"F_Uint32_repeated,omitempty"`
319
- F_Uint64Repeated []uint64 `protobuf:"varint,26,rep,name=F_Uint64_repeated" json:"F_Uint64_repeated,omitempty"`
320
- F_FloatRepeated []float32 `protobuf:"fixed32,27,rep,name=F_Float_repeated" json:"F_Float_repeated,omitempty"`
321
- F_DoubleRepeated []float64 `protobuf:"fixed64,28,rep,name=F_Double_repeated" json:"F_Double_repeated,omitempty"`
322
- F_StringRepeated []string `protobuf:"bytes,29,rep,name=F_String_repeated" json:"F_String_repeated,omitempty"`
323
- F_BytesRepeated [][]byte `protobuf:"bytes,201,rep,name=F_Bytes_repeated" json:"F_Bytes_repeated,omitempty"`
324
- F_Sint32Repeated []int32 `protobuf:"zigzag32,202,rep,name=F_Sint32_repeated" json:"F_Sint32_repeated,omitempty"`
325
- F_Sint64Repeated []int64 `protobuf:"zigzag64,203,rep,name=F_Sint64_repeated" json:"F_Sint64_repeated,omitempty"`
326
- // Optional fields of all basic types
327
- F_BoolOptional *bool `protobuf:"varint,30,opt,name=F_Bool_optional" json:"F_Bool_optional,omitempty"`
328
- F_Int32Optional *int32 `protobuf:"varint,31,opt,name=F_Int32_optional" json:"F_Int32_optional,omitempty"`
329
- F_Int64Optional *int64 `protobuf:"varint,32,opt,name=F_Int64_optional" json:"F_Int64_optional,omitempty"`
330
- F_Fixed32Optional *uint32 `protobuf:"fixed32,33,opt,name=F_Fixed32_optional" json:"F_Fixed32_optional,omitempty"`
331
- F_Fixed64Optional *uint64 `protobuf:"fixed64,34,opt,name=F_Fixed64_optional" json:"F_Fixed64_optional,omitempty"`
332
- F_Uint32Optional *uint32 `protobuf:"varint,35,opt,name=F_Uint32_optional" json:"F_Uint32_optional,omitempty"`
333
- F_Uint64Optional *uint64 `protobuf:"varint,36,opt,name=F_Uint64_optional" json:"F_Uint64_optional,omitempty"`
334
- F_FloatOptional *float32 `protobuf:"fixed32,37,opt,name=F_Float_optional" json:"F_Float_optional,omitempty"`
335
- F_DoubleOptional *float64 `protobuf:"fixed64,38,opt,name=F_Double_optional" json:"F_Double_optional,omitempty"`
336
- F_StringOptional *string `protobuf:"bytes,39,opt,name=F_String_optional" json:"F_String_optional,omitempty"`
337
- F_BytesOptional []byte `protobuf:"bytes,301,opt,name=F_Bytes_optional" json:"F_Bytes_optional,omitempty"`
338
- F_Sint32Optional *int32 `protobuf:"zigzag32,302,opt,name=F_Sint32_optional" json:"F_Sint32_optional,omitempty"`
339
- F_Sint64Optional *int64 `protobuf:"zigzag64,303,opt,name=F_Sint64_optional" json:"F_Sint64_optional,omitempty"`
340
- // Default-valued fields of all basic types
341
- F_BoolDefaulted *bool `protobuf:"varint,40,opt,name=F_Bool_defaulted,def=1" json:"F_Bool_defaulted,omitempty"`
342
- F_Int32Defaulted *int32 `protobuf:"varint,41,opt,name=F_Int32_defaulted,def=32" json:"F_Int32_defaulted,omitempty"`
343
- F_Int64Defaulted *int64 `protobuf:"varint,42,opt,name=F_Int64_defaulted,def=64" json:"F_Int64_defaulted,omitempty"`
344
- F_Fixed32Defaulted *uint32 `protobuf:"fixed32,43,opt,name=F_Fixed32_defaulted,def=320" json:"F_Fixed32_defaulted,omitempty"`
345
- F_Fixed64Defaulted *uint64 `protobuf:"fixed64,44,opt,name=F_Fixed64_defaulted,def=640" json:"F_Fixed64_defaulted,omitempty"`
346
- F_Uint32Defaulted *uint32 `protobuf:"varint,45,opt,name=F_Uint32_defaulted,def=3200" json:"F_Uint32_defaulted,omitempty"`
347
- F_Uint64Defaulted *uint64 `protobuf:"varint,46,opt,name=F_Uint64_defaulted,def=6400" json:"F_Uint64_defaulted,omitempty"`
348
- F_FloatDefaulted *float32 `protobuf:"fixed32,47,opt,name=F_Float_defaulted,def=314159" json:"F_Float_defaulted,omitempty"`
349
- F_DoubleDefaulted *float64 `protobuf:"fixed64,48,opt,name=F_Double_defaulted,def=271828" json:"F_Double_defaulted,omitempty"`
350
- F_StringDefaulted *string `protobuf:"bytes,49,opt,name=F_String_defaulted,def=hello, \"world!\"\n" json:"F_String_defaulted,omitempty"`
351
- F_BytesDefaulted []byte `protobuf:"bytes,401,opt,name=F_Bytes_defaulted,def=Bignose" json:"F_Bytes_defaulted,omitempty"`
352
- F_Sint32Defaulted *int32 `protobuf:"zigzag32,402,opt,name=F_Sint32_defaulted,def=-32" json:"F_Sint32_defaulted,omitempty"`
353
- F_Sint64Defaulted *int64 `protobuf:"zigzag64,403,opt,name=F_Sint64_defaulted,def=-64" json:"F_Sint64_defaulted,omitempty"`
354
- // Packed repeated fields (no string or bytes).
355
- F_BoolRepeatedPacked []bool `protobuf:"varint,50,rep,packed,name=F_Bool_repeated_packed" json:"F_Bool_repeated_packed,omitempty"`
356
- F_Int32RepeatedPacked []int32 `protobuf:"varint,51,rep,packed,name=F_Int32_repeated_packed" json:"F_Int32_repeated_packed,omitempty"`
357
- F_Int64RepeatedPacked []int64 `protobuf:"varint,52,rep,packed,name=F_Int64_repeated_packed" json:"F_Int64_repeated_packed,omitempty"`
358
- F_Fixed32RepeatedPacked []uint32 `protobuf:"fixed32,53,rep,packed,name=F_Fixed32_repeated_packed" json:"F_Fixed32_repeated_packed,omitempty"`
359
- F_Fixed64RepeatedPacked []uint64 `protobuf:"fixed64,54,rep,packed,name=F_Fixed64_repeated_packed" json:"F_Fixed64_repeated_packed,omitempty"`
360
- F_Uint32RepeatedPacked []uint32 `protobuf:"varint,55,rep,packed,name=F_Uint32_repeated_packed" json:"F_Uint32_repeated_packed,omitempty"`
361
- F_Uint64RepeatedPacked []uint64 `protobuf:"varint,56,rep,packed,name=F_Uint64_repeated_packed" json:"F_Uint64_repeated_packed,omitempty"`
362
- F_FloatRepeatedPacked []float32 `protobuf:"fixed32,57,rep,packed,name=F_Float_repeated_packed" json:"F_Float_repeated_packed,omitempty"`
363
- F_DoubleRepeatedPacked []float64 `protobuf:"fixed64,58,rep,packed,name=F_Double_repeated_packed" json:"F_Double_repeated_packed,omitempty"`
364
- F_Sint32RepeatedPacked []int32 `protobuf:"zigzag32,502,rep,packed,name=F_Sint32_repeated_packed" json:"F_Sint32_repeated_packed,omitempty"`
365
- F_Sint64RepeatedPacked []int64 `protobuf:"zigzag64,503,rep,packed,name=F_Sint64_repeated_packed" json:"F_Sint64_repeated_packed,omitempty"`
366
- Requiredgroup *GoTest_RequiredGroup `protobuf:"group,70,req,name=RequiredGroup" json:"requiredgroup,omitempty"`
367
- Repeatedgroup []*GoTest_RepeatedGroup `protobuf:"group,80,rep,name=RepeatedGroup" json:"repeatedgroup,omitempty"`
368
- Optionalgroup *GoTest_OptionalGroup `protobuf:"group,90,opt,name=OptionalGroup" json:"optionalgroup,omitempty"`
369
- XXX_unrecognized []byte `json:"-"`
370
-}
371
-
372
-func (m *GoTest) Reset() { *m = GoTest{} }
373
-func (m *GoTest) String() string { return proto.CompactTextString(m) }
374
-func (*GoTest) ProtoMessage() {}
375
-
376
-const Default_GoTest_F_BoolDefaulted bool = true
377
-const Default_GoTest_F_Int32Defaulted int32 = 32
378
-const Default_GoTest_F_Int64Defaulted int64 = 64
379
-const Default_GoTest_F_Fixed32Defaulted uint32 = 320
380
-const Default_GoTest_F_Fixed64Defaulted uint64 = 640
381
-const Default_GoTest_F_Uint32Defaulted uint32 = 3200
382
-const Default_GoTest_F_Uint64Defaulted uint64 = 6400
383
-const Default_GoTest_F_FloatDefaulted float32 = 314159
384
-const Default_GoTest_F_DoubleDefaulted float64 = 271828
385
-const Default_GoTest_F_StringDefaulted string = "hello, \"world!\"\n"
386
-
387
-var Default_GoTest_F_BytesDefaulted []byte = []byte("Bignose")
388
-
389
-const Default_GoTest_F_Sint32Defaulted int32 = -32
390
-const Default_GoTest_F_Sint64Defaulted int64 = -64
391
-
392
-func (m *GoTest) GetKind() GoTest_KIND {
393
- if m != nil && m.Kind != nil {
394
- return *m.Kind
395
- }
396
- return GoTest_VOID
397
-}
398
-
399
-func (m *GoTest) GetTable() string {
400
- if m != nil && m.Table != nil {
401
- return *m.Table
402
- }
403
- return ""
404
-}
405
-
406
-func (m *GoTest) GetParam() int32 {
407
- if m != nil && m.Param != nil {
408
- return *m.Param
409
- }
410
- return 0
411
-}
412
-
413
-func (m *GoTest) GetRequiredField() *GoTestField {
414
- if m != nil {
415
- return m.RequiredField
416
- }
417
- return nil
418
-}
419
-
420
-func (m *GoTest) GetRepeatedField() []*GoTestField {
421
- if m != nil {
422
- return m.RepeatedField
423
- }
424
- return nil
425
-}
426
-
427
-func (m *GoTest) GetOptionalField() *GoTestField {
428
- if m != nil {
429
- return m.OptionalField
430
- }
431
- return nil
432
-}
433
-
434
-func (m *GoTest) GetF_BoolRequired() bool {
435
- if m != nil && m.F_BoolRequired != nil {
436
- return *m.F_BoolRequired
437
- }
438
- return false
439
-}
440
-
441
-func (m *GoTest) GetF_Int32Required() int32 {
442
- if m != nil && m.F_Int32Required != nil {
443
- return *m.F_Int32Required
444
- }
445
- return 0
446
-}
447
-
448
-func (m *GoTest) GetF_Int64Required() int64 {
449
- if m != nil && m.F_Int64Required != nil {
450
- return *m.F_Int64Required
451
- }
452
- return 0
453
-}
454
-
455
-func (m *GoTest) GetF_Fixed32Required() uint32 {
456
- if m != nil && m.F_Fixed32Required != nil {
457
- return *m.F_Fixed32Required
458
- }
459
- return 0
460
-}
461
-
462
-func (m *GoTest) GetF_Fixed64Required() uint64 {
463
- if m != nil && m.F_Fixed64Required != nil {
464
- return *m.F_Fixed64Required
465
- }
466
- return 0
467
-}
468
-
469
-func (m *GoTest) GetF_Uint32Required() uint32 {
470
- if m != nil && m.F_Uint32Required != nil {
471
- return *m.F_Uint32Required
472
- }
473
- return 0
474
-}
475
-
476
-func (m *GoTest) GetF_Uint64Required() uint64 {
477
- if m != nil && m.F_Uint64Required != nil {
478
- return *m.F_Uint64Required
479
- }
480
- return 0
481
-}
482
-
483
-func (m *GoTest) GetF_FloatRequired() float32 {
484
- if m != nil && m.F_FloatRequired != nil {
485
- return *m.F_FloatRequired
486
- }
487
- return 0
488
-}
489
-
490
-func (m *GoTest) GetF_DoubleRequired() float64 {
491
- if m != nil && m.F_DoubleRequired != nil {
492
- return *m.F_DoubleRequired
493
- }
494
- return 0
495
-}
496
-
497
-func (m *GoTest) GetF_StringRequired() string {
498
- if m != nil && m.F_StringRequired != nil {
499
- return *m.F_StringRequired
500
- }
501
- return ""
502
-}
503
-
504
-func (m *GoTest) GetF_BytesRequired() []byte {
505
- if m != nil {
506
- return m.F_BytesRequired
507
- }
508
- return nil
509
-}
510
-
511
-func (m *GoTest) GetF_Sint32Required() int32 {
512
- if m != nil && m.F_Sint32Required != nil {
513
- return *m.F_Sint32Required
514
- }
515
- return 0
516
-}
517
-
518
-func (m *GoTest) GetF_Sint64Required() int64 {
519
- if m != nil && m.F_Sint64Required != nil {
520
- return *m.F_Sint64Required
521
- }
522
- return 0
523
-}
524
-
525
-func (m *GoTest) GetF_BoolRepeated() []bool {
526
- if m != nil {
527
- return m.F_BoolRepeated
528
- }
529
- return nil
530
-}
531
-
532
-func (m *GoTest) GetF_Int32Repeated() []int32 {
533
- if m != nil {
534
- return m.F_Int32Repeated
535
- }
536
- return nil
537
-}
538
-
539
-func (m *GoTest) GetF_Int64Repeated() []int64 {
540
- if m != nil {
541
- return m.F_Int64Repeated
542
- }
543
- return nil
544
-}
545
-
546
-func (m *GoTest) GetF_Fixed32Repeated() []uint32 {
547
- if m != nil {
548
- return m.F_Fixed32Repeated
549
- }
550
- return nil
551
-}
552
-
553
-func (m *GoTest) GetF_Fixed64Repeated() []uint64 {
554
- if m != nil {
555
- return m.F_Fixed64Repeated
556
- }
557
- return nil
558
-}
559
-
560
-func (m *GoTest) GetF_Uint32Repeated() []uint32 {
561
- if m != nil {
562
- return m.F_Uint32Repeated
563
- }
564
- return nil
565
-}
566
-
567
-func (m *GoTest) GetF_Uint64Repeated() []uint64 {
568
- if m != nil {
569
- return m.F_Uint64Repeated
570
- }
571
- return nil
572
-}
573
-
574
-func (m *GoTest) GetF_FloatRepeated() []float32 {
575
- if m != nil {
576
- return m.F_FloatRepeated
577
- }
578
- return nil
579
-}
580
-
581
-func (m *GoTest) GetF_DoubleRepeated() []float64 {
582
- if m != nil {
583
- return m.F_DoubleRepeated
584
- }
585
- return nil
586
-}
587
-
588
-func (m *GoTest) GetF_StringRepeated() []string {
589
- if m != nil {
590
- return m.F_StringRepeated
591
- }
592
- return nil
593
-}
594
-
595
-func (m *GoTest) GetF_BytesRepeated() [][]byte {
596
- if m != nil {
597
- return m.F_BytesRepeated
598
- }
599
- return nil
600
-}
601
-
602
-func (m *GoTest) GetF_Sint32Repeated() []int32 {
603
- if m != nil {
604
- return m.F_Sint32Repeated
605
- }
606
- return nil
607
-}
608
-
609
-func (m *GoTest) GetF_Sint64Repeated() []int64 {
610
- if m != nil {
611
- return m.F_Sint64Repeated
612
- }
613
- return nil
614
-}
615
-
616
-func (m *GoTest) GetF_BoolOptional() bool {
617
- if m != nil && m.F_BoolOptional != nil {
618
- return *m.F_BoolOptional
619
- }
620
- return false
621
-}
622
-
623
-func (m *GoTest) GetF_Int32Optional() int32 {
624
- if m != nil && m.F_Int32Optional != nil {
625
- return *m.F_Int32Optional
626
- }
627
- return 0
628
-}
629
-
630
-func (m *GoTest) GetF_Int64Optional() int64 {
631
- if m != nil && m.F_Int64Optional != nil {
632
- return *m.F_Int64Optional
633
- }
634
- return 0
635
-}
636
-
637
-func (m *GoTest) GetF_Fixed32Optional() uint32 {
638
- if m != nil && m.F_Fixed32Optional != nil {
639
- return *m.F_Fixed32Optional
640
- }
641
- return 0
642
-}
643
-
644
-func (m *GoTest) GetF_Fixed64Optional() uint64 {
645
- if m != nil && m.F_Fixed64Optional != nil {
646
- return *m.F_Fixed64Optional
647
- }
648
- return 0
649
-}
650
-
651
-func (m *GoTest) GetF_Uint32Optional() uint32 {
652
- if m != nil && m.F_Uint32Optional != nil {
653
- return *m.F_Uint32Optional
654
- }
655
- return 0
656
-}
657
-
658
-func (m *GoTest) GetF_Uint64Optional() uint64 {
659
- if m != nil && m.F_Uint64Optional != nil {
660
- return *m.F_Uint64Optional
661
- }
662
- return 0
663
-}
664
-
665
-func (m *GoTest) GetF_FloatOptional() float32 {
666
- if m != nil && m.F_FloatOptional != nil {
667
- return *m.F_FloatOptional
668
- }
669
- return 0
670
-}
671
-
672
-func (m *GoTest) GetF_DoubleOptional() float64 {
673
- if m != nil && m.F_DoubleOptional != nil {
674
- return *m.F_DoubleOptional
675
- }
676
- return 0
677
-}
678
-
679
-func (m *GoTest) GetF_StringOptional() string {
680
- if m != nil && m.F_StringOptional != nil {
681
- return *m.F_StringOptional
682
- }
683
- return ""
684
-}
685
-
686
-func (m *GoTest) GetF_BytesOptional() []byte {
687
- if m != nil {
688
- return m.F_BytesOptional
689
- }
690
- return nil
691
-}
692
-
693
-func (m *GoTest) GetF_Sint32Optional() int32 {
694
- if m != nil && m.F_Sint32Optional != nil {
695
- return *m.F_Sint32Optional
696
- }
697
- return 0
698
-}
699
-
700
-func (m *GoTest) GetF_Sint64Optional() int64 {
701
- if m != nil && m.F_Sint64Optional != nil {
702
- return *m.F_Sint64Optional
703
- }
704
- return 0
705
-}
706
-
707
-func (m *GoTest) GetF_BoolDefaulted() bool {
708
- if m != nil && m.F_BoolDefaulted != nil {
709
- return *m.F_BoolDefaulted
710
- }
711
- return Default_GoTest_F_BoolDefaulted
712
-}
713
-
714
-func (m *GoTest) GetF_Int32Defaulted() int32 {
715
- if m != nil && m.F_Int32Defaulted != nil {
716
- return *m.F_Int32Defaulted
717
- }
718
- return Default_GoTest_F_Int32Defaulted
719
-}
720
-
721
-func (m *GoTest) GetF_Int64Defaulted() int64 {
722
- if m != nil && m.F_Int64Defaulted != nil {
723
- return *m.F_Int64Defaulted
724
- }
725
- return Default_GoTest_F_Int64Defaulted
726
-}
727
-
728
-func (m *GoTest) GetF_Fixed32Defaulted() uint32 {
729
- if m != nil && m.F_Fixed32Defaulted != nil {
730
- return *m.F_Fixed32Defaulted
731
- }
732
- return Default_GoTest_F_Fixed32Defaulted
733
-}
734
-
735
-func (m *GoTest) GetF_Fixed64Defaulted() uint64 {
736
- if m != nil && m.F_Fixed64Defaulted != nil {
737
- return *m.F_Fixed64Defaulted
738
- }
739
- return Default_GoTest_F_Fixed64Defaulted
740
-}
741
-
742
-func (m *GoTest) GetF_Uint32Defaulted() uint32 {
743
- if m != nil && m.F_Uint32Defaulted != nil {
744
- return *m.F_Uint32Defaulted
745
- }
746
- return Default_GoTest_F_Uint32Defaulted
747
-}
748
-
749
-func (m *GoTest) GetF_Uint64Defaulted() uint64 {
750
- if m != nil && m.F_Uint64Defaulted != nil {
751
- return *m.F_Uint64Defaulted
752
- }
753
- return Default_GoTest_F_Uint64Defaulted
754
-}
755
-
756
-func (m *GoTest) GetF_FloatDefaulted() float32 {
757
- if m != nil && m.F_FloatDefaulted != nil {
758
- return *m.F_FloatDefaulted
759
- }
760
- return Default_GoTest_F_FloatDefaulted
761
-}
762
-
763
-func (m *GoTest) GetF_DoubleDefaulted() float64 {
764
- if m != nil && m.F_DoubleDefaulted != nil {
765
- return *m.F_DoubleDefaulted
766
- }
767
- return Default_GoTest_F_DoubleDefaulted
768
-}
769
-
770
-func (m *GoTest) GetF_StringDefaulted() string {
771
- if m != nil && m.F_StringDefaulted != nil {
772
- return *m.F_StringDefaulted
773
- }
774
- return Default_GoTest_F_StringDefaulted
775
-}
776
-
777
-func (m *GoTest) GetF_BytesDefaulted() []byte {
778
- if m != nil && m.F_BytesDefaulted != nil {
779
- return m.F_BytesDefaulted
780
- }
781
- return append([]byte(nil), Default_GoTest_F_BytesDefaulted...)
782
-}
783
-
784
-func (m *GoTest) GetF_Sint32Defaulted() int32 {
785
- if m != nil && m.F_Sint32Defaulted != nil {
786
- return *m.F_Sint32Defaulted
787
- }
788
- return Default_GoTest_F_Sint32Defaulted
789
-}
790
-
791
-func (m *GoTest) GetF_Sint64Defaulted() int64 {
792
- if m != nil && m.F_Sint64Defaulted != nil {
793
- return *m.F_Sint64Defaulted
794
- }
795
- return Default_GoTest_F_Sint64Defaulted
796
-}
797
-
798
-func (m *GoTest) GetF_BoolRepeatedPacked() []bool {
799
- if m != nil {
800
- return m.F_BoolRepeatedPacked
801
- }
802
- return nil
803
-}
804
-
805
-func (m *GoTest) GetF_Int32RepeatedPacked() []int32 {
806
- if m != nil {
807
- return m.F_Int32RepeatedPacked
808
- }
809
- return nil
810
-}
811
-
812
-func (m *GoTest) GetF_Int64RepeatedPacked() []int64 {
813
- if m != nil {
814
- return m.F_Int64RepeatedPacked
815
- }
816
- return nil
817
-}
818
-
819
-func (m *GoTest) GetF_Fixed32RepeatedPacked() []uint32 {
820
- if m != nil {
821
- return m.F_Fixed32RepeatedPacked
822
- }
823
- return nil
824
-}
825
-
826
-func (m *GoTest) GetF_Fixed64RepeatedPacked() []uint64 {
827
- if m != nil {
828
- return m.F_Fixed64RepeatedPacked
829
- }
830
- return nil
831
-}
832
-
833
-func (m *GoTest) GetF_Uint32RepeatedPacked() []uint32 {
834
- if m != nil {
835
- return m.F_Uint32RepeatedPacked
836
- }
837
- return nil
838
-}
839
-
840
-func (m *GoTest) GetF_Uint64RepeatedPacked() []uint64 {
841
- if m != nil {
842
- return m.F_Uint64RepeatedPacked
843
- }
844
- return nil
845
-}
846
-
847
-func (m *GoTest) GetF_FloatRepeatedPacked() []float32 {
848
- if m != nil {
849
- return m.F_FloatRepeatedPacked
850
- }
851
- return nil
852
-}
853
-
854
-func (m *GoTest) GetF_DoubleRepeatedPacked() []float64 {
855
- if m != nil {
856
- return m.F_DoubleRepeatedPacked
857
- }
858
- return nil
859
-}
860
-
861
-func (m *GoTest) GetF_Sint32RepeatedPacked() []int32 {
862
- if m != nil {
863
- return m.F_Sint32RepeatedPacked
864
- }
865
- return nil
866
-}
867
-
868
-func (m *GoTest) GetF_Sint64RepeatedPacked() []int64 {
869
- if m != nil {
870
- return m.F_Sint64RepeatedPacked
871
- }
872
- return nil
873
-}
874
-
875
-func (m *GoTest) GetRequiredgroup() *GoTest_RequiredGroup {
876
- if m != nil {
877
- return m.Requiredgroup
878
- }
879
- return nil
880
-}
881
-
882
-func (m *GoTest) GetRepeatedgroup() []*GoTest_RepeatedGroup {
883
- if m != nil {
884
- return m.Repeatedgroup
885
- }
886
- return nil
887
-}
888
-
889
-func (m *GoTest) GetOptionalgroup() *GoTest_OptionalGroup {
890
- if m != nil {
891
- return m.Optionalgroup
892
- }
893
- return nil
894
-}
895
-
896
-// Required, repeated, and optional groups.
897
-type GoTest_RequiredGroup struct {
898
- RequiredField *string `protobuf:"bytes,71,req" json:"RequiredField,omitempty"`
899
- XXX_unrecognized []byte `json:"-"`
900
-}
901
-
902
-func (m *GoTest_RequiredGroup) Reset() { *m = GoTest_RequiredGroup{} }
903
-func (m *GoTest_RequiredGroup) String() string { return proto.CompactTextString(m) }
904
-func (*GoTest_RequiredGroup) ProtoMessage() {}
905
-
906
-func (m *GoTest_RequiredGroup) GetRequiredField() string {
907
- if m != nil && m.RequiredField != nil {
908
- return *m.RequiredField
909
- }
910
- return ""
911
-}
912
-
913
-type GoTest_RepeatedGroup struct {
914
- RequiredField *string `protobuf:"bytes,81,req" json:"RequiredField,omitempty"`
915
- XXX_unrecognized []byte `json:"-"`
916
-}
917
-
918
-func (m *GoTest_RepeatedGroup) Reset() { *m = GoTest_RepeatedGroup{} }
919
-func (m *GoTest_RepeatedGroup) String() string { return proto.CompactTextString(m) }
920
-func (*GoTest_RepeatedGroup) ProtoMessage() {}
921
-
922
-func (m *GoTest_RepeatedGroup) GetRequiredField() string {
923
- if m != nil && m.RequiredField != nil {
924
- return *m.RequiredField
925
- }
926
- return ""
927
-}
928
-
929
-type GoTest_OptionalGroup struct {
930
- RequiredField *string `protobuf:"bytes,91,req" json:"RequiredField,omitempty"`
931
- XXX_unrecognized []byte `json:"-"`
932
-}
933
-
934
-func (m *GoTest_OptionalGroup) Reset() { *m = GoTest_OptionalGroup{} }
935
-func (m *GoTest_OptionalGroup) String() string { return proto.CompactTextString(m) }
936
-func (*GoTest_OptionalGroup) ProtoMessage() {}
937
-
938
-func (m *GoTest_OptionalGroup) GetRequiredField() string {
939
- if m != nil && m.RequiredField != nil {
940
- return *m.RequiredField
941
- }
942
- return ""
943
-}
944
-
945
-// For testing skipping of unrecognized fields.
946
-// Numbers are all big, larger than tag numbers in GoTestField,
947
-// the message used in the corresponding test.
948
-type GoSkipTest struct {
949
- SkipInt32 *int32 `protobuf:"varint,11,req,name=skip_int32" json:"skip_int32,omitempty"`
950
- SkipFixed32 *uint32 `protobuf:"fixed32,12,req,name=skip_fixed32" json:"skip_fixed32,omitempty"`
951
- SkipFixed64 *uint64 `protobuf:"fixed64,13,req,name=skip_fixed64" json:"skip_fixed64,omitempty"`
952
- SkipString *string `protobuf:"bytes,14,req,name=skip_string" json:"skip_string,omitempty"`
953
- Skipgroup *GoSkipTest_SkipGroup `protobuf:"group,15,req,name=SkipGroup" json:"skipgroup,omitempty"`
954
- XXX_unrecognized []byte `json:"-"`
955
-}
956
-
957
-func (m *GoSkipTest) Reset() { *m = GoSkipTest{} }
958
-func (m *GoSkipTest) String() string { return proto.CompactTextString(m) }
959
-func (*GoSkipTest) ProtoMessage() {}
960
-
961
-func (m *GoSkipTest) GetSkipInt32() int32 {
962
- if m != nil && m.SkipInt32 != nil {
963
- return *m.SkipInt32
964
- }
965
- return 0
966
-}
967
-
968
-func (m *GoSkipTest) GetSkipFixed32() uint32 {
969
- if m != nil && m.SkipFixed32 != nil {
970
- return *m.SkipFixed32
971
- }
972
- return 0
973
-}
974
-
975
-func (m *GoSkipTest) GetSkipFixed64() uint64 {
976
- if m != nil && m.SkipFixed64 != nil {
977
- return *m.SkipFixed64
978
- }
979
- return 0
980
-}
981
-
982
-func (m *GoSkipTest) GetSkipString() string {
983
- if m != nil && m.SkipString != nil {
984
- return *m.SkipString
985
- }
986
- return ""
987
-}
988
-
989
-func (m *GoSkipTest) GetSkipgroup() *GoSkipTest_SkipGroup {
990
- if m != nil {
991
- return m.Skipgroup
992
- }
993
- return nil
994
-}
995
-
996
-type GoSkipTest_SkipGroup struct {
997
- GroupInt32 *int32 `protobuf:"varint,16,req,name=group_int32" json:"group_int32,omitempty"`
998
- GroupString *string `protobuf:"bytes,17,req,name=group_string" json:"group_string,omitempty"`
999
- XXX_unrecognized []byte `json:"-"`
1000
-}
1001
-
1002
-func (m *GoSkipTest_SkipGroup) Reset() { *m = GoSkipTest_SkipGroup{} }
1003
-func (m *GoSkipTest_SkipGroup) String() string { return proto.CompactTextString(m) }
1004
-func (*GoSkipTest_SkipGroup) ProtoMessage() {}
1005
-
1006
-func (m *GoSkipTest_SkipGroup) GetGroupInt32() int32 {
1007
- if m != nil && m.GroupInt32 != nil {
1008
- return *m.GroupInt32
1009
- }
1010
- return 0
1011
-}
1012
-
1013
-func (m *GoSkipTest_SkipGroup) GetGroupString() string {
1014
- if m != nil && m.GroupString != nil {
1015
- return *m.GroupString
1016
- }
1017
- return ""
1018
-}
1019
-
1020
-// For testing packed/non-packed decoder switching.
1021
-// A serialized instance of one should be deserializable as the other.
1022
-type NonPackedTest struct {
1023
- A []int32 `protobuf:"varint,1,rep,name=a" json:"a,omitempty"`
1024
- XXX_unrecognized []byte `json:"-"`
1025
-}
1026
-
1027
-func (m *NonPackedTest) Reset() { *m = NonPackedTest{} }
1028
-func (m *NonPackedTest) String() string { return proto.CompactTextString(m) }
1029
-func (*NonPackedTest) ProtoMessage() {}
1030
-
1031
-func (m *NonPackedTest) GetA() []int32 {
1032
- if m != nil {
1033
- return m.A
1034
- }
1035
- return nil
1036
-}
1037
-
1038
-type PackedTest struct {
1039
- B []int32 `protobuf:"varint,1,rep,packed,name=b" json:"b,omitempty"`
1040
- XXX_unrecognized []byte `json:"-"`
1041
-}
1042
-
1043
-func (m *PackedTest) Reset() { *m = PackedTest{} }
1044
-func (m *PackedTest) String() string { return proto.CompactTextString(m) }
1045
-func (*PackedTest) ProtoMessage() {}
1046
-
1047
-func (m *PackedTest) GetB() []int32 {
1048
- if m != nil {
1049
- return m.B
1050
- }
1051
- return nil
1052
-}
1053
-
1054
-type MaxTag struct {
1055
- // Maximum possible tag number.
1056
- LastField *string `protobuf:"bytes,536870911,opt,name=last_field" json:"last_field,omitempty"`
1057
- XXX_unrecognized []byte `json:"-"`
1058
-}
1059
-
1060
-func (m *MaxTag) Reset() { *m = MaxTag{} }
1061
-func (m *MaxTag) String() string { return proto.CompactTextString(m) }
1062
-func (*MaxTag) ProtoMessage() {}
1063
-
1064
-func (m *MaxTag) GetLastField() string {
1065
- if m != nil && m.LastField != nil {
1066
- return *m.LastField
1067
- }
1068
- return ""
1069
-}
1070
-
1071
-type OldMessage struct {
1072
- Nested *OldMessage_Nested `protobuf:"bytes,1,opt,name=nested" json:"nested,omitempty"`
1073
- XXX_unrecognized []byte `json:"-"`
1074
-}
1075
-
1076
-func (m *OldMessage) Reset() { *m = OldMessage{} }
1077
-func (m *OldMessage) String() string { return proto.CompactTextString(m) }
1078
-func (*OldMessage) ProtoMessage() {}
1079
-
1080
-func (m *OldMessage) GetNested() *OldMessage_Nested {
1081
- if m != nil {
1082
- return m.Nested
1083
- }
1084
- return nil
1085
-}
1086
-
1087
-type OldMessage_Nested struct {
1088
- Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
1089
- XXX_unrecognized []byte `json:"-"`
1090
-}
1091
-
1092
-func (m *OldMessage_Nested) Reset() { *m = OldMessage_Nested{} }
1093
-func (m *OldMessage_Nested) String() string { return proto.CompactTextString(m) }
1094
-func (*OldMessage_Nested) ProtoMessage() {}
1095
-
1096
-func (m *OldMessage_Nested) GetName() string {
1097
- if m != nil && m.Name != nil {
1098
- return *m.Name
1099
- }
1100
- return ""
1101
-}
1102
-
1103
-// NewMessage is wire compatible with OldMessage;
1104
-// imagine it as a future version.
1105
-type NewMessage struct {
1106
- Nested *NewMessage_Nested `protobuf:"bytes,1,opt,name=nested" json:"nested,omitempty"`
1107
- XXX_unrecognized []byte `json:"-"`
1108
-}
1109
-
1110
-func (m *NewMessage) Reset() { *m = NewMessage{} }
1111
-func (m *NewMessage) String() string { return proto.CompactTextString(m) }
1112
-func (*NewMessage) ProtoMessage() {}
1113
-
1114
-func (m *NewMessage) GetNested() *NewMessage_Nested {
1115
- if m != nil {
1116
- return m.Nested
1117
- }
1118
- return nil
1119
-}
1120
-
1121
-type NewMessage_Nested struct {
1122
- Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
1123
- FoodGroup *string `protobuf:"bytes,2,opt,name=food_group" json:"food_group,omitempty"`
1124
- XXX_unrecognized []byte `json:"-"`
1125
-}
1126
-
1127
-func (m *NewMessage_Nested) Reset() { *m = NewMessage_Nested{} }
1128
-func (m *NewMessage_Nested) String() string { return proto.CompactTextString(m) }
1129
-func (*NewMessage_Nested) ProtoMessage() {}
1130
-
1131
-func (m *NewMessage_Nested) GetName() string {
1132
- if m != nil && m.Name != nil {
1133
- return *m.Name
1134
- }
1135
- return ""
1136
-}
1137
-
1138
-func (m *NewMessage_Nested) GetFoodGroup() string {
1139
- if m != nil && m.FoodGroup != nil {
1140
- return *m.FoodGroup
1141
- }
1142
- return ""
1143
-}
1144
-
1145
-type InnerMessage struct {
1146
- Host *string `protobuf:"bytes,1,req,name=host" json:"host,omitempty"`
1147
- Port *int32 `protobuf:"varint,2,opt,name=port,def=4000" json:"port,omitempty"`
1148
- Connected *bool `protobuf:"varint,3,opt,name=connected" json:"connected,omitempty"`
1149
- XXX_unrecognized []byte `json:"-"`
1150
-}
1151
-
1152
-func (m *InnerMessage) Reset() { *m = InnerMessage{} }
1153
-func (m *InnerMessage) String() string { return proto.CompactTextString(m) }
1154
-func (*InnerMessage) ProtoMessage() {}
1155
-
1156
-const Default_InnerMessage_Port int32 = 4000
1157
-
1158
-func (m *InnerMessage) GetHost() string {
1159
- if m != nil && m.Host != nil {
1160
- return *m.Host
1161
- }
1162
- return ""
1163
-}
1164
-
1165
-func (m *InnerMessage) GetPort() int32 {
1166
- if m != nil && m.Port != nil {
1167
- return *m.Port
1168
- }
1169
- return Default_InnerMessage_Port
1170
-}
1171
-
1172
-func (m *InnerMessage) GetConnected() bool {
1173
- if m != nil && m.Connected != nil {
1174
- return *m.Connected
1175
- }
1176
- return false
1177
-}
1178
-
1179
-type OtherMessage struct {
1180
- Key *int64 `protobuf:"varint,1,opt,name=key" json:"key,omitempty"`
1181
- Value []byte `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
1182
- Weight *float32 `protobuf:"fixed32,3,opt,name=weight" json:"weight,omitempty"`
1183
- Inner *InnerMessage `protobuf:"bytes,4,opt,name=inner" json:"inner,omitempty"`
1184
- XXX_unrecognized []byte `json:"-"`
1185
-}
1186
-
1187
-func (m *OtherMessage) Reset() { *m = OtherMessage{} }
1188
-func (m *OtherMessage) String() string { return proto.CompactTextString(m) }
1189
-func (*OtherMessage) ProtoMessage() {}
1190
-
1191
-func (m *OtherMessage) GetKey() int64 {
1192
- if m != nil && m.Key != nil {
1193
- return *m.Key
1194
- }
1195
- return 0
1196
-}
1197
-
1198
-func (m *OtherMessage) GetValue() []byte {
1199
- if m != nil {
1200
- return m.Value
1201
- }
1202
- return nil
1203
-}
1204
-
1205
-func (m *OtherMessage) GetWeight() float32 {
1206
- if m != nil && m.Weight != nil {
1207
- return *m.Weight
1208
- }
1209
- return 0
1210
-}
1211
-
1212
-func (m *OtherMessage) GetInner() *InnerMessage {
1213
- if m != nil {
1214
- return m.Inner
1215
- }
1216
- return nil
1217
-}
1218
-
1219
-type MyMessage struct {
1220
- Count *int32 `protobuf:"varint,1,req,name=count" json:"count,omitempty"`
1221
- Name *string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
1222
- Quote *string `protobuf:"bytes,3,opt,name=quote" json:"quote,omitempty"`
1223
- Pet []string `protobuf:"bytes,4,rep,name=pet" json:"pet,omitempty"`
1224
- Inner *InnerMessage `protobuf:"bytes,5,opt,name=inner" json:"inner,omitempty"`
1225
- Others []*OtherMessage `protobuf:"bytes,6,rep,name=others" json:"others,omitempty"`
1226
- RepInner []*InnerMessage `protobuf:"bytes,12,rep,name=rep_inner" json:"rep_inner,omitempty"`
1227
- Bikeshed *MyMessage_Color `protobuf:"varint,7,opt,name=bikeshed,enum=testdata.MyMessage_Color" json:"bikeshed,omitempty"`
1228
- Somegroup *MyMessage_SomeGroup `protobuf:"group,8,opt,name=SomeGroup" json:"somegroup,omitempty"`
1229
- // This field becomes [][]byte in the generated code.
1230
- RepBytes [][]byte `protobuf:"bytes,10,rep,name=rep_bytes" json:"rep_bytes,omitempty"`
1231
- Bigfloat *float64 `protobuf:"fixed64,11,opt,name=bigfloat" json:"bigfloat,omitempty"`
1232
- XXX_extensions map[int32]proto.Extension `json:"-"`
1233
- XXX_unrecognized []byte `json:"-"`
1234
-}
1235
-
1236
-func (m *MyMessage) Reset() { *m = MyMessage{} }
1237
-func (m *MyMessage) String() string { return proto.CompactTextString(m) }
1238
-func (*MyMessage) ProtoMessage() {}
1239
-
1240
-var extRange_MyMessage = []proto.ExtensionRange{
1241
- {100, 536870911},
1242
-}
1243
-
1244
-func (*MyMessage) ExtensionRangeArray() []proto.ExtensionRange {
1245
- return extRange_MyMessage
1246
-}
1247
-func (m *MyMessage) ExtensionMap() map[int32]proto.Extension {
1248
- if m.XXX_extensions == nil {
1249
- m.XXX_extensions = make(map[int32]proto.Extension)
1250
- }
1251
- return m.XXX_extensions
1252
-}
1253
-
1254
-func (m *MyMessage) GetCount() int32 {
1255
- if m != nil && m.Count != nil {
1256
- return *m.Count
1257
- }
1258
- return 0
1259
-}
1260
-
1261
-func (m *MyMessage) GetName() string {
1262
- if m != nil && m.Name != nil {
1263
- return *m.Name
1264
- }
1265
- return ""
1266
-}
1267
-
1268
-func (m *MyMessage) GetQuote() string {
1269
- if m != nil && m.Quote != nil {
1270
- return *m.Quote
1271
- }
1272
- return ""
1273
-}
1274
-
1275
-func (m *MyMessage) GetPet() []string {
1276
- if m != nil {
1277
- return m.Pet
1278
- }
1279
- return nil
1280
-}
1281
-
1282
-func (m *MyMessage) GetInner() *InnerMessage {
1283
- if m != nil {
1284
- return m.Inner
1285
- }
1286
- return nil
1287
-}
1288
-
1289
-func (m *MyMessage) GetOthers() []*OtherMessage {
1290
- if m != nil {
1291
- return m.Others
1292
- }
1293
- return nil
1294
-}
1295
-
1296
-func (m *MyMessage) GetRepInner() []*InnerMessage {
1297
- if m != nil {
1298
- return m.RepInner
1299
- }
1300
- return nil
1301
-}
1302
-
1303
-func (m *MyMessage) GetBikeshed() MyMessage_Color {
1304
- if m != nil && m.Bikeshed != nil {
1305
- return *m.Bikeshed
1306
- }
1307
- return MyMessage_RED
1308
-}
1309
-
1310
-func (m *MyMessage) GetSomegroup() *MyMessage_SomeGroup {
1311
- if m != nil {
1312
- return m.Somegroup
1313
- }
1314
- return nil
1315
-}
1316
-
1317
-func (m *MyMessage) GetRepBytes() [][]byte {
1318
- if m != nil {
1319
- return m.RepBytes
1320
- }
1321
- return nil
1322
-}
1323
-
1324
-func (m *MyMessage) GetBigfloat() float64 {
1325
- if m != nil && m.Bigfloat != nil {
1326
- return *m.Bigfloat
1327
- }
1328
- return 0
1329
-}
1330
-
1331
-type MyMessage_SomeGroup struct {
1332
- GroupField *int32 `protobuf:"varint,9,opt,name=group_field" json:"group_field,omitempty"`
1333
- XXX_unrecognized []byte `json:"-"`
1334
-}
1335
-
1336
-func (m *MyMessage_SomeGroup) Reset() { *m = MyMessage_SomeGroup{} }
1337
-func (m *MyMessage_SomeGroup) String() string { return proto.CompactTextString(m) }
1338
-func (*MyMessage_SomeGroup) ProtoMessage() {}
1339
-
1340
-func (m *MyMessage_SomeGroup) GetGroupField() int32 {
1341
- if m != nil && m.GroupField != nil {
1342
- return *m.GroupField
1343
- }
1344
- return 0
1345
-}
1346
-
1347
-type Ext struct {
1348
- Data *string `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
1349
- XXX_unrecognized []byte `json:"-"`
1350
-}
1351
-
1352
-func (m *Ext) Reset() { *m = Ext{} }
1353
-func (m *Ext) String() string { return proto.CompactTextString(m) }
1354
-func (*Ext) ProtoMessage() {}
1355
-
1356
-func (m *Ext) GetData() string {
1357
- if m != nil && m.Data != nil {
1358
- return *m.Data
1359
- }
1360
- return ""
1361
-}
1362
-
1363
-var E_Ext_More = &proto.ExtensionDesc{
1364
- ExtendedType: (*MyMessage)(nil),
1365
- ExtensionType: (*Ext)(nil),
1366
- Field: 103,
1367
- Name: "testdata.Ext.more",
1368
- Tag: "bytes,103,opt,name=more",
1369
-}
1370
-
1371
-var E_Ext_Text = &proto.ExtensionDesc{
1372
- ExtendedType: (*MyMessage)(nil),
1373
- ExtensionType: (*string)(nil),
1374
- Field: 104,
1375
- Name: "testdata.Ext.text",
1376
- Tag: "bytes,104,opt,name=text",
1377
-}
1378
-
1379
-var E_Ext_Number = &proto.ExtensionDesc{
1380
- ExtendedType: (*MyMessage)(nil),
1381
- ExtensionType: (*int32)(nil),
1382
- Field: 105,
1383
- Name: "testdata.Ext.number",
1384
- Tag: "varint,105,opt,name=number",
1385
-}
1386
-
1387
-type MyMessageSet struct {
1388
- XXX_extensions map[int32]proto.Extension `json:"-"`
1389
- XXX_unrecognized []byte `json:"-"`
1390
-}
1391
-
1392
-func (m *MyMessageSet) Reset() { *m = MyMessageSet{} }
1393
-func (m *MyMessageSet) String() string { return proto.CompactTextString(m) }
1394
-func (*MyMessageSet) ProtoMessage() {}
1395
-
1396
-func (m *MyMessageSet) Marshal() ([]byte, error) {
1397
- return proto.MarshalMessageSet(m.ExtensionMap())
1398
-}
1399
-func (m *MyMessageSet) Unmarshal(buf []byte) error {
1400
- return proto.UnmarshalMessageSet(buf, m.ExtensionMap())
1401
-}
1402
-
1403
-// ensure MyMessageSet satisfies proto.Marshaler and proto.Unmarshaler
1404
-var _ proto.Marshaler = (*MyMessageSet)(nil)
1405
-var _ proto.Unmarshaler = (*MyMessageSet)(nil)
1406
-
1407
-var extRange_MyMessageSet = []proto.ExtensionRange{
1408
- {100, 2147483646},
1409
-}
1410
-
1411
-func (*MyMessageSet) ExtensionRangeArray() []proto.ExtensionRange {
1412
- return extRange_MyMessageSet
1413
-}
1414
-func (m *MyMessageSet) ExtensionMap() map[int32]proto.Extension {
1415
- if m.XXX_extensions == nil {
1416
- m.XXX_extensions = make(map[int32]proto.Extension)
1417
- }
1418
- return m.XXX_extensions
1419
-}
1420
-
1421
-type Empty struct {
1422
- XXX_unrecognized []byte `json:"-"`
1423
-}
1424
-
1425
-func (m *Empty) Reset() { *m = Empty{} }
1426
-func (m *Empty) String() string { return proto.CompactTextString(m) }
1427
-func (*Empty) ProtoMessage() {}
1428
-
1429
-type MessageList struct {
1430
- Message []*MessageList_Message `protobuf:"group,1,rep" json:"message,omitempty"`
1431
- XXX_unrecognized []byte `json:"-"`
1432
-}
1433
-
1434
-func (m *MessageList) Reset() { *m = MessageList{} }
1435
-func (m *MessageList) String() string { return proto.CompactTextString(m) }
1436
-func (*MessageList) ProtoMessage() {}
1437
-
1438
-func (m *MessageList) GetMessage() []*MessageList_Message {
1439
- if m != nil {
1440
- return m.Message
1441
- }
1442
- return nil
1443
-}
1444
-
1445
-type MessageList_Message struct {
1446
- Name *string `protobuf:"bytes,2,req,name=name" json:"name,omitempty"`
1447
- Count *int32 `protobuf:"varint,3,req,name=count" json:"count,omitempty"`
1448
- XXX_unrecognized []byte `json:"-"`
1449
-}
1450
-
1451
-func (m *MessageList_Message) Reset() { *m = MessageList_Message{} }
1452
-func (m *MessageList_Message) String() string { return proto.CompactTextString(m) }
1453
-func (*MessageList_Message) ProtoMessage() {}
1454
-
1455
-func (m *MessageList_Message) GetName() string {
1456
- if m != nil && m.Name != nil {
1457
- return *m.Name
1458
- }
1459
- return ""
1460
-}
1461
-
1462
-func (m *MessageList_Message) GetCount() int32 {
1463
- if m != nil && m.Count != nil {
1464
- return *m.Count
1465
- }
1466
- return 0
1467
-}
1468
-
1469
-type Strings struct {
1470
- StringField *string `protobuf:"bytes,1,opt,name=string_field" json:"string_field,omitempty"`
1471
- BytesField []byte `protobuf:"bytes,2,opt,name=bytes_field" json:"bytes_field,omitempty"`
1472
- XXX_unrecognized []byte `json:"-"`
1473
-}
1474
-
1475
-func (m *Strings) Reset() { *m = Strings{} }
1476
-func (m *Strings) String() string { return proto.CompactTextString(m) }
1477
-func (*Strings) ProtoMessage() {}
1478
-
1479
-func (m *Strings) GetStringField() string {
1480
- if m != nil && m.StringField != nil {
1481
- return *m.StringField
1482
- }
1483
- return ""
1484
-}
1485
-
1486
-func (m *Strings) GetBytesField() []byte {
1487
- if m != nil {
1488
- return m.BytesField
1489
- }
1490
- return nil
1491
-}
1492
-
1493
-type Defaults struct {
1494
- // Default-valued fields of all basic types.
1495
- // Same as GoTest, but copied here to make testing easier.
1496
- F_Bool *bool `protobuf:"varint,1,opt,def=1" json:"F_Bool,omitempty"`
1497
- F_Int32 *int32 `protobuf:"varint,2,opt,def=32" json:"F_Int32,omitempty"`
1498
- F_Int64 *int64 `protobuf:"varint,3,opt,def=64" json:"F_Int64,omitempty"`
1499
- F_Fixed32 *uint32 `protobuf:"fixed32,4,opt,def=320" json:"F_Fixed32,omitempty"`
1500
- F_Fixed64 *uint64 `protobuf:"fixed64,5,opt,def=640" json:"F_Fixed64,omitempty"`
1501
- F_Uint32 *uint32 `protobuf:"varint,6,opt,def=3200" json:"F_Uint32,omitempty"`
1502
- F_Uint64 *uint64 `protobuf:"varint,7,opt,def=6400" json:"F_Uint64,omitempty"`
1503
- F_Float *float32 `protobuf:"fixed32,8,opt,def=314159" json:"F_Float,omitempty"`
1504
- F_Double *float64 `protobuf:"fixed64,9,opt,def=271828" json:"F_Double,omitempty"`
1505
- F_String *string `protobuf:"bytes,10,opt,def=hello, \"world!\"\n" json:"F_String,omitempty"`
1506
- F_Bytes []byte `protobuf:"bytes,11,opt,def=Bignose" json:"F_Bytes,omitempty"`
1507
- F_Sint32 *int32 `protobuf:"zigzag32,12,opt,def=-32" json:"F_Sint32,omitempty"`
1508
- F_Sint64 *int64 `protobuf:"zigzag64,13,opt,def=-64" json:"F_Sint64,omitempty"`
1509
- F_Enum *Defaults_Color `protobuf:"varint,14,opt,enum=testdata.Defaults_Color,def=1" json:"F_Enum,omitempty"`
1510
- // More fields with crazy defaults.
1511
- F_Pinf *float32 `protobuf:"fixed32,15,opt,def=inf" json:"F_Pinf,omitempty"`
1512
- F_Ninf *float32 `protobuf:"fixed32,16,opt,def=-inf" json:"F_Ninf,omitempty"`
1513
- F_Nan *float32 `protobuf:"fixed32,17,opt,def=nan" json:"F_Nan,omitempty"`
1514
- // Sub-message.
1515
- Sub *SubDefaults `protobuf:"bytes,18,opt,name=sub" json:"sub,omitempty"`
1516
- XXX_unrecognized []byte `json:"-"`
1517
-}
1518
-
1519
-func (m *Defaults) Reset() { *m = Defaults{} }
1520
-func (m *Defaults) String() string { return proto.CompactTextString(m) }
1521
-func (*Defaults) ProtoMessage() {}
1522
-
1523
-const Default_Defaults_F_Bool bool = true
1524
-const Default_Defaults_F_Int32 int32 = 32
1525
-const Default_Defaults_F_Int64 int64 = 64
1526
-const Default_Defaults_F_Fixed32 uint32 = 320
1527
-const Default_Defaults_F_Fixed64 uint64 = 640
1528
-const Default_Defaults_F_Uint32 uint32 = 3200
1529
-const Default_Defaults_F_Uint64 uint64 = 6400
1530
-const Default_Defaults_F_Float float32 = 314159
1531
-const Default_Defaults_F_Double float64 = 271828
1532
-const Default_Defaults_F_String string = "hello, \"world!\"\n"
1533
-
1534
-var Default_Defaults_F_Bytes []byte = []byte("Bignose")
1535
-
1536
-const Default_Defaults_F_Sint32 int32 = -32
1537
-const Default_Defaults_F_Sint64 int64 = -64
1538
-const Default_Defaults_F_Enum Defaults_Color = Defaults_GREEN
1539
-
1540
-var Default_Defaults_F_Pinf float32 = float32(math.Inf(1))
1541
-var Default_Defaults_F_Ninf float32 = float32(math.Inf(-1))
1542
-var Default_Defaults_F_Nan float32 = float32(math.NaN())
1543
-
1544
-func (m *Defaults) GetF_Bool() bool {
1545
- if m != nil && m.F_Bool != nil {
1546
- return *m.F_Bool
1547
- }
1548
- return Default_Defaults_F_Bool
1549
-}
1550
-
1551
-func (m *Defaults) GetF_Int32() int32 {
1552
- if m != nil && m.F_Int32 != nil {
1553
- return *m.F_Int32
1554
- }
1555
- return Default_Defaults_F_Int32
1556
-}
1557
-
1558
-func (m *Defaults) GetF_Int64() int64 {
1559
- if m != nil && m.F_Int64 != nil {
1560
- return *m.F_Int64
1561
- }
1562
- return Default_Defaults_F_Int64
1563
-}
1564
-
1565
-func (m *Defaults) GetF_Fixed32() uint32 {
1566
- if m != nil && m.F_Fixed32 != nil {
1567
- return *m.F_Fixed32
1568
- }
1569
- return Default_Defaults_F_Fixed32
1570
-}
1571
-
1572
-func (m *Defaults) GetF_Fixed64() uint64 {
1573
- if m != nil && m.F_Fixed64 != nil {
1574
- return *m.F_Fixed64
1575
- }
1576
- return Default_Defaults_F_Fixed64
1577
-}
1578
-
1579
-func (m *Defaults) GetF_Uint32() uint32 {
1580
- if m != nil && m.F_Uint32 != nil {
1581
- return *m.F_Uint32
1582
- }
1583
- return Default_Defaults_F_Uint32
1584
-}
1585
-
1586
-func (m *Defaults) GetF_Uint64() uint64 {
1587
- if m != nil && m.F_Uint64 != nil {
1588
- return *m.F_Uint64
1589
- }
1590
- return Default_Defaults_F_Uint64
1591
-}
1592
-
1593
-func (m *Defaults) GetF_Float() float32 {
1594
- if m != nil && m.F_Float != nil {
1595
- return *m.F_Float
1596
- }
1597
- return Default_Defaults_F_Float
1598
-}
1599
-
1600
-func (m *Defaults) GetF_Double() float64 {
1601
- if m != nil && m.F_Double != nil {
1602
- return *m.F_Double
1603
- }
1604
- return Default_Defaults_F_Double
1605
-}
1606
-
1607
-func (m *Defaults) GetF_String() string {
1608
- if m != nil && m.F_String != nil {
1609
- return *m.F_String
1610
- }
1611
- return Default_Defaults_F_String
1612
-}
1613
-
1614
-func (m *Defaults) GetF_Bytes() []byte {
1615
- if m != nil && m.F_Bytes != nil {
1616
- return m.F_Bytes
1617
- }
1618
- return append([]byte(nil), Default_Defaults_F_Bytes...)
1619
-}
1620
-
1621
-func (m *Defaults) GetF_Sint32() int32 {
1622
- if m != nil && m.F_Sint32 != nil {
1623
- return *m.F_Sint32
1624
- }
1625
- return Default_Defaults_F_Sint32
1626
-}
1627
-
1628
-func (m *Defaults) GetF_Sint64() int64 {
1629
- if m != nil && m.F_Sint64 != nil {
1630
- return *m.F_Sint64
1631
- }
1632
- return Default_Defaults_F_Sint64
1633
-}
1634
-
1635
-func (m *Defaults) GetF_Enum() Defaults_Color {
1636
- if m != nil && m.F_Enum != nil {
1637
- return *m.F_Enum
1638
- }
1639
- return Default_Defaults_F_Enum
1640
-}
1641
-
1642
-func (m *Defaults) GetF_Pinf() float32 {
1643
- if m != nil && m.F_Pinf != nil {
1644
- return *m.F_Pinf
1645
- }
1646
- return Default_Defaults_F_Pinf
1647
-}
1648
-
1649
-func (m *Defaults) GetF_Ninf() float32 {
1650
- if m != nil && m.F_Ninf != nil {
1651
- return *m.F_Ninf
1652
- }
1653
- return Default_Defaults_F_Ninf
1654
-}
1655
-
1656
-func (m *Defaults) GetF_Nan() float32 {
1657
- if m != nil && m.F_Nan != nil {
1658
- return *m.F_Nan
1659
- }
1660
- return Default_Defaults_F_Nan
1661
-}
1662
-
1663
-func (m *Defaults) GetSub() *SubDefaults {
1664
- if m != nil {
1665
- return m.Sub
1666
- }
1667
- return nil
1668
-}
1669
-
1670
-type SubDefaults struct {
1671
- N *int64 `protobuf:"varint,1,opt,name=n,def=7" json:"n,omitempty"`
1672
- XXX_unrecognized []byte `json:"-"`
1673
-}
1674
-
1675
-func (m *SubDefaults) Reset() { *m = SubDefaults{} }
1676
-func (m *SubDefaults) String() string { return proto.CompactTextString(m) }
1677
-func (*SubDefaults) ProtoMessage() {}
1678
-
1679
-const Default_SubDefaults_N int64 = 7
1680
-
1681
-func (m *SubDefaults) GetN() int64 {
1682
- if m != nil && m.N != nil {
1683
- return *m.N
1684
- }
1685
- return Default_SubDefaults_N
1686
-}
1687
-
1688
-type RepeatedEnum struct {
1689
- Color []RepeatedEnum_Color `protobuf:"varint,1,rep,name=color,enum=testdata.RepeatedEnum_Color" json:"color,omitempty"`
1690
- XXX_unrecognized []byte `json:"-"`
1691
-}
1692
-
1693
-func (m *RepeatedEnum) Reset() { *m = RepeatedEnum{} }
1694
-func (m *RepeatedEnum) String() string { return proto.CompactTextString(m) }
1695
-func (*RepeatedEnum) ProtoMessage() {}
1696
-
1697
-func (m *RepeatedEnum) GetColor() []RepeatedEnum_Color {
1698
- if m != nil {
1699
- return m.Color
1700
- }
1701
- return nil
1702
-}
1703
-
1704
-type MoreRepeated struct {
1705
- Bools []bool `protobuf:"varint,1,rep,name=bools" json:"bools,omitempty"`
1706
- BoolsPacked []bool `protobuf:"varint,2,rep,packed,name=bools_packed" json:"bools_packed,omitempty"`
1707
- Ints []int32 `protobuf:"varint,3,rep,name=ints" json:"ints,omitempty"`
1708
- IntsPacked []int32 `protobuf:"varint,4,rep,packed,name=ints_packed" json:"ints_packed,omitempty"`
1709
- Int64SPacked []int64 `protobuf:"varint,7,rep,packed,name=int64s_packed" json:"int64s_packed,omitempty"`
1710
- Strings []string `protobuf:"bytes,5,rep,name=strings" json:"strings,omitempty"`
1711
- Fixeds []uint32 `protobuf:"fixed32,6,rep,name=fixeds" json:"fixeds,omitempty"`
1712
- XXX_unrecognized []byte `json:"-"`
1713
-}
1714
-
1715
-func (m *MoreRepeated) Reset() { *m = MoreRepeated{} }
1716
-func (m *MoreRepeated) String() string { return proto.CompactTextString(m) }
1717
-func (*MoreRepeated) ProtoMessage() {}
1718
-
1719
-func (m *MoreRepeated) GetBools() []bool {
1720
- if m != nil {
1721
- return m.Bools
1722
- }
1723
- return nil
1724
-}
1725
-
1726
-func (m *MoreRepeated) GetBoolsPacked() []bool {
1727
- if m != nil {
1728
- return m.BoolsPacked
1729
- }
1730
- return nil
1731
-}
1732
-
1733
-func (m *MoreRepeated) GetInts() []int32 {
1734
- if m != nil {
1735
- return m.Ints
1736
- }
1737
- return nil
1738
-}
1739
-
1740
-func (m *MoreRepeated) GetIntsPacked() []int32 {
1741
- if m != nil {
1742
- return m.IntsPacked
1743
- }
1744
- return nil
1745
-}
1746
-
1747
-func (m *MoreRepeated) GetInt64SPacked() []int64 {
1748
- if m != nil {
1749
- return m.Int64SPacked
1750
- }
1751
- return nil
1752
-}
1753
-
1754
-func (m *MoreRepeated) GetStrings() []string {
1755
- if m != nil {
1756
- return m.Strings
1757
- }
1758
- return nil
1759
-}
1760
-
1761
-func (m *MoreRepeated) GetFixeds() []uint32 {
1762
- if m != nil {
1763
- return m.Fixeds
1764
- }
1765
- return nil
1766
-}
1767
-
1768
-type GroupOld struct {
1769
- G *GroupOld_G `protobuf:"group,101,opt" json:"g,omitempty"`
1770
- XXX_unrecognized []byte `json:"-"`
1771
-}
1772
-
1773
-func (m *GroupOld) Reset() { *m = GroupOld{} }
1774
-func (m *GroupOld) String() string { return proto.CompactTextString(m) }
1775
-func (*GroupOld) ProtoMessage() {}
1776
-
1777
-func (m *GroupOld) GetG() *GroupOld_G {
1778
- if m != nil {
1779
- return m.G
1780
- }
1781
- return nil
1782
-}
1783
-
1784
-type GroupOld_G struct {
1785
- X *int32 `protobuf:"varint,2,opt,name=x" json:"x,omitempty"`
1786
- XXX_unrecognized []byte `json:"-"`
1787
-}
1788
-
1789
-func (m *GroupOld_G) Reset() { *m = GroupOld_G{} }
1790
-func (m *GroupOld_G) String() string { return proto.CompactTextString(m) }
1791
-func (*GroupOld_G) ProtoMessage() {}
1792
-
1793
-func (m *GroupOld_G) GetX() int32 {
1794
- if m != nil && m.X != nil {
1795
- return *m.X
1796
- }
1797
- return 0
1798
-}
1799
-
1800
-type GroupNew struct {
1801
- G *GroupNew_G `protobuf:"group,101,opt" json:"g,omitempty"`
1802
- XXX_unrecognized []byte `json:"-"`
1803
-}
1804
-
1805
-func (m *GroupNew) Reset() { *m = GroupNew{} }
1806
-func (m *GroupNew) String() string { return proto.CompactTextString(m) }
1807
-func (*GroupNew) ProtoMessage() {}
1808
-
1809
-func (m *GroupNew) GetG() *GroupNew_G {
1810
- if m != nil {
1811
- return m.G
1812
- }
1813
- return nil
1814
-}
1815
-
1816
-type GroupNew_G struct {
1817
- X *int32 `protobuf:"varint,2,opt,name=x" json:"x,omitempty"`
1818
- Y *int32 `protobuf:"varint,3,opt,name=y" json:"y,omitempty"`
1819
- XXX_unrecognized []byte `json:"-"`
1820
-}
1821
-
1822
-func (m *GroupNew_G) Reset() { *m = GroupNew_G{} }
1823
-func (m *GroupNew_G) String() string { return proto.CompactTextString(m) }
1824
-func (*GroupNew_G) ProtoMessage() {}
1825
-
1826
-func (m *GroupNew_G) GetX() int32 {
1827
- if m != nil && m.X != nil {
1828
- return *m.X
1829
- }
1830
- return 0
1831
-}
1832
-
1833
-func (m *GroupNew_G) GetY() int32 {
1834
- if m != nil && m.Y != nil {
1835
- return *m.Y
1836
- }
1837
- return 0
1838
-}
1839
-
1840
-type FloatingPoint struct {
1841
- F *float64 `protobuf:"fixed64,1,req,name=f" json:"f,omitempty"`
1842
- XXX_unrecognized []byte `json:"-"`
1843
-}
1844
-
1845
-func (m *FloatingPoint) Reset() { *m = FloatingPoint{} }
1846
-func (m *FloatingPoint) String() string { return proto.CompactTextString(m) }
1847
-func (*FloatingPoint) ProtoMessage() {}
1848
-
1849
-func (m *FloatingPoint) GetF() float64 {
1850
- if m != nil && m.F != nil {
1851
- return *m.F
1852
- }
1853
- return 0
1854
-}
1855
-
1856
-var E_Greeting = &proto.ExtensionDesc{
1857
- ExtendedType: (*MyMessage)(nil),
1858
- ExtensionType: ([]string)(nil),
1859
- Field: 106,
1860
- Name: "testdata.greeting",
1861
- Tag: "bytes,106,rep,name=greeting",
1862
-}
1863
-
1864
-var E_X201 = &proto.ExtensionDesc{
1865
- ExtendedType: (*MyMessageSet)(nil),
1866
- ExtensionType: (*Empty)(nil),
1867
- Field: 201,
1868
- Name: "testdata.x201",
1869
- Tag: "bytes,201,opt,name=x201",
1870
-}
1871
-
1872
-var E_X202 = &proto.ExtensionDesc{
1873
- ExtendedType: (*MyMessageSet)(nil),
1874
- ExtensionType: (*Empty)(nil),
1875
- Field: 202,
1876
- Name: "testdata.x202",
1877
- Tag: "bytes,202,opt,name=x202",
1878
-}
1879
-
1880
-var E_X203 = &proto.ExtensionDesc{
1881
- ExtendedType: (*MyMessageSet)(nil),
1882
- ExtensionType: (*Empty)(nil),
1883
- Field: 203,
1884
- Name: "testdata.x203",
1885
- Tag: "bytes,203,opt,name=x203",
1886
-}
1887
-
1888
-var E_X204 = &proto.ExtensionDesc{
1889
- ExtendedType: (*MyMessageSet)(nil),
1890
- ExtensionType: (*Empty)(nil),
1891
- Field: 204,
1892
- Name: "testdata.x204",
1893
- Tag: "bytes,204,opt,name=x204",
1894
-}
1895
-
1896
-var E_X205 = &proto.ExtensionDesc{
1897
- ExtendedType: (*MyMessageSet)(nil),
1898
- ExtensionType: (*Empty)(nil),
1899
- Field: 205,
1900
- Name: "testdata.x205",
1901
- Tag: "bytes,205,opt,name=x205",
1902
-}
1903
-
1904
-var E_X206 = &proto.ExtensionDesc{
1905
- ExtendedType: (*MyMessageSet)(nil),
1906
- ExtensionType: (*Empty)(nil),
1907
- Field: 206,
1908
- Name: "testdata.x206",
1909
- Tag: "bytes,206,opt,name=x206",
1910
-}
1911
-
1912
-var E_X207 = &proto.ExtensionDesc{
1913
- ExtendedType: (*MyMessageSet)(nil),
1914
- ExtensionType: (*Empty)(nil),
1915
- Field: 207,
1916
- Name: "testdata.x207",
1917
- Tag: "bytes,207,opt,name=x207",
1918
-}
1919
-
1920
-var E_X208 = &proto.ExtensionDesc{
1921
- ExtendedType: (*MyMessageSet)(nil),
1922
- ExtensionType: (*Empty)(nil),
1923
- Field: 208,
1924
- Name: "testdata.x208",
1925
- Tag: "bytes,208,opt,name=x208",
1926
-}
1927
-
1928
-var E_X209 = &proto.ExtensionDesc{
1929
- ExtendedType: (*MyMessageSet)(nil),
1930
- ExtensionType: (*Empty)(nil),
1931
- Field: 209,
1932
- Name: "testdata.x209",
1933
- Tag: "bytes,209,opt,name=x209",
1934
-}
1935
-
1936
-var E_X210 = &proto.ExtensionDesc{
1937
- ExtendedType: (*MyMessageSet)(nil),
1938
- ExtensionType: (*Empty)(nil),
1939
- Field: 210,
1940
- Name: "testdata.x210",
1941
- Tag: "bytes,210,opt,name=x210",
1942
-}
1943
-
1944
-var E_X211 = &proto.ExtensionDesc{
1945
- ExtendedType: (*MyMessageSet)(nil),
1946
- ExtensionType: (*Empty)(nil),
1947
- Field: 211,
1948
- Name: "testdata.x211",
1949
- Tag: "bytes,211,opt,name=x211",
1950
-}
1951
-
1952
-var E_X212 = &proto.ExtensionDesc{
1953
- ExtendedType: (*MyMessageSet)(nil),
1954
- ExtensionType: (*Empty)(nil),
1955
- Field: 212,
1956
- Name: "testdata.x212",
1957
- Tag: "bytes,212,opt,name=x212",
1958
-}
1959
-
1960
-var E_X213 = &proto.ExtensionDesc{
1961
- ExtendedType: (*MyMessageSet)(nil),
1962
- ExtensionType: (*Empty)(nil),
1963
- Field: 213,
1964
- Name: "testdata.x213",
1965
- Tag: "bytes,213,opt,name=x213",
1966
-}
1967
-
1968
-var E_X214 = &proto.ExtensionDesc{
1969
- ExtendedType: (*MyMessageSet)(nil),
1970
- ExtensionType: (*Empty)(nil),
1971
- Field: 214,
1972
- Name: "testdata.x214",
1973
- Tag: "bytes,214,opt,name=x214",
1974
-}
1975
-
1976
-var E_X215 = &proto.ExtensionDesc{
1977
- ExtendedType: (*MyMessageSet)(nil),
1978
- ExtensionType: (*Empty)(nil),
1979
- Field: 215,
1980
- Name: "testdata.x215",
1981
- Tag: "bytes,215,opt,name=x215",
1982
-}
1983
-
1984
-var E_X216 = &proto.ExtensionDesc{
1985
- ExtendedType: (*MyMessageSet)(nil),
1986
- ExtensionType: (*Empty)(nil),
1987
- Field: 216,
1988
- Name: "testdata.x216",
1989
- Tag: "bytes,216,opt,name=x216",
1990
-}
1991
-
1992
-var E_X217 = &proto.ExtensionDesc{
1993
- ExtendedType: (*MyMessageSet)(nil),
1994
- ExtensionType: (*Empty)(nil),
1995
- Field: 217,
1996
- Name: "testdata.x217",
1997
- Tag: "bytes,217,opt,name=x217",
1998
-}
1999
-
2000
-var E_X218 = &proto.ExtensionDesc{
2001
- ExtendedType: (*MyMessageSet)(nil),
2002
- ExtensionType: (*Empty)(nil),
2003
- Field: 218,
2004
- Name: "testdata.x218",
2005
- Tag: "bytes,218,opt,name=x218",
2006
-}
2007
-
2008
-var E_X219 = &proto.ExtensionDesc{
2009
- ExtendedType: (*MyMessageSet)(nil),
2010
- ExtensionType: (*Empty)(nil),
2011
- Field: 219,
2012
- Name: "testdata.x219",
2013
- Tag: "bytes,219,opt,name=x219",
2014
-}
2015
-
2016
-var E_X220 = &proto.ExtensionDesc{
2017
- ExtendedType: (*MyMessageSet)(nil),
2018
- ExtensionType: (*Empty)(nil),
2019
- Field: 220,
2020
- Name: "testdata.x220",
2021
- Tag: "bytes,220,opt,name=x220",
2022
-}
2023
-
2024
-var E_X221 = &proto.ExtensionDesc{
2025
- ExtendedType: (*MyMessageSet)(nil),
2026
- ExtensionType: (*Empty)(nil),
2027
- Field: 221,
2028
- Name: "testdata.x221",
2029
- Tag: "bytes,221,opt,name=x221",
2030
-}
2031
-
2032
-var E_X222 = &proto.ExtensionDesc{
2033
- ExtendedType: (*MyMessageSet)(nil),
2034
- ExtensionType: (*Empty)(nil),
2035
- Field: 222,
2036
- Name: "testdata.x222",
2037
- Tag: "bytes,222,opt,name=x222",
2038
-}
2039
-
2040
-var E_X223 = &proto.ExtensionDesc{
2041
- ExtendedType: (*MyMessageSet)(nil),
2042
- ExtensionType: (*Empty)(nil),
2043
- Field: 223,
2044
- Name: "testdata.x223",
2045
- Tag: "bytes,223,opt,name=x223",
2046
-}
2047
-
2048
-var E_X224 = &proto.ExtensionDesc{
2049
- ExtendedType: (*MyMessageSet)(nil),
2050
- ExtensionType: (*Empty)(nil),
2051
- Field: 224,
2052
- Name: "testdata.x224",
2053
- Tag: "bytes,224,opt,name=x224",
2054
-}
2055
-
2056
-var E_X225 = &proto.ExtensionDesc{
2057
- ExtendedType: (*MyMessageSet)(nil),
2058
- ExtensionType: (*Empty)(nil),
2059
- Field: 225,
2060
- Name: "testdata.x225",
2061
- Tag: "bytes,225,opt,name=x225",
2062
-}
2063
-
2064
-var E_X226 = &proto.ExtensionDesc{
2065
- ExtendedType: (*MyMessageSet)(nil),
2066
- ExtensionType: (*Empty)(nil),
2067
- Field: 226,
2068
- Name: "testdata.x226",
2069
- Tag: "bytes,226,opt,name=x226",
2070
-}
2071
-
2072
-var E_X227 = &proto.ExtensionDesc{
2073
- ExtendedType: (*MyMessageSet)(nil),
2074
- ExtensionType: (*Empty)(nil),
2075
- Field: 227,
2076
- Name: "testdata.x227",
2077
- Tag: "bytes,227,opt,name=x227",
2078
-}
2079
-
2080
-var E_X228 = &proto.ExtensionDesc{
2081
- ExtendedType: (*MyMessageSet)(nil),
2082
- ExtensionType: (*Empty)(nil),
2083
- Field: 228,
2084
- Name: "testdata.x228",
2085
- Tag: "bytes,228,opt,name=x228",
2086
-}
2087
-
2088
-var E_X229 = &proto.ExtensionDesc{
2089
- ExtendedType: (*MyMessageSet)(nil),
2090
- ExtensionType: (*Empty)(nil),
2091
- Field: 229,
2092
- Name: "testdata.x229",
2093
- Tag: "bytes,229,opt,name=x229",
2094
-}
2095
-
2096
-var E_X230 = &proto.ExtensionDesc{
2097
- ExtendedType: (*MyMessageSet)(nil),
2098
- ExtensionType: (*Empty)(nil),
2099
- Field: 230,
2100
- Name: "testdata.x230",
2101
- Tag: "bytes,230,opt,name=x230",
2102
-}
2103
-
2104
-var E_X231 = &proto.ExtensionDesc{
2105
- ExtendedType: (*MyMessageSet)(nil),
2106
- ExtensionType: (*Empty)(nil),
2107
- Field: 231,
2108
- Name: "testdata.x231",
2109
- Tag: "bytes,231,opt,name=x231",
2110
-}
2111
-
2112
-var E_X232 = &proto.ExtensionDesc{
2113
- ExtendedType: (*MyMessageSet)(nil),
2114
- ExtensionType: (*Empty)(nil),
2115
- Field: 232,
2116
- Name: "testdata.x232",
2117
- Tag: "bytes,232,opt,name=x232",
2118
-}
2119
-
2120
-var E_X233 = &proto.ExtensionDesc{
2121
- ExtendedType: (*MyMessageSet)(nil),
2122
- ExtensionType: (*Empty)(nil),
2123
- Field: 233,
2124
- Name: "testdata.x233",
2125
- Tag: "bytes,233,opt,name=x233",
2126
-}
2127
-
2128
-var E_X234 = &proto.ExtensionDesc{
2129
- ExtendedType: (*MyMessageSet)(nil),
2130
- ExtensionType: (*Empty)(nil),
2131
- Field: 234,
2132
- Name: "testdata.x234",
2133
- Tag: "bytes,234,opt,name=x234",
2134
-}
2135
-
2136
-var E_X235 = &proto.ExtensionDesc{
2137
- ExtendedType: (*MyMessageSet)(nil),
2138
- ExtensionType: (*Empty)(nil),
2139
- Field: 235,
2140
- Name: "testdata.x235",
2141
- Tag: "bytes,235,opt,name=x235",
2142
-}
2143
-
2144
-var E_X236 = &proto.ExtensionDesc{
2145
- ExtendedType: (*MyMessageSet)(nil),
2146
- ExtensionType: (*Empty)(nil),
2147
- Field: 236,
2148
- Name: "testdata.x236",
2149
- Tag: "bytes,236,opt,name=x236",
2150
-}
2151
-
2152
-var E_X237 = &proto.ExtensionDesc{
2153
- ExtendedType: (*MyMessageSet)(nil),
2154
- ExtensionType: (*Empty)(nil),
2155
- Field: 237,
2156
- Name: "testdata.x237",
2157
- Tag: "bytes,237,opt,name=x237",
2158
-}
2159
-
2160
-var E_X238 = &proto.ExtensionDesc{
2161
- ExtendedType: (*MyMessageSet)(nil),
2162
- ExtensionType: (*Empty)(nil),
2163
- Field: 238,
2164
- Name: "testdata.x238",
2165
- Tag: "bytes,238,opt,name=x238",
2166
-}
2167
-
2168
-var E_X239 = &proto.ExtensionDesc{
2169
- ExtendedType: (*MyMessageSet)(nil),
2170
- ExtensionType: (*Empty)(nil),
2171
- Field: 239,
2172
- Name: "testdata.x239",
2173
- Tag: "bytes,239,opt,name=x239",
2174
-}
2175
-
2176
-var E_X240 = &proto.ExtensionDesc{
2177
- ExtendedType: (*MyMessageSet)(nil),
2178
- ExtensionType: (*Empty)(nil),
2179
- Field: 240,
2180
- Name: "testdata.x240",
2181
- Tag: "bytes,240,opt,name=x240",
2182
-}
2183
-
2184
-var E_X241 = &proto.ExtensionDesc{
2185
- ExtendedType: (*MyMessageSet)(nil),
2186
- ExtensionType: (*Empty)(nil),
2187
- Field: 241,
2188
- Name: "testdata.x241",
2189
- Tag: "bytes,241,opt,name=x241",
2190
-}
2191
-
2192
-var E_X242 = &proto.ExtensionDesc{
2193
- ExtendedType: (*MyMessageSet)(nil),
2194
- ExtensionType: (*Empty)(nil),
2195
- Field: 242,
2196
- Name: "testdata.x242",
2197
- Tag: "bytes,242,opt,name=x242",
2198
-}
2199
-
2200
-var E_X243 = &proto.ExtensionDesc{
2201
- ExtendedType: (*MyMessageSet)(nil),
2202
- ExtensionType: (*Empty)(nil),
2203
- Field: 243,
2204
- Name: "testdata.x243",
2205
- Tag: "bytes,243,opt,name=x243",
2206
-}
2207
-
2208
-var E_X244 = &proto.ExtensionDesc{
2209
- ExtendedType: (*MyMessageSet)(nil),
2210
- ExtensionType: (*Empty)(nil),
2211
- Field: 244,
2212
- Name: "testdata.x244",
2213
- Tag: "bytes,244,opt,name=x244",
2214
-}
2215
-
2216
-var E_X245 = &proto.ExtensionDesc{
2217
- ExtendedType: (*MyMessageSet)(nil),
2218
- ExtensionType: (*Empty)(nil),
2219
- Field: 245,
2220
- Name: "testdata.x245",
2221
- Tag: "bytes,245,opt,name=x245",
2222
-}
2223
-
2224
-var E_X246 = &proto.ExtensionDesc{
2225
- ExtendedType: (*MyMessageSet)(nil),
2226
- ExtensionType: (*Empty)(nil),
2227
- Field: 246,
2228
- Name: "testdata.x246",
2229
- Tag: "bytes,246,opt,name=x246",
2230
-}
2231
-
2232
-var E_X247 = &proto.ExtensionDesc{
2233
- ExtendedType: (*MyMessageSet)(nil),
2234
- ExtensionType: (*Empty)(nil),
2235
- Field: 247,
2236
- Name: "testdata.x247",
2237
- Tag: "bytes,247,opt,name=x247",
2238
-}
2239
-
2240
-var E_X248 = &proto.ExtensionDesc{
2241
- ExtendedType: (*MyMessageSet)(nil),
2242
- ExtensionType: (*Empty)(nil),
2243
- Field: 248,
2244
- Name: "testdata.x248",
2245
- Tag: "bytes,248,opt,name=x248",
2246
-}
2247
-
2248
-var E_X249 = &proto.ExtensionDesc{
2249
- ExtendedType: (*MyMessageSet)(nil),
2250
- ExtensionType: (*Empty)(nil),
2251
- Field: 249,
2252
- Name: "testdata.x249",
2253
- Tag: "bytes,249,opt,name=x249",
2254
-}
2255
-
2256
-var E_X250 = &proto.ExtensionDesc{
2257
- ExtendedType: (*MyMessageSet)(nil),
2258
- ExtensionType: (*Empty)(nil),
2259
- Field: 250,
2260
- Name: "testdata.x250",
2261
- Tag: "bytes,250,opt,name=x250",
2262
-}
2263
-
2264
-func init() {
2265
- proto.RegisterEnum("testdata.FOO", FOO_name, FOO_value)
2266
- proto.RegisterEnum("testdata.GoTest_KIND", GoTest_KIND_name, GoTest_KIND_value)
2267
- proto.RegisterEnum("testdata.MyMessage_Color", MyMessage_Color_name, MyMessage_Color_value)
2268
- proto.RegisterEnum("testdata.Defaults_Color", Defaults_Color_name, Defaults_Color_value)
2269
- proto.RegisterEnum("testdata.RepeatedEnum_Color", RepeatedEnum_Color_name, RepeatedEnum_Color_value)
2270
- proto.RegisterExtension(E_Ext_More)
2271
- proto.RegisterExtension(E_Ext_Text)
2272
- proto.RegisterExtension(E_Ext_Number)
2273
- proto.RegisterExtension(E_Greeting)
2274
- proto.RegisterExtension(E_X201)
2275
- proto.RegisterExtension(E_X202)
2276
- proto.RegisterExtension(E_X203)
2277
- proto.RegisterExtension(E_X204)
2278
- proto.RegisterExtension(E_X205)
2279
- proto.RegisterExtension(E_X206)
2280
- proto.RegisterExtension(E_X207)
2281
- proto.RegisterExtension(E_X208)
2282
- proto.RegisterExtension(E_X209)
2283
- proto.RegisterExtension(E_X210)
2284
- proto.RegisterExtension(E_X211)
2285
- proto.RegisterExtension(E_X212)
2286
- proto.RegisterExtension(E_X213)
2287
- proto.RegisterExtension(E_X214)
2288
- proto.RegisterExtension(E_X215)
2289
- proto.RegisterExtension(E_X216)
2290
- proto.RegisterExtension(E_X217)
2291
- proto.RegisterExtension(E_X218)
2292
- proto.RegisterExtension(E_X219)
2293
- proto.RegisterExtension(E_X220)
2294
- proto.RegisterExtension(E_X221)
2295
- proto.RegisterExtension(E_X222)
2296
- proto.RegisterExtension(E_X223)
2297
- proto.RegisterExtension(E_X224)
2298
- proto.RegisterExtension(E_X225)
2299
- proto.RegisterExtension(E_X226)
2300
- proto.RegisterExtension(E_X227)
2301
- proto.RegisterExtension(E_X228)
2302
- proto.RegisterExtension(E_X229)
2303
- proto.RegisterExtension(E_X230)
2304
- proto.RegisterExtension(E_X231)
2305
- proto.RegisterExtension(E_X232)
2306
- proto.RegisterExtension(E_X233)
2307
- proto.RegisterExtension(E_X234)
2308
- proto.RegisterExtension(E_X235)
2309
- proto.RegisterExtension(E_X236)
2310
- proto.RegisterExtension(E_X237)
2311
- proto.RegisterExtension(E_X238)
2312
- proto.RegisterExtension(E_X239)
2313
- proto.RegisterExtension(E_X240)
2314
- proto.RegisterExtension(E_X241)
2315
- proto.RegisterExtension(E_X242)
2316
- proto.RegisterExtension(E_X243)
2317
- proto.RegisterExtension(E_X244)
2318
- proto.RegisterExtension(E_X245)
2319
- proto.RegisterExtension(E_X246)
2320
- proto.RegisterExtension(E_X247)
2321
- proto.RegisterExtension(E_X248)
2322
- proto.RegisterExtension(E_X249)
2323
- proto.RegisterExtension(E_X250)
2324
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/testdata/test.proto
deleted
-420
@@ -1,420 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-// A feature-rich test file for the protocol compiler and libraries.
33
-
34
-syntax = "proto2";
35
-
36
-package testdata;
37
-
38
-enum FOO { FOO1 = 1; };
39
-
40
-message GoEnum {
41
- required FOO foo = 1;
42
-}
43
-
44
-message GoTestField {
45
- required string Label = 1;
46
- required string Type = 2;
47
-}
48
-
49
-message GoTest {
50
- // An enum, for completeness.
51
- enum KIND {
52
- VOID = 0;
53
-
54
- // Basic types
55
- BOOL = 1;
56
- BYTES = 2;
57
- FINGERPRINT = 3;
58
- FLOAT = 4;
59
- INT = 5;
60
- STRING = 6;
61
- TIME = 7;
62
-
63
- // Groupings
64
- TUPLE = 8;
65
- ARRAY = 9;
66
- MAP = 10;
67
-
68
- // Table types
69
- TABLE = 11;
70
-
71
- // Functions
72
- FUNCTION = 12; // last tag
73
- };
74
-
75
- // Some typical parameters
76
- required KIND Kind = 1;
77
- optional string Table = 2;
78
- optional int32 Param = 3;
79
-
80
- // Required, repeated and optional foreign fields.
81
- required GoTestField RequiredField = 4;
82
- repeated GoTestField RepeatedField = 5;
83
- optional GoTestField OptionalField = 6;
84
-
85
- // Required fields of all basic types
86
- required bool F_Bool_required = 10;
87
- required int32 F_Int32_required = 11;
88
- required int64 F_Int64_required = 12;
89
- required fixed32 F_Fixed32_required = 13;
90
- required fixed64 F_Fixed64_required = 14;
91
- required uint32 F_Uint32_required = 15;
92
- required uint64 F_Uint64_required = 16;
93
- required float F_Float_required = 17;
94
- required double F_Double_required = 18;
95
- required string F_String_required = 19;
96
- required bytes F_Bytes_required = 101;
97
- required sint32 F_Sint32_required = 102;
98
- required sint64 F_Sint64_required = 103;
99
-
100
- // Repeated fields of all basic types
101
- repeated bool F_Bool_repeated = 20;
102
- repeated int32 F_Int32_repeated = 21;
103
- repeated int64 F_Int64_repeated = 22;
104
- repeated fixed32 F_Fixed32_repeated = 23;
105
- repeated fixed64 F_Fixed64_repeated = 24;
106
- repeated uint32 F_Uint32_repeated = 25;
107
- repeated uint64 F_Uint64_repeated = 26;
108
- repeated float F_Float_repeated = 27;
109
- repeated double F_Double_repeated = 28;
110
- repeated string F_String_repeated = 29;
111
- repeated bytes F_Bytes_repeated = 201;
112
- repeated sint32 F_Sint32_repeated = 202;
113
- repeated sint64 F_Sint64_repeated = 203;
114
-
115
- // Optional fields of all basic types
116
- optional bool F_Bool_optional = 30;
117
- optional int32 F_Int32_optional = 31;
118
- optional int64 F_Int64_optional = 32;
119
- optional fixed32 F_Fixed32_optional = 33;
120
- optional fixed64 F_Fixed64_optional = 34;
121
- optional uint32 F_Uint32_optional = 35;
122
- optional uint64 F_Uint64_optional = 36;
123
- optional float F_Float_optional = 37;
124
- optional double F_Double_optional = 38;
125
- optional string F_String_optional = 39;
126
- optional bytes F_Bytes_optional = 301;
127
- optional sint32 F_Sint32_optional = 302;
128
- optional sint64 F_Sint64_optional = 303;
129
-
130
- // Default-valued fields of all basic types
131
- optional bool F_Bool_defaulted = 40 [default=true];
132
- optional int32 F_Int32_defaulted = 41 [default=32];
133
- optional int64 F_Int64_defaulted = 42 [default=64];
134
- optional fixed32 F_Fixed32_defaulted = 43 [default=320];
135
- optional fixed64 F_Fixed64_defaulted = 44 [default=640];
136
- optional uint32 F_Uint32_defaulted = 45 [default=3200];
137
- optional uint64 F_Uint64_defaulted = 46 [default=6400];
138
- optional float F_Float_defaulted = 47 [default=314159.];
139
- optional double F_Double_defaulted = 48 [default=271828.];
140
- optional string F_String_defaulted = 49 [default="hello, \"world!\"\n"];
141
- optional bytes F_Bytes_defaulted = 401 [default="Bignose"];
142
- optional sint32 F_Sint32_defaulted = 402 [default = -32];
143
- optional sint64 F_Sint64_defaulted = 403 [default = -64];
144
-
145
- // Packed repeated fields (no string or bytes).
146
- repeated bool F_Bool_repeated_packed = 50 [packed=true];
147
- repeated int32 F_Int32_repeated_packed = 51 [packed=true];
148
- repeated int64 F_Int64_repeated_packed = 52 [packed=true];
149
- repeated fixed32 F_Fixed32_repeated_packed = 53 [packed=true];
150
- repeated fixed64 F_Fixed64_repeated_packed = 54 [packed=true];
151
- repeated uint32 F_Uint32_repeated_packed = 55 [packed=true];
152
- repeated uint64 F_Uint64_repeated_packed = 56 [packed=true];
153
- repeated float F_Float_repeated_packed = 57 [packed=true];
154
- repeated double F_Double_repeated_packed = 58 [packed=true];
155
- repeated sint32 F_Sint32_repeated_packed = 502 [packed=true];
156
- repeated sint64 F_Sint64_repeated_packed = 503 [packed=true];
157
-
158
- // Required, repeated, and optional groups.
159
- required group RequiredGroup = 70 {
160
- required string RequiredField = 71;
161
- };
162
-
163
- repeated group RepeatedGroup = 80 {
164
- required string RequiredField = 81;
165
- };
166
-
167
- optional group OptionalGroup = 90 {
168
- required string RequiredField = 91;
169
- };
170
-}
171
-
172
-// For testing skipping of unrecognized fields.
173
-// Numbers are all big, larger than tag numbers in GoTestField,
174
-// the message used in the corresponding test.
175
-message GoSkipTest {
176
- required int32 skip_int32 = 11;
177
- required fixed32 skip_fixed32 = 12;
178
- required fixed64 skip_fixed64 = 13;
179
- required string skip_string = 14;
180
- required group SkipGroup = 15 {
181
- required int32 group_int32 = 16;
182
- required string group_string = 17;
183
- }
184
-}
185
-
186
-// For testing packed/non-packed decoder switching.
187
-// A serialized instance of one should be deserializable as the other.
188
-message NonPackedTest {
189
- repeated int32 a = 1;
190
-}
191
-
192
-message PackedTest {
193
- repeated int32 b = 1 [packed=true];
194
-}
195
-
196
-message MaxTag {
197
- // Maximum possible tag number.
198
- optional string last_field = 536870911;
199
-}
200
-
201
-message OldMessage {
202
- message Nested {
203
- optional string name = 1;
204
- }
205
- optional Nested nested = 1;
206
-}
207
-
208
-// NewMessage is wire compatible with OldMessage;
209
-// imagine it as a future version.
210
-message NewMessage {
211
- message Nested {
212
- optional string name = 1;
213
- optional string food_group = 2;
214
- }
215
- optional Nested nested = 1;
216
-}
217
-
218
-// Smaller tests for ASCII formatting.
219
-
220
-message InnerMessage {
221
- required string host = 1;
222
- optional int32 port = 2 [default=4000];
223
- optional bool connected = 3;
224
-}
225
-
226
-message OtherMessage {
227
- optional int64 key = 1;
228
- optional bytes value = 2;
229
- optional float weight = 3;
230
- optional InnerMessage inner = 4;
231
-}
232
-
233
-message MyMessage {
234
- required int32 count = 1;
235
- optional string name = 2;
236
- optional string quote = 3;
237
- repeated string pet = 4;
238
- optional InnerMessage inner = 5;
239
- repeated OtherMessage others = 6;
240
- repeated InnerMessage rep_inner = 12;
241
-
242
- enum Color {
243
- RED = 0;
244
- GREEN = 1;
245
- BLUE = 2;
246
- };
247
- optional Color bikeshed = 7;
248
-
249
- optional group SomeGroup = 8 {
250
- optional int32 group_field = 9;
251
- }
252
-
253
- // This field becomes [][]byte in the generated code.
254
- repeated bytes rep_bytes = 10;
255
-
256
- optional double bigfloat = 11;
257
-
258
- extensions 100 to max;
259
-}
260
-
261
-message Ext {
262
- extend MyMessage {
263
- optional Ext more = 103;
264
- optional string text = 104;
265
- optional int32 number = 105;
266
- }
267
-
268
- optional string data = 1;
269
-}
270
-
271
-extend MyMessage {
272
- repeated string greeting = 106;
273
-}
274
-
275
-message MyMessageSet {
276
- option message_set_wire_format = true;
277
- extensions 100 to max;
278
-}
279
-
280
-message Empty {
281
-}
282
-
283
-extend MyMessageSet {
284
- optional Empty x201 = 201;
285
- optional Empty x202 = 202;
286
- optional Empty x203 = 203;
287
- optional Empty x204 = 204;
288
- optional Empty x205 = 205;
289
- optional Empty x206 = 206;
290
- optional Empty x207 = 207;
291
- optional Empty x208 = 208;
292
- optional Empty x209 = 209;
293
- optional Empty x210 = 210;
294
- optional Empty x211 = 211;
295
- optional Empty x212 = 212;
296
- optional Empty x213 = 213;
297
- optional Empty x214 = 214;
298
- optional Empty x215 = 215;
299
- optional Empty x216 = 216;
300
- optional Empty x217 = 217;
301
- optional Empty x218 = 218;
302
- optional Empty x219 = 219;
303
- optional Empty x220 = 220;
304
- optional Empty x221 = 221;
305
- optional Empty x222 = 222;
306
- optional Empty x223 = 223;
307
- optional Empty x224 = 224;
308
- optional Empty x225 = 225;
309
- optional Empty x226 = 226;
310
- optional Empty x227 = 227;
311
- optional Empty x228 = 228;
312
- optional Empty x229 = 229;
313
- optional Empty x230 = 230;
314
- optional Empty x231 = 231;
315
- optional Empty x232 = 232;
316
- optional Empty x233 = 233;
317
- optional Empty x234 = 234;
318
- optional Empty x235 = 235;
319
- optional Empty x236 = 236;
320
- optional Empty x237 = 237;
321
- optional Empty x238 = 238;
322
- optional Empty x239 = 239;
323
- optional Empty x240 = 240;
324
- optional Empty x241 = 241;
325
- optional Empty x242 = 242;
326
- optional Empty x243 = 243;
327
- optional Empty x244 = 244;
328
- optional Empty x245 = 245;
329
- optional Empty x246 = 246;
330
- optional Empty x247 = 247;
331
- optional Empty x248 = 248;
332
- optional Empty x249 = 249;
333
- optional Empty x250 = 250;
334
-}
335
-
336
-message MessageList {
337
- repeated group Message = 1 {
338
- required string name = 2;
339
- required int32 count = 3;
340
- }
341
-}
342
-
343
-message Strings {
344
- optional string string_field = 1;
345
- optional bytes bytes_field = 2;
346
-}
347
-
348
-message Defaults {
349
- enum Color {
350
- RED = 0;
351
- GREEN = 1;
352
- BLUE = 2;
353
- }
354
-
355
- // Default-valued fields of all basic types.
356
- // Same as GoTest, but copied here to make testing easier.
357
- optional bool F_Bool = 1 [default=true];
358
- optional int32 F_Int32 = 2 [default=32];
359
- optional int64 F_Int64 = 3 [default=64];
360
- optional fixed32 F_Fixed32 = 4 [default=320];
361
- optional fixed64 F_Fixed64 = 5 [default=640];
362
- optional uint32 F_Uint32 = 6 [default=3200];
363
- optional uint64 F_Uint64 = 7 [default=6400];
364
- optional float F_Float = 8 [default=314159.];
365
- optional double F_Double = 9 [default=271828.];
366
- optional string F_String = 10 [default="hello, \"world!\"\n"];
367
- optional bytes F_Bytes = 11 [default="Bignose"];
368
- optional sint32 F_Sint32 = 12 [default=-32];
369
- optional sint64 F_Sint64 = 13 [default=-64];
370
- optional Color F_Enum = 14 [default=GREEN];
371
-
372
- // More fields with crazy defaults.
373
- optional float F_Pinf = 15 [default=inf];
374
- optional float F_Ninf = 16 [default=-inf];
375
- optional float F_Nan = 17 [default=nan];
376
-
377
- // Sub-message.
378
- optional SubDefaults sub = 18;
379
-}
380
-
381
-message SubDefaults {
382
- optional int64 n = 1 [default=7];
383
-}
384
-
385
-message RepeatedEnum {
386
- enum Color {
387
- RED = 1;
388
- }
389
- repeated Color color = 1;
390
-}
391
-
392
-message MoreRepeated {
393
- repeated bool bools = 1;
394
- repeated bool bools_packed = 2 [packed=true];
395
- repeated int32 ints = 3;
396
- repeated int32 ints_packed = 4 [packed=true];
397
- repeated int64 int64s_packed = 7 [packed=true];
398
- repeated string strings = 5;
399
- repeated fixed32 fixeds = 6;
400
-}
401
-
402
-// GroupOld and GroupNew have the same wire format.
403
-// GroupNew has a new field inside a group.
404
-
405
-message GroupOld {
406
- optional group G = 101 {
407
- optional int32 x = 2;
408
- }
409
-}
410
-
411
-message GroupNew {
412
- optional group G = 101 {
413
- optional int32 x = 2;
414
- optional int32 y = 3;
415
- }
416
-}
417
-
418
-message FloatingPoint {
419
- required double f = 1;
420
-}
Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto/text_parser_test.go
deleted
-462
@@ -1,462 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto_test
33
-
34
-import (
35
- "math"
36
- "reflect"
37
- "testing"
38
-
39
- . "./testdata"
40
- . "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
41
-)
42
-
43
-type UnmarshalTextTest struct {
44
- in string
45
- err string // if "", no error expected
46
- out *MyMessage
47
-}
48
-
49
-func buildExtStructTest(text string) UnmarshalTextTest {
50
- msg := &MyMessage{
51
- Count: Int32(42),
52
- }
53
- SetExtension(msg, E_Ext_More, &Ext{
54
- Data: String("Hello, world!"),
55
- })
56
- return UnmarshalTextTest{in: text, out: msg}
57
-}
58
-
59
-func buildExtDataTest(text string) UnmarshalTextTest {
60
- msg := &MyMessage{
61
- Count: Int32(42),
62
- }
63
- SetExtension(msg, E_Ext_Text, String("Hello, world!"))
64
- SetExtension(msg, E_Ext_Number, Int32(1729))
65
- return UnmarshalTextTest{in: text, out: msg}
66
-}
67
-
68
-func buildExtRepStringTest(text string) UnmarshalTextTest {
69
- msg := &MyMessage{
70
- Count: Int32(42),
71
- }
72
- if err := SetExtension(msg, E_Greeting, []string{"bula", "hola"}); err != nil {
73
- panic(err)
74
- }
75
- return UnmarshalTextTest{in: text, out: msg}
76
-}
77
-
78
-var unMarshalTextTests = []UnmarshalTextTest{
79
- // Basic
80
- {
81
- in: " count:42\n name:\"Dave\" ",
82
- out: &MyMessage{
83
- Count: Int32(42),
84
- Name: String("Dave"),
85
- },
86
- },
87
-
88
- // Empty quoted string
89
- {
90
- in: `count:42 name:""`,
91
- out: &MyMessage{
92
- Count: Int32(42),
93
- Name: String(""),
94
- },
95
- },
96
-
97
- // Quoted string concatenation
98
- {
99
- in: `count:42 name: "My name is "` + "\n" + `"elsewhere"`,
100
- out: &MyMessage{
101
- Count: Int32(42),
102
- Name: String("My name is elsewhere"),
103
- },
104
- },
105
-
106
- // Quoted string with escaped apostrophe
107
- {
108
- in: `count:42 name: "HOLIDAY - New Year\'s Day"`,
109
- out: &MyMessage{
110
- Count: Int32(42),
111
- Name: String("HOLIDAY - New Year's Day"),
112
- },
113
- },
114
-
115
- // Quoted string with single quote
116
- {
117
- in: `count:42 name: 'Roger "The Ramster" Ramjet'`,
118
- out: &MyMessage{
119
- Count: Int32(42),
120
- Name: String(`Roger "The Ramster" Ramjet`),
121
- },
122
- },
123
-
124
- // Quoted string with all the accepted special characters from the C++ test
125
- {
126
- in: `count:42 name: ` + "\"\\\"A string with \\' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"",
127
- out: &MyMessage{
128
- Count: Int32(42),
129
- Name: String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces"),
130
- },
131
- },
132
-
133
- // Quoted string with quoted backslash
134
- {
135
- in: `count:42 name: "\\'xyz"`,
136
- out: &MyMessage{
137
- Count: Int32(42),
138
- Name: String(`\'xyz`),
139
- },
140
- },
141
-
142
- // Quoted string with UTF-8 bytes.
143
- {
144
- in: "count:42 name: '\303\277\302\201\xAB'",
145
- out: &MyMessage{
146
- Count: Int32(42),
147
- Name: String("\303\277\302\201\xAB"),
148
- },
149
- },
150
-
151
- // Bad quoted string
152
- {
153
- in: `inner: < host: "\0" >` + "\n",
154
- err: `line 1.15: invalid quoted string "\0"`,
155
- },
156
-
157
- // Number too large for int64
158
- {
159
- in: "count: 1 others { key: 123456789012345678901 }",
160
- err: "line 1.23: invalid int64: 123456789012345678901",
161
- },
162
-
163
- // Number too large for int32
164
- {
165
- in: "count: 1234567890123",
166
- err: "line 1.7: invalid int32: 1234567890123",
167
- },
168
-
169
- // Number in hexadecimal
170
- {
171
- in: "count: 0x2beef",
172
- out: &MyMessage{
173
- Count: Int32(0x2beef),
174
- },
175
- },
176
-
177
- // Number in octal
178
- {
179
- in: "count: 024601",
180
- out: &MyMessage{
181
- Count: Int32(024601),
182
- },
183
- },
184
-
185
- // Floating point number with "f" suffix
186
- {
187
- in: "count: 4 others:< weight: 17.0f >",
188
- out: &MyMessage{
189
- Count: Int32(4),
190
- Others: []*OtherMessage{
191
- {
192
- Weight: Float32(17),
193
- },
194
- },
195
- },
196
- },
197
-
198
- // Floating point positive infinity
199
- {
200
- in: "count: 4 bigfloat: inf",
201
- out: &MyMessage{
202
- Count: Int32(4),
203
- Bigfloat: Float64(math.Inf(1)),
204
- },
205
- },
206
-
207
- // Floating point negative infinity
208
- {
209
- in: "count: 4 bigfloat: -inf",
210
- out: &MyMessage{
211
- Count: Int32(4),
212
- Bigfloat: Float64(math.Inf(-1)),
213
- },
214
- },
215
-
216
- // Number too large for float32
217
- {
218
- in: "others:< weight: 12345678901234567890123456789012345678901234567890 >",
219
- err: "line 1.17: invalid float32: 12345678901234567890123456789012345678901234567890",
220
- },
221
-
222
- // Number posing as a quoted string
223
- {
224
- in: `inner: < host: 12 >` + "\n",
225
- err: `line 1.15: invalid string: 12`,
226
- },
227
-
228
- // Quoted string posing as int32
229
- {
230
- in: `count: "12"`,
231
- err: `line 1.7: invalid int32: "12"`,
232
- },
233
-
234
- // Quoted string posing a float32
235
- {
236
- in: `others:< weight: "17.4" >`,
237
- err: `line 1.17: invalid float32: "17.4"`,
238
- },
239
-
240
- // Enum
241
- {
242
- in: `count:42 bikeshed: BLUE`,
243
- out: &MyMessage{
244
- Count: Int32(42),
245
- Bikeshed: MyMessage_BLUE.Enum(),
246
- },
247
- },
248
-
249
- // Repeated field
250
- {
251
- in: `count:42 pet: "horsey" pet:"bunny"`,
252
- out: &MyMessage{
253
- Count: Int32(42),
254
- Pet: []string{"horsey", "bunny"},
255
- },
256
- },
257
-
258
- // Repeated message with/without colon and <>/{}
259
- {
260
- in: `count:42 others:{} others{} others:<> others:{}`,
261
- out: &MyMessage{
262
- Count: Int32(42),
263
- Others: []*OtherMessage{
264
- {},
265
- {},
266
- {},
267
- {},
268
- },
269
- },
270
- },
271
-
272
- // Missing colon for inner message
273
- {
274
- in: `count:42 inner < host: "cauchy.syd" >`,
275
- out: &MyMessage{
276
- Count: Int32(42),
277
- Inner: &InnerMessage{
278
- Host: String("cauchy.syd"),
279
- },
280
- },
281
- },
282
-
283
- // Missing colon for string field
284
- {
285
- in: `name "Dave"`,
286
- err: `line 1.5: expected ':', found "\"Dave\""`,
287
- },
288
-
289
- // Missing colon for int32 field
290
- {
291
- in: `count 42`,
292
- err: `line 1.6: expected ':', found "42"`,
293
- },
294
-
295
- // Missing required field
296
- {
297
- in: ``,
298
- err: `line 1.0: message testdata.MyMessage missing required field "count"`,
299
- },
300
-
301
- // Repeated non-repeated field
302
- {
303
- in: `name: "Rob" name: "Russ"`,
304
- err: `line 1.12: non-repeated field "name" was repeated`,
305
- },
306
-
307
- // Group
308
- {
309
- in: `count: 17 SomeGroup { group_field: 12 }`,
310
- out: &MyMessage{
311
- Count: Int32(17),
312
- Somegroup: &MyMessage_SomeGroup{
313
- GroupField: Int32(12),
314
- },
315
- },
316
- },
317
-
318
- // Semicolon between fields
319
- {
320
- in: `count:3;name:"Calvin"`,
321
- out: &MyMessage{
322
- Count: Int32(3),
323
- Name: String("Calvin"),
324
- },
325
- },
326
- // Comma between fields
327
- {
328
- in: `count:4,name:"Ezekiel"`,
329
- out: &MyMessage{
330
- Count: Int32(4),
331
- Name: String("Ezekiel"),
332
- },
333
- },
334
-
335
- // Extension
336
- buildExtStructTest(`count: 42 [testdata.Ext.more]:<data:"Hello, world!" >`),
337
- buildExtStructTest(`count: 42 [testdata.Ext.more] {data:"Hello, world!"}`),
338
- buildExtDataTest(`count: 42 [testdata.Ext.text]:"Hello, world!" [testdata.Ext.number]:1729`),
339
- buildExtRepStringTest(`count: 42 [testdata.greeting]:"bula" [testdata.greeting]:"hola"`),
340
-
341
- // Big all-in-one
342
- {
343
- in: "count:42 # Meaning\n" +
344
- `name:"Dave" ` +
345
- `quote:"\"I didn't want to go.\"" ` +
346
- `pet:"bunny" ` +
347
- `pet:"kitty" ` +
348
- `pet:"horsey" ` +
349
- `inner:<` +
350
- ` host:"footrest.syd" ` +
351
- ` port:7001 ` +
352
- ` connected:true ` +
353
- `> ` +
354
- `others:<` +
355
- ` key:3735928559 ` +
356
- ` value:"\x01A\a\f" ` +
357
- `> ` +
358
- `others:<` +
359
- " weight:58.9 # Atomic weight of Co\n" +
360
- ` inner:<` +
361
- ` host:"lesha.mtv" ` +
362
- ` port:8002 ` +
363
- ` >` +
364
- `>`,
365
- out: &MyMessage{
366
- Count: Int32(42),
367
- Name: String("Dave"),
368
- Quote: String(`"I didn't want to go."`),
369
- Pet: []string{"bunny", "kitty", "horsey"},
370
- Inner: &InnerMessage{
371
- Host: String("footrest.syd"),
372
- Port: Int32(7001),
373
- Connected: Bool(true),
374
- },
375
- Others: []*OtherMessage{
376
- {
377
- Key: Int64(3735928559),
378
- Value: []byte{0x1, 'A', '\a', '\f'},
379
- },
380
- {
381
- Weight: Float32(58.9),
382
- Inner: &InnerMessage{
383
- Host: String("lesha.mtv"),
384
- Port: Int32(8002),
385
- },
386
- },
387
- },
388
- },
389
- },
390
-}
391
-
392
-func TestUnmarshalText(t *testing.T) {
393
- for i, test := range unMarshalTextTests {
394
- pb := new(MyMessage)
395
- err := UnmarshalText(test.in, pb)
396
- if test.err == "" {
397
- // We don't expect failure.
398
- if err != nil {
399
- t.Errorf("Test %d: Unexpected error: %v", i, err)
400
- } else if !reflect.DeepEqual(pb, test.out) {
401
- t.Errorf("Test %d: Incorrect populated \nHave: %v\nWant: %v",
402
- i, pb, test.out)
403
- }
404
- } else {
405
- // We do expect failure.
406
- if err == nil {
407
- t.Errorf("Test %d: Didn't get expected error: %v", i, test.err)
408
- } else if err.Error() != test.err {
409
- t.Errorf("Test %d: Incorrect error.\nHave: %v\nWant: %v",
410
- i, err.Error(), test.err)
411
- }
412
- }
413
- }
414
-}
415
-
416
-func TestUnmarshalTextCustomMessage(t *testing.T) {
417
- msg := &textMessage{}
418
- if err := UnmarshalText("custom", msg); err != nil {
419
- t.Errorf("Unexpected error from custom unmarshal: %v", err)
420
- }
421
- if UnmarshalText("not custom", msg) == nil {
422
- t.Errorf("Didn't get expected error from custom unmarshal")
423
- }
424
-}
425
-
426
-// Regression test; this caused a panic.
427
-func TestRepeatedEnum(t *testing.T) {
428
- pb := new(RepeatedEnum)
429
- if err := UnmarshalText("color: RED", pb); err != nil {
430
- t.Fatal(err)
431
- }
432
- exp := &RepeatedEnum{
433
- Color: []RepeatedEnum_Color{RepeatedEnum_RED},
434
- }
435
- if !Equal(pb, exp) {
436
- t.Errorf("Incorrect populated \nHave: %v\nWant: %v", pb, exp)
437
- }
438
-}
439
-
440
-var benchInput string
441
-
442
-func init() {
443
- benchInput = "count: 4\n"
444
- for i := 0; i < 1000; i++ {
445
- benchInput += "pet: \"fido\"\n"
446
- }
447
-
448
- // Check it is valid input.
449
- pb := new(MyMessage)
450
- err := UnmarshalText(benchInput, pb)
451
- if err != nil {
452
- panic("Bad benchmark input: " + err.Error())
453
- }
454
-}
455
-
456
-func BenchmarkUnmarshalText(b *testing.B) {
457
- pb := new(MyMessage)
458
- for i := 0; i < b.N; i++ {
459
- UnmarshalText(benchInput, pb)
460
- }
461
- b.SetBytes(int64(len(benchInput)))
462
-}
Godeps/_workspace/src/code.google.com/p/goprotobuf/proto/clone.go
deleted
-169
@@ -1,169 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2011 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-// Protocol buffer deep copy.
33
-// TODO: MessageSet and RawMessage.
34
-
35
-package proto
36
-
37
-import (
38
- "log"
39
- "reflect"
40
- "strings"
41
-)
42
-
43
-// Clone returns a deep copy of a protocol buffer.
44
-func Clone(pb Message) Message {
45
- in := reflect.ValueOf(pb)
46
- if in.IsNil() {
47
- return pb
48
- }
49
-
50
- out := reflect.New(in.Type().Elem())
51
- // out is empty so a merge is a deep copy.
52
- mergeStruct(out.Elem(), in.Elem())
53
- return out.Interface().(Message)
54
-}
55
-
56
-// Merge merges src into dst.
57
-// Required and optional fields that are set in src will be set to that value in dst.
58
-// Elements of repeated fields will be appended.
59
-// Merge panics if src and dst are not the same type, or if dst is nil.
60
-func Merge(dst, src Message) {
61
- in := reflect.ValueOf(src)
62
- out := reflect.ValueOf(dst)
63
- if out.IsNil() {
64
- panic("proto: nil destination")
65
- }
66
- if in.Type() != out.Type() {
67
- // Explicit test prior to mergeStruct so that mistyped nils will fail
68
- panic("proto: type mismatch")
69
- }
70
- if in.IsNil() {
71
- // Merging nil into non-nil is a quiet no-op
72
- return
73
- }
74
- mergeStruct(out.Elem(), in.Elem())
75
-}
76
-
77
-func mergeStruct(out, in reflect.Value) {
78
- for i := 0; i < in.NumField(); i++ {
79
- f := in.Type().Field(i)
80
- if strings.HasPrefix(f.Name, "XXX_") {
81
- continue
82
- }
83
- mergeAny(out.Field(i), in.Field(i))
84
- }
85
-
86
- if emIn, ok := in.Addr().Interface().(extendableProto); ok {
87
- emOut := out.Addr().Interface().(extendableProto)
88
- mergeExtension(emOut.ExtensionMap(), emIn.ExtensionMap())
89
- }
90
-
91
- uf := in.FieldByName("XXX_unrecognized")
92
- if !uf.IsValid() {
93
- return
94
- }
95
- uin := uf.Bytes()
96
- if len(uin) > 0 {
97
- out.FieldByName("XXX_unrecognized").SetBytes(append([]byte(nil), uin...))
98
- }
99
-}
100
-
101
-func mergeAny(out, in reflect.Value) {
102
- if in.Type() == protoMessageType {
103
- if !in.IsNil() {
104
- if out.IsNil() {
105
- out.Set(reflect.ValueOf(Clone(in.Interface().(Message))))
106
- } else {
107
- Merge(out.Interface().(Message), in.Interface().(Message))
108
- }
109
- }
110
- return
111
- }
112
- switch in.Kind() {
113
- case reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int32, reflect.Int64,
114
- reflect.String, reflect.Uint32, reflect.Uint64:
115
- out.Set(in)
116
- case reflect.Ptr:
117
- if in.IsNil() {
118
- return
119
- }
120
- if out.IsNil() {
121
- out.Set(reflect.New(in.Elem().Type()))
122
- }
123
- mergeAny(out.Elem(), in.Elem())
124
- case reflect.Slice:
125
- if in.IsNil() {
126
- return
127
- }
128
- n := in.Len()
129
- if out.IsNil() {
130
- out.Set(reflect.MakeSlice(in.Type(), 0, n))
131
- }
132
- switch in.Type().Elem().Kind() {
133
- case reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int32, reflect.Int64,
134
- reflect.String, reflect.Uint32, reflect.Uint64:
135
- out.Set(reflect.AppendSlice(out, in))
136
- case reflect.Uint8:
137
- // []byte is a scalar bytes field.
138
- out.Set(in)
139
- default:
140
- for i := 0; i < n; i++ {
141
- x := reflect.Indirect(reflect.New(in.Type().Elem()))
142
- mergeAny(x, in.Index(i))
143
- out.Set(reflect.Append(out, x))
144
- }
145
- }
146
- case reflect.Struct:
147
- mergeStruct(out, in)
148
- default:
149
- // unknown type, so not a protocol buffer
150
- log.Printf("proto: don't know how to copy %v", in)
151
- }
152
-}
153
-
154
-func mergeExtension(out, in map[int32]Extension) {
155
- for extNum, eIn := range in {
156
- eOut := Extension{desc: eIn.desc}
157
- if eIn.value != nil {
158
- v := reflect.New(reflect.TypeOf(eIn.value)).Elem()
159
- mergeAny(v, reflect.ValueOf(eIn.value))
160
- eOut.value = v.Interface()
161
- }
162
- if eIn.enc != nil {
163
- eOut.enc = make([]byte, len(eIn.enc))
164
- copy(eOut.enc, eIn.enc)
165
- }
166
-
167
- out[extNum] = eOut
168
- }
169
-}
Godeps/_workspace/src/code.google.com/p/goprotobuf/proto/decode.go
deleted
-721
@@ -1,721 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto
33
-
34
-/*
35
- * Routines for decoding protocol buffer data to construct in-memory representations.
36
- */
37
-
38
-import (
39
- "errors"
40
- "fmt"
41
- "io"
42
- "os"
43
- "reflect"
44
-)
45
-
46
-// errOverflow is returned when an integer is too large to be represented.
47
-var errOverflow = errors.New("proto: integer overflow")
48
-
49
-// The fundamental decoders that interpret bytes on the wire.
50
-// Those that take integer types all return uint64 and are
51
-// therefore of type valueDecoder.
52
-
53
-// DecodeVarint reads a varint-encoded integer from the slice.
54
-// It returns the integer and the number of bytes consumed, or
55
-// zero if there is not enough.
56
-// This is the format for the
57
-// int32, int64, uint32, uint64, bool, and enum
58
-// protocol buffer types.
59
-func DecodeVarint(buf []byte) (x uint64, n int) {
60
- // x, n already 0
61
- for shift := uint(0); shift < 64; shift += 7 {
62
- if n >= len(buf) {
63
- return 0, 0
64
- }
65
- b := uint64(buf[n])
66
- n++
67
- x |= (b & 0x7F) << shift
68
- if (b & 0x80) == 0 {
69
- return x, n
70
- }
71
- }
72
-
73
- // The number is too large to represent in a 64-bit value.
74
- return 0, 0
75
-}
76
-
77
-// DecodeVarint reads a varint-encoded integer from the Buffer.
78
-// This is the format for the
79
-// int32, int64, uint32, uint64, bool, and enum
80
-// protocol buffer types.
81
-func (p *Buffer) DecodeVarint() (x uint64, err error) {
82
- // x, err already 0
83
-
84
- i := p.index
85
- l := len(p.buf)
86
-
87
- for shift := uint(0); shift < 64; shift += 7 {
88
- if i >= l {
89
- err = io.ErrUnexpectedEOF
90
- return
91
- }
92
- b := p.buf[i]
93
- i++
94
- x |= (uint64(b) & 0x7F) << shift
95
- if b < 0x80 {
96
- p.index = i
97
- return
98
- }
99
- }
100
-
101
- // The number is too large to represent in a 64-bit value.
102
- err = errOverflow
103
- return
104
-}
105
-
106
-// DecodeFixed64 reads a 64-bit integer from the Buffer.
107
-// This is the format for the
108
-// fixed64, sfixed64, and double protocol buffer types.
109
-func (p *Buffer) DecodeFixed64() (x uint64, err error) {
110
- // x, err already 0
111
- i := p.index + 8
112
- if i < 0 || i > len(p.buf) {
113
- err = io.ErrUnexpectedEOF
114
- return
115
- }
116
- p.index = i
117
-
118
- x = uint64(p.buf[i-8])
119
- x |= uint64(p.buf[i-7]) << 8
120
- x |= uint64(p.buf[i-6]) << 16
121
- x |= uint64(p.buf[i-5]) << 24
122
- x |= uint64(p.buf[i-4]) << 32
123
- x |= uint64(p.buf[i-3]) << 40
124
- x |= uint64(p.buf[i-2]) << 48
125
- x |= uint64(p.buf[i-1]) << 56
126
- return
127
-}
128
-
129
-// DecodeFixed32 reads a 32-bit integer from the Buffer.
130
-// This is the format for the
131
-// fixed32, sfixed32, and float protocol buffer types.
132
-func (p *Buffer) DecodeFixed32() (x uint64, err error) {
133
- // x, err already 0
134
- i := p.index + 4
135
- if i < 0 || i > len(p.buf) {
136
- err = io.ErrUnexpectedEOF
137
- return
138
- }
139
- p.index = i
140
-
141
- x = uint64(p.buf[i-4])
142
- x |= uint64(p.buf[i-3]) << 8
143
- x |= uint64(p.buf[i-2]) << 16
144
- x |= uint64(p.buf[i-1]) << 24
145
- return
146
-}
147
-
148
-// DecodeZigzag64 reads a zigzag-encoded 64-bit integer
149
-// from the Buffer.
150
-// This is the format used for the sint64 protocol buffer type.
151
-func (p *Buffer) DecodeZigzag64() (x uint64, err error) {
152
- x, err = p.DecodeVarint()
153
- if err != nil {
154
- return
155
- }
156
- x = (x >> 1) ^ uint64((int64(x&1)<<63)>>63)
157
- return
158
-}
159
-
160
-// DecodeZigzag32 reads a zigzag-encoded 32-bit integer
161
-// from the Buffer.
162
-// This is the format used for the sint32 protocol buffer type.
163
-func (p *Buffer) DecodeZigzag32() (x uint64, err error) {
164
- x, err = p.DecodeVarint()
165
- if err != nil {
166
- return
167
- }
168
- x = uint64((uint32(x) >> 1) ^ uint32((int32(x&1)<<31)>>31))
169
- return
170
-}
171
-
172
-// These are not ValueDecoders: they produce an array of bytes or a string.
173
-// bytes, embedded messages
174
-
175
-// DecodeRawBytes reads a count-delimited byte buffer from the Buffer.
176
-// This is the format used for the bytes protocol buffer
177
-// type and for embedded messages.
178
-func (p *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err error) {
179
- n, err := p.DecodeVarint()
180
- if err != nil {
181
- return
182
- }
183
-
184
- nb := int(n)
185
- if nb < 0 {
186
- return nil, fmt.Errorf("proto: bad byte length %d", nb)
187
- }
188
- end := p.index + nb
189
- if end < p.index || end > len(p.buf) {
190
- return nil, io.ErrUnexpectedEOF
191
- }
192
-
193
- if !alloc {
194
- // todo: check if can get more uses of alloc=false
195
- buf = p.buf[p.index:end]
196
- p.index += nb
197
- return
198
- }
199
-
200
- buf = make([]byte, nb)
201
- copy(buf, p.buf[p.index:])
202
- p.index += nb
203
- return
204
-}
205
-
206
-// DecodeStringBytes reads an encoded string from the Buffer.
207
-// This is the format used for the proto2 string type.
208
-func (p *Buffer) DecodeStringBytes() (s string, err error) {
209
- buf, err := p.DecodeRawBytes(false)
210
- if err != nil {
211
- return
212
- }
213
- return string(buf), nil
214
-}
215
-
216
-// Skip the next item in the buffer. Its wire type is decoded and presented as an argument.
217
-// If the protocol buffer has extensions, and the field matches, add it as an extension.
218
-// Otherwise, if the XXX_unrecognized field exists, append the skipped data there.
219
-func (o *Buffer) skipAndSave(t reflect.Type, tag, wire int, base structPointer, unrecField field) error {
220
- oi := o.index
221
-
222
- err := o.skip(t, tag, wire)
223
- if err != nil {
224
- return err
225
- }
226
-
227
- if !unrecField.IsValid() {
228
- return nil
229
- }
230
-
231
- ptr := structPointer_Bytes(base, unrecField)
232
-
233
- // Add the skipped field to struct field
234
- obuf := o.buf
235
-
236
- o.buf = *ptr
237
- o.EncodeVarint(uint64(tag<<3 | wire))
238
- *ptr = append(o.buf, obuf[oi:o.index]...)
239
-
240
- o.buf = obuf
241
-
242
- return nil
243
-}
244
-
245
-// Skip the next item in the buffer. Its wire type is decoded and presented as an argument.
246
-func (o *Buffer) skip(t reflect.Type, tag, wire int) error {
247
-
248
- var u uint64
249
- var err error
250
-
251
- switch wire {
252
- case WireVarint:
253
- _, err = o.DecodeVarint()
254
- case WireFixed64:
255
- _, err = o.DecodeFixed64()
256
- case WireBytes:
257
- _, err = o.DecodeRawBytes(false)
258
- case WireFixed32:
259
- _, err = o.DecodeFixed32()
260
- case WireStartGroup:
261
- for {
262
- u, err = o.DecodeVarint()
263
- if err != nil {
264
- break
265
- }
266
- fwire := int(u & 0x7)
267
- if fwire == WireEndGroup {
268
- break
269
- }
270
- ftag := int(u >> 3)
271
- err = o.skip(t, ftag, fwire)
272
- if err != nil {
273
- break
274
- }
275
- }
276
- default:
277
- err = fmt.Errorf("proto: can't skip unknown wire type %d for %s", wire, t)
278
- }
279
- return err
280
-}
281
-
282
-// Unmarshaler is the interface representing objects that can
283
-// unmarshal themselves. The method should reset the receiver before
284
-// decoding starts. The argument points to data that may be
285
-// overwritten, so implementations should not keep references to the
286
-// buffer.
287
-type Unmarshaler interface {
288
- Unmarshal([]byte) error
289
-}
290
-
291
-// Unmarshal parses the protocol buffer representation in buf and places the
292
-// decoded result in pb. If the struct underlying pb does not match
293
-// the data in buf, the results can be unpredictable.
294
-//
295
-// Unmarshal resets pb before starting to unmarshal, so any
296
-// existing data in pb is always removed. Use UnmarshalMerge
297
-// to preserve and append to existing data.
298
-func Unmarshal(buf []byte, pb Message) error {
299
- pb.Reset()
300
- return UnmarshalMerge(buf, pb)
301
-}
302
-
303
-// UnmarshalMerge parses the protocol buffer representation in buf and
304
-// writes the decoded result to pb. If the struct underlying pb does not match
305
-// the data in buf, the results can be unpredictable.
306
-//
307
-// UnmarshalMerge merges into existing data in pb.
308
-// Most code should use Unmarshal instead.
309
-func UnmarshalMerge(buf []byte, pb Message) error {
310
- // If the object can unmarshal itself, let it.
311
- if u, ok := pb.(Unmarshaler); ok {
312
- return u.Unmarshal(buf)
313
- }
314
- return NewBuffer(buf).Unmarshal(pb)
315
-}
316
-
317
-// Unmarshal parses the protocol buffer representation in the
318
-// Buffer and places the decoded result in pb. If the struct
319
-// underlying pb does not match the data in the buffer, the results can be
320
-// unpredictable.
321
-func (p *Buffer) Unmarshal(pb Message) error {
322
- // If the object can unmarshal itself, let it.
323
- if u, ok := pb.(Unmarshaler); ok {
324
- err := u.Unmarshal(p.buf[p.index:])
325
- p.index = len(p.buf)
326
- return err
327
- }
328
-
329
- typ, base, err := getbase(pb)
330
- if err != nil {
331
- return err
332
- }
333
-
334
- err = p.unmarshalType(typ.Elem(), GetProperties(typ.Elem()), false, base)
335
-
336
- if collectStats {
337
- stats.Decode++
338
- }
339
-
340
- return err
341
-}
342
-
343
-// unmarshalType does the work of unmarshaling a structure.
344
-func (o *Buffer) unmarshalType(st reflect.Type, prop *StructProperties, is_group bool, base structPointer) error {
345
- var state errorState
346
- required, reqFields := prop.reqCount, uint64(0)
347
-
348
- var err error
349
- for err == nil && o.index < len(o.buf) {
350
- oi := o.index
351
- var u uint64
352
- u, err = o.DecodeVarint()
353
- if err != nil {
354
- break
355
- }
356
- wire := int(u & 0x7)
357
- if wire == WireEndGroup {
358
- if is_group {
359
- return nil // input is satisfied
360
- }
361
- return fmt.Errorf("proto: %s: wiretype end group for non-group", st)
362
- }
363
- tag := int(u >> 3)
364
- if tag <= 0 {
365
- return fmt.Errorf("proto: %s: illegal tag %d", st, tag)
366
- }
367
- fieldnum, ok := prop.decoderTags.get(tag)
368
- if !ok {
369
- // Maybe it's an extension?
370
- if prop.extendable {
371
- if e := structPointer_Interface(base, st).(extendableProto); isExtensionField(e, int32(tag)) {
372
- if err = o.skip(st, tag, wire); err == nil {
373
- ext := e.ExtensionMap()[int32(tag)] // may be missing
374
- ext.enc = append(ext.enc, o.buf[oi:o.index]...)
375
- e.ExtensionMap()[int32(tag)] = ext
376
- }
377
- continue
378
- }
379
- }
380
- err = o.skipAndSave(st, tag, wire, base, prop.unrecField)
381
- continue
382
- }
383
- p := prop.Prop[fieldnum]
384
-
385
- if p.dec == nil {
386
- fmt.Fprintf(os.Stderr, "proto: no protobuf decoder for %s.%s\n", st, st.Field(fieldnum).Name)
387
- continue
388
- }
389
- dec := p.dec
390
- if wire != WireStartGroup && wire != p.WireType {
391
- if wire == WireBytes && p.packedDec != nil {
392
- // a packable field
393
- dec = p.packedDec
394
- } else {
395
- err = fmt.Errorf("proto: bad wiretype for field %s.%s: got wiretype %d, want %d", st, st.Field(fieldnum).Name, wire, p.WireType)
396
- continue
397
- }
398
- }
399
- decErr := dec(o, p, base)
400
- if decErr != nil && !state.shouldContinue(decErr, p) {
401
- err = decErr
402
- }
403
- if err == nil && p.Required {
404
- // Successfully decoded a required field.
405
- if tag <= 64 {
406
- // use bitmap for fields 1-64 to catch field reuse.
407
- var mask uint64 = 1 << uint64(tag-1)
408
- if reqFields&mask == 0 {
409
- // new required field
410
- reqFields |= mask
411
- required--
412
- }
413
- } else {
414
- // This is imprecise. It can be fooled by a required field
415
- // with a tag > 64 that is encoded twice; that's very rare.
416
- // A fully correct implementation would require allocating
417
- // a data structure, which we would like to avoid.
418
- required--
419
- }
420
- }
421
- }
422
- if err == nil {
423
- if is_group {
424
- return io.ErrUnexpectedEOF
425
- }
426
- if state.err != nil {
427
- return state.err
428
- }
429
- if required > 0 {
430
- // Not enough information to determine the exact field. If we use extra
431
- // CPU, we could determine the field only if the missing required field
432
- // has a tag <= 64 and we check reqFields.
433
- return &RequiredNotSetError{"{Unknown}"}
434
- }
435
- }
436
- return err
437
-}
438
-
439
-// Individual type decoders
440
-// For each,
441
-// u is the decoded value,
442
-// v is a pointer to the field (pointer) in the struct
443
-
444
-// Sizes of the pools to allocate inside the Buffer.
445
-// The goal is modest amortization and allocation
446
-// on at least 16-byte boundaries.
447
-const (
448
- boolPoolSize = 16
449
- uint32PoolSize = 8
450
- uint64PoolSize = 4
451
-)
452
-
453
-// Decode a bool.
454
-func (o *Buffer) dec_bool(p *Properties, base structPointer) error {
455
- u, err := p.valDec(o)
456
- if err != nil {
457
- return err
458
- }
459
- if len(o.bools) == 0 {
460
- o.bools = make([]bool, boolPoolSize)
461
- }
462
- o.bools[0] = u != 0
463
- *structPointer_Bool(base, p.field) = &o.bools[0]
464
- o.bools = o.bools[1:]
465
- return nil
466
-}
467
-
468
-// Decode an int32.
469
-func (o *Buffer) dec_int32(p *Properties, base structPointer) error {
470
- u, err := p.valDec(o)
471
- if err != nil {
472
- return err
473
- }
474
- word32_Set(structPointer_Word32(base, p.field), o, uint32(u))
475
- return nil
476
-}
477
-
478
-// Decode an int64.
479
-func (o *Buffer) dec_int64(p *Properties, base structPointer) error {
480
- u, err := p.valDec(o)
481
- if err != nil {
482
- return err
483
- }
484
- word64_Set(structPointer_Word64(base, p.field), o, u)
485
- return nil
486
-}
487
-
488
-// Decode a string.
489
-func (o *Buffer) dec_string(p *Properties, base structPointer) error {
490
- s, err := o.DecodeStringBytes()
491
- if err != nil {
492
- return err
493
- }
494
- sp := new(string)
495
- *sp = s
496
- *structPointer_String(base, p.field) = sp
497
- return nil
498
-}
499
-
500
-// Decode a slice of bytes ([]byte).
501
-func (o *Buffer) dec_slice_byte(p *Properties, base structPointer) error {
502
- b, err := o.DecodeRawBytes(true)
503
- if err != nil {
504
- return err
505
- }
506
- *structPointer_Bytes(base, p.field) = b
507
- return nil
508
-}
509
-
510
-// Decode a slice of bools ([]bool).
511
-func (o *Buffer) dec_slice_bool(p *Properties, base structPointer) error {
512
- u, err := p.valDec(o)
513
- if err != nil {
514
- return err
515
- }
516
- v := structPointer_BoolSlice(base, p.field)
517
- *v = append(*v, u != 0)
518
- return nil
519
-}
520
-
521
-// Decode a slice of bools ([]bool) in packed format.
522
-func (o *Buffer) dec_slice_packed_bool(p *Properties, base structPointer) error {
523
- v := structPointer_BoolSlice(base, p.field)
524
-
525
- nn, err := o.DecodeVarint()
526
- if err != nil {
527
- return err
528
- }
529
- nb := int(nn) // number of bytes of encoded bools
530
-
531
- y := *v
532
- for i := 0; i < nb; i++ {
533
- u, err := p.valDec(o)
534
- if err != nil {
535
- return err
536
- }
537
- y = append(y, u != 0)
538
- }
539
-
540
- *v = y
541
- return nil
542
-}
543
-
544
-// Decode a slice of int32s ([]int32).
545
-func (o *Buffer) dec_slice_int32(p *Properties, base structPointer) error {
546
- u, err := p.valDec(o)
547
- if err != nil {
548
- return err
549
- }
550
- structPointer_Word32Slice(base, p.field).Append(uint32(u))
551
- return nil
552
-}
553
-
554
-// Decode a slice of int32s ([]int32) in packed format.
555
-func (o *Buffer) dec_slice_packed_int32(p *Properties, base structPointer) error {
556
- v := structPointer_Word32Slice(base, p.field)
557
-
558
- nn, err := o.DecodeVarint()
559
- if err != nil {
560
- return err
561
- }
562
- nb := int(nn) // number of bytes of encoded int32s
563
-
564
- fin := o.index + nb
565
- if fin < o.index {
566
- return errOverflow
567
- }
568
- for o.index < fin {
569
- u, err := p.valDec(o)
570
- if err != nil {
571
- return err
572
- }
573
- v.Append(uint32(u))
574
- }
575
- return nil
576
-}
577
-
578
-// Decode a slice of int64s ([]int64).
579
-func (o *Buffer) dec_slice_int64(p *Properties, base structPointer) error {
580
- u, err := p.valDec(o)
581
- if err != nil {
582
- return err
583
- }
584
-
585
- structPointer_Word64Slice(base, p.field).Append(u)
586
- return nil
587
-}
588
-
589
-// Decode a slice of int64s ([]int64) in packed format.
590
-func (o *Buffer) dec_slice_packed_int64(p *Properties, base structPointer) error {
591
- v := structPointer_Word64Slice(base, p.field)
592
-
593
- nn, err := o.DecodeVarint()
594
- if err != nil {
595
- return err
596
- }
597
- nb := int(nn) // number of bytes of encoded int64s
598
-
599
- fin := o.index + nb
600
- if fin < o.index {
601
- return errOverflow
602
- }
603
- for o.index < fin {
604
- u, err := p.valDec(o)
605
- if err != nil {
606
- return err
607
- }
608
- v.Append(u)
609
- }
610
- return nil
611
-}
612
-
613
-// Decode a slice of strings ([]string).
614
-func (o *Buffer) dec_slice_string(p *Properties, base structPointer) error {
615
- s, err := o.DecodeStringBytes()
616
- if err != nil {
617
- return err
618
- }
619
- v := structPointer_StringSlice(base, p.field)
620
- *v = append(*v, s)
621
- return nil
622
-}
623
-
624
-// Decode a slice of slice of bytes ([][]byte).
625
-func (o *Buffer) dec_slice_slice_byte(p *Properties, base structPointer) error {
626
- b, err := o.DecodeRawBytes(true)
627
- if err != nil {
628
- return err
629
- }
630
- v := structPointer_BytesSlice(base, p.field)
631
- *v = append(*v, b)
632
- return nil
633
-}
634
-
635
-// Decode a group.
636
-func (o *Buffer) dec_struct_group(p *Properties, base structPointer) error {
637
- bas := structPointer_GetStructPointer(base, p.field)
638
- if structPointer_IsNil(bas) {
639
- // allocate new nested message
640
- bas = toStructPointer(reflect.New(p.stype))
641
- structPointer_SetStructPointer(base, p.field, bas)
642
- }
643
- return o.unmarshalType(p.stype, p.sprop, true, bas)
644
-}
645
-
646
-// Decode an embedded message.
647
-func (o *Buffer) dec_struct_message(p *Properties, base structPointer) (err error) {
648
- raw, e := o.DecodeRawBytes(false)
649
- if e != nil {
650
- return e
651
- }
652
-
653
- bas := structPointer_GetStructPointer(base, p.field)
654
- if structPointer_IsNil(bas) {
655
- // allocate new nested message
656
- bas = toStructPointer(reflect.New(p.stype))
657
- structPointer_SetStructPointer(base, p.field, bas)
658
- }
659
-
660
- // If the object can unmarshal itself, let it.
661
- if p.isUnmarshaler {
662
- iv := structPointer_Interface(bas, p.stype)
663
- return iv.(Unmarshaler).Unmarshal(raw)
664
- }
665
-
666
- obuf := o.buf
667
- oi := o.index
668
- o.buf = raw
669
- o.index = 0
670
-
671
- err = o.unmarshalType(p.stype, p.sprop, false, bas)
672
- o.buf = obuf
673
- o.index = oi
674
-
675
- return err
676
-}
677
-
678
-// Decode a slice of embedded messages.
679
-func (o *Buffer) dec_slice_struct_message(p *Properties, base structPointer) error {
680
- return o.dec_slice_struct(p, false, base)
681
-}
682
-
683
-// Decode a slice of embedded groups.
684
-func (o *Buffer) dec_slice_struct_group(p *Properties, base structPointer) error {
685
- return o.dec_slice_struct(p, true, base)
686
-}
687
-
688
-// Decode a slice of structs ([]*struct).
689
-func (o *Buffer) dec_slice_struct(p *Properties, is_group bool, base structPointer) error {
690
- v := reflect.New(p.stype)
691
- bas := toStructPointer(v)
692
- structPointer_StructPointerSlice(base, p.field).Append(bas)
693
-
694
- if is_group {
695
- err := o.unmarshalType(p.stype, p.sprop, is_group, bas)
696
- return err
697
- }
698
-
699
- raw, err := o.DecodeRawBytes(false)
700
- if err != nil {
701
- return err
702
- }
703
-
704
- // If the object can unmarshal itself, let it.
705
- if p.isUnmarshaler {
706
- iv := v.Interface()
707
- return iv.(Unmarshaler).Unmarshal(raw)
708
- }
709
-
710
- obuf := o.buf
711
- oi := o.index
712
- o.buf = raw
713
- o.index = 0
714
-
715
- err = o.unmarshalType(p.stype, p.sprop, is_group, bas)
716
-
717
- o.buf = obuf
718
- o.index = oi
719
-
720
- return err
721
-}
Godeps/_workspace/src/code.google.com/p/goprotobuf/proto/extensions.go
deleted
-351
@@ -1,351 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto
33
-
34
-/*
35
- * Types and routines for supporting protocol buffer extensions.
36
- */
37
-
38
-import (
39
- "errors"
40
- "reflect"
41
- "strconv"
42
- "sync"
43
-)
44
-
45
-// ErrMissingExtension is the error returned by GetExtension if the named extension is not in the message.
46
-var ErrMissingExtension = errors.New("proto: missing extension")
47
-
48
-// ExtensionRange represents a range of message extensions for a protocol buffer.
49
-// Used in code generated by the protocol compiler.
50
-type ExtensionRange struct {
51
- Start, End int32 // both inclusive
52
-}
53
-
54
-// extendableProto is an interface implemented by any protocol buffer that may be extended.
55
-type extendableProto interface {
56
- Message
57
- ExtensionRangeArray() []ExtensionRange
58
- ExtensionMap() map[int32]Extension
59
-}
60
-
61
-var extendableProtoType = reflect.TypeOf((*extendableProto)(nil)).Elem()
62
-
63
-// ExtensionDesc represents an extension specification.
64
-// Used in generated code from the protocol compiler.
65
-type ExtensionDesc struct {
66
- ExtendedType Message // nil pointer to the type that is being extended
67
- ExtensionType interface{} // nil pointer to the extension type
68
- Field int32 // field number
69
- Name string // fully-qualified name of extension, for text formatting
70
- Tag string // protobuf tag style
71
-}
72
-
73
-func (ed *ExtensionDesc) repeated() bool {
74
- t := reflect.TypeOf(ed.ExtensionType)
75
- return t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8
76
-}
77
-
78
-// Extension represents an extension in a message.
79
-type Extension struct {
80
- // When an extension is stored in a message using SetExtension
81
- // only desc and value are set. When the message is marshaled
82
- // enc will be set to the encoded form of the message.
83
- //
84
- // When a message is unmarshaled and contains extensions, each
85
- // extension will have only enc set. When such an extension is
86
- // accessed using GetExtension (or GetExtensions) desc and value
87
- // will be set.
88
- desc *ExtensionDesc
89
- value interface{}
90
- enc []byte
91
-}
92
-
93
-// SetRawExtension is for testing only.
94
-func SetRawExtension(base extendableProto, id int32, b []byte) {
95
- base.ExtensionMap()[id] = Extension{enc: b}
96
-}
97
-
98
-// isExtensionField returns true iff the given field number is in an extension range.
99
-func isExtensionField(pb extendableProto, field int32) bool {
100
- for _, er := range pb.ExtensionRangeArray() {
101
- if er.Start <= field && field <= er.End {
102
- return true
103
- }
104
- }
105
- return false
106
-}
107
-
108
-// checkExtensionTypes checks that the given extension is valid for pb.
109
-func checkExtensionTypes(pb extendableProto, extension *ExtensionDesc) error {
110
- // Check the extended type.
111
- if a, b := reflect.TypeOf(pb), reflect.TypeOf(extension.ExtendedType); a != b {
112
- return errors.New("proto: bad extended type; " + b.String() + " does not extend " + a.String())
113
- }
114
- // Check the range.
115
- if !isExtensionField(pb, extension.Field) {
116
- return errors.New("proto: bad extension number; not in declared ranges")
117
- }
118
- return nil
119
-}
120
-
121
-// extPropKey is sufficient to uniquely identify an extension.
122
-type extPropKey struct {
123
- base reflect.Type
124
- field int32
125
-}
126
-
127
-var extProp = struct {
128
- sync.RWMutex
129
- m map[extPropKey]*Properties
130
-}{
131
- m: make(map[extPropKey]*Properties),
132
-}
133
-
134
-func extensionProperties(ed *ExtensionDesc) *Properties {
135
- key := extPropKey{base: reflect.TypeOf(ed.ExtendedType), field: ed.Field}
136
-
137
- extProp.RLock()
138
- if prop, ok := extProp.m[key]; ok {
139
- extProp.RUnlock()
140
- return prop
141
- }
142
- extProp.RUnlock()
143
-
144
- extProp.Lock()
145
- defer extProp.Unlock()
146
- // Check again.
147
- if prop, ok := extProp.m[key]; ok {
148
- return prop
149
- }
150
-
151
- prop := new(Properties)
152
- prop.Init(reflect.TypeOf(ed.ExtensionType), "unknown_name", ed.Tag, nil)
153
- extProp.m[key] = prop
154
- return prop
155
-}
156
-
157
-// encodeExtensionMap encodes any unmarshaled (unencoded) extensions in m.
158
-func encodeExtensionMap(m map[int32]Extension) error {
159
- for k, e := range m {
160
- if e.value == nil || e.desc == nil {
161
- // Extension is only in its encoded form.
162
- continue
163
- }
164
-
165
- // We don't skip extensions that have an encoded form set,
166
- // because the extension value may have been mutated after
167
- // the last time this function was called.
168
-
169
- et := reflect.TypeOf(e.desc.ExtensionType)
170
- props := extensionProperties(e.desc)
171
-
172
- p := NewBuffer(nil)
173
- // If e.value has type T, the encoder expects a *struct{ X T }.
174
- // Pass a *T with a zero field and hope it all works out.
175
- x := reflect.New(et)
176
- x.Elem().Set(reflect.ValueOf(e.value))
177
- if err := props.enc(p, props, toStructPointer(x)); err != nil {
178
- return err
179
- }
180
- e.enc = p.buf
181
- m[k] = e
182
- }
183
- return nil
184
-}
185
-
186
-func sizeExtensionMap(m map[int32]Extension) (n int) {
187
- for _, e := range m {
188
- if e.value == nil || e.desc == nil {
189
- // Extension is only in its encoded form.
190
- n += len(e.enc)
191
- continue
192
- }
193
-
194
- // We don't skip extensions that have an encoded form set,
195
- // because the extension value may have been mutated after
196
- // the last time this function was called.
197
-
198
- et := reflect.TypeOf(e.desc.ExtensionType)
199
- props := extensionProperties(e.desc)
200
-
201
- // If e.value has type T, the encoder expects a *struct{ X T }.
202
- // Pass a *T with a zero field and hope it all works out.
203
- x := reflect.New(et)
204
- x.Elem().Set(reflect.ValueOf(e.value))
205
- n += props.size(props, toStructPointer(x))
206
- }
207
- return
208
-}
209
-
210
-// HasExtension returns whether the given extension is present in pb.
211
-func HasExtension(pb extendableProto, extension *ExtensionDesc) bool {
212
- // TODO: Check types, field numbers, etc.?
213
- _, ok := pb.ExtensionMap()[extension.Field]
214
- return ok
215
-}
216
-
217
-// ClearExtension removes the given extension from pb.
218
-func ClearExtension(pb extendableProto, extension *ExtensionDesc) {
219
- // TODO: Check types, field numbers, etc.?
220
- delete(pb.ExtensionMap(), extension.Field)
221
-}
222
-
223
-// GetExtension parses and returns the given extension of pb.
224
-// If the extension is not present it returns ErrMissingExtension.
225
-func GetExtension(pb extendableProto, extension *ExtensionDesc) (interface{}, error) {
226
- if err := checkExtensionTypes(pb, extension); err != nil {
227
- return nil, err
228
- }
229
-
230
- e, ok := pb.ExtensionMap()[extension.Field]
231
- if !ok {
232
- return nil, ErrMissingExtension
233
- }
234
- if e.value != nil {
235
- // Already decoded. Check the descriptor, though.
236
- if e.desc != extension {
237
- // This shouldn't happen. If it does, it means that
238
- // GetExtension was called twice with two different
239
- // descriptors with the same field number.
240
- return nil, errors.New("proto: descriptor conflict")
241
- }
242
- return e.value, nil
243
- }
244
-
245
- v, err := decodeExtension(e.enc, extension)
246
- if err != nil {
247
- return nil, err
248
- }
249
-
250
- // Remember the decoded version and drop the encoded version.
251
- // That way it is safe to mutate what we return.
252
- e.value = v
253
- e.desc = extension
254
- e.enc = nil
255
- return e.value, nil
256
-}
257
-
258
-// decodeExtension decodes an extension encoded in b.
259
-func decodeExtension(b []byte, extension *ExtensionDesc) (interface{}, error) {
260
- o := NewBuffer(b)
261
-
262
- t := reflect.TypeOf(extension.ExtensionType)
263
- rep := extension.repeated()
264
-
265
- props := extensionProperties(extension)
266
-
267
- // t is a pointer to a struct, pointer to basic type or a slice.
268
- // Allocate a "field" to store the pointer/slice itself; the
269
- // pointer/slice will be stored here. We pass
270
- // the address of this field to props.dec.
271
- // This passes a zero field and a *t and lets props.dec
272
- // interpret it as a *struct{ x t }.
273
- value := reflect.New(t).Elem()
274
-
275
- for {
276
- // Discard wire type and field number varint. It isn't needed.
277
- if _, err := o.DecodeVarint(); err != nil {
278
- return nil, err
279
- }
280
-
281
- if err := props.dec(o, props, toStructPointer(value.Addr())); err != nil {
282
- return nil, err
283
- }
284
-
285
- if !rep || o.index >= len(o.buf) {
286
- break
287
- }
288
- }
289
- return value.Interface(), nil
290
-}
291
-
292
-// GetExtensions returns a slice of the extensions present in pb that are also listed in es.
293
-// The returned slice has the same length as es; missing extensions will appear as nil elements.
294
-func GetExtensions(pb Message, es []*ExtensionDesc) (extensions []interface{}, err error) {
295
- epb, ok := pb.(extendableProto)
296
- if !ok {
297
- err = errors.New("proto: not an extendable proto")
298
- return
299
- }
300
- extensions = make([]interface{}, len(es))
301
- for i, e := range es {
302
- extensions[i], err = GetExtension(epb, e)
303
- if err == ErrMissingExtension {
304
- err = nil
305
- }
306
- if err != nil {
307
- return
308
- }
309
- }
310
- return
311
-}
312
-
313
-// SetExtension sets the specified extension of pb to the specified value.
314
-func SetExtension(pb extendableProto, extension *ExtensionDesc, value interface{}) error {
315
- if err := checkExtensionTypes(pb, extension); err != nil {
316
- return err
317
- }
318
- typ := reflect.TypeOf(extension.ExtensionType)
319
- if typ != reflect.TypeOf(value) {
320
- return errors.New("proto: bad extension value type")
321
- }
322
-
323
- pb.ExtensionMap()[extension.Field] = Extension{desc: extension, value: value}
324
- return nil
325
-}
326
-
327
-// A global registry of extensions.
328
-// The generated code will register the generated descriptors by calling RegisterExtension.
329
-
330
-var extensionMaps = make(map[reflect.Type]map[int32]*ExtensionDesc)
331
-
332
-// RegisterExtension is called from the generated code.
333
-func RegisterExtension(desc *ExtensionDesc) {
334
- st := reflect.TypeOf(desc.ExtendedType).Elem()
335
- m := extensionMaps[st]
336
- if m == nil {
337
- m = make(map[int32]*ExtensionDesc)
338
- extensionMaps[st] = m
339
- }
340
- if _, ok := m[desc.Field]; ok {
341
- panic("proto: duplicate extension registered: " + st.String() + " " + strconv.Itoa(int(desc.Field)))
342
- }
343
- m[desc.Field] = desc
344
-}
345
-
346
-// RegisteredExtensions returns a map of the registered extensions of a
347
-// protocol buffer struct, indexed by the extension number.
348
-// The argument pb should be a nil pointer to the struct type.
349
-func RegisteredExtensions(pb Message) map[int32]*ExtensionDesc {
350
- return extensionMaps[reflect.TypeOf(pb).Elem()]
351
-}
Godeps/_workspace/src/code.google.com/p/goprotobuf/proto/testdata/Makefile
deleted
-50
@@ -1,50 +0,0 @@
1
-# Go support for Protocol Buffers - Google's data interchange format
2
-#
3
-# Copyright 2010 The Go Authors. All rights reserved.
4
-# http://code.google.com/p/goprotobuf/
5
-#
6
-# Redistribution and use in source and binary forms, with or without
7
-# modification, are permitted provided that the following conditions are
8
-# met:
9
-#
10
-# * Redistributions of source code must retain the above copyright
11
-# notice, this list of conditions and the following disclaimer.
12
-# * Redistributions in binary form must reproduce the above
13
-# copyright notice, this list of conditions and the following disclaimer
14
-# in the documentation and/or other materials provided with the
15
-# distribution.
16
-# * Neither the name of Google Inc. nor the names of its
17
-# contributors may be used to endorse or promote products derived from
18
-# this software without specific prior written permission.
19
-#
20
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-
33
-include ../../Make.protobuf
34
-
35
-all: regenerate
36
-
37
-regenerate:
38
- rm -f test.pb.go
39
- make test.pb.go
40
-
41
-# The following rules are just aids to development. Not needed for typical testing.
42
-
43
-diff: regenerate
44
- hg diff test.pb.go
45
-
46
-restore:
47
- cp test.pb.go.golden test.pb.go
48
-
49
-preserve:
50
- cp test.pb.go test.pb.go.golden
Godeps/_workspace/src/code.google.com/p/goprotobuf/proto/testdata/golden_test.go
deleted
-86
@@ -1,86 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2012 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-// Verify that the compiler output for test.proto is unchanged.
33
-
34
-package testdata
35
-
36
-import (
37
- "crypto/sha1"
38
- "fmt"
39
- "io/ioutil"
40
- "os"
41
- "os/exec"
42
- "path/filepath"
43
- "testing"
44
-)
45
-
46
-// sum returns in string form (for easy comparison) the SHA-1 hash of the named file.
47
-func sum(t *testing.T, name string) string {
48
- data, err := ioutil.ReadFile(name)
49
- if err != nil {
50
- t.Fatal(err)
51
- }
52
- t.Logf("sum(%q): length is %d", name, len(data))
53
- hash := sha1.New()
54
- _, err = hash.Write(data)
55
- if err != nil {
56
- t.Fatal(err)
57
- }
58
- return fmt.Sprintf("% x", hash.Sum(nil))
59
-}
60
-
61
-func run(t *testing.T, name string, args ...string) {
62
- cmd := exec.Command(name, args...)
63
- cmd.Stdin = os.Stdin
64
- cmd.Stdout = os.Stdout
65
- cmd.Stderr = os.Stderr
66
- err := cmd.Run()
67
- if err != nil {
68
- t.Fatal(err)
69
- }
70
-}
71
-
72
-func TestGolden(t *testing.T) {
73
- // Compute the original checksum.
74
- goldenSum := sum(t, "test.pb.go")
75
- // Run the proto compiler.
76
- run(t, "protoc", "--go_out="+os.TempDir(), "test.proto")
77
- newFile := filepath.Join(os.TempDir(), "test.pb.go")
78
- defer os.Remove(newFile)
79
- // Compute the new checksum.
80
- newSum := sum(t, newFile)
81
- // Verify
82
- if newSum != goldenSum {
83
- run(t, "diff", "-u", "test.pb.go", newFile)
84
- t.Fatal("Code generated by protoc-gen-go has changed; update test.pb.go")
85
- }
86
-}
Godeps/_workspace/src/code.google.com/p/goprotobuf/proto/text.go
deleted
-701
@@ -1,701 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto
33
-
34
-// Functions for writing the text protocol buffer format.
35
-
36
-import (
37
- "bufio"
38
- "bytes"
39
- "fmt"
40
- "io"
41
- "log"
42
- "math"
43
- "os"
44
- "reflect"
45
- "sort"
46
- "strings"
47
-)
48
-
49
-var (
50
- newline = []byte("\n")
51
- spaces = []byte(" ")
52
- gtNewline = []byte(">\n")
53
- endBraceNewline = []byte("}\n")
54
- backslashN = []byte{'\\', 'n'}
55
- backslashR = []byte{'\\', 'r'}
56
- backslashT = []byte{'\\', 't'}
57
- backslashDQ = []byte{'\\', '"'}
58
- backslashBS = []byte{'\\', '\\'}
59
- posInf = []byte("inf")
60
- negInf = []byte("-inf")
61
- nan = []byte("nan")
62
-)
63
-
64
-type writer interface {
65
- io.Writer
66
- WriteByte(byte) error
67
-}
68
-
69
-// textWriter is an io.Writer that tracks its indentation level.
70
-type textWriter struct {
71
- ind int
72
- complete bool // if the current position is a complete line
73
- compact bool // whether to write out as a one-liner
74
- w writer
75
-}
76
-
77
-// textMarshaler is implemented by Messages that can marshal themsleves.
78
-// It is identical to encoding.TextMarshaler, introduced in go 1.2,
79
-// which will eventually replace it.
80
-type textMarshaler interface {
81
- MarshalText() (text []byte, err error)
82
-}
83
-
84
-func (w *textWriter) WriteString(s string) (n int, err error) {
85
- if !strings.Contains(s, "\n") {
86
- if !w.compact && w.complete {
87
- w.writeIndent()
88
- }
89
- w.complete = false
90
- return io.WriteString(w.w, s)
91
- }
92
- // WriteString is typically called without newlines, so this
93
- // codepath and its copy are rare. We copy to avoid
94
- // duplicating all of Write's logic here.
95
- return w.Write([]byte(s))
96
-}
97
-
98
-func (w *textWriter) Write(p []byte) (n int, err error) {
99
- newlines := bytes.Count(p, newline)
100
- if newlines == 0 {
101
- if !w.compact && w.complete {
102
- w.writeIndent()
103
- }
104
- n, err = w.w.Write(p)
105
- w.complete = false
106
- return n, err
107
- }
108
-
109
- frags := bytes.SplitN(p, newline, newlines+1)
110
- if w.compact {
111
- for i, frag := range frags {
112
- if i > 0 {
113
- if err := w.w.WriteByte(' '); err != nil {
114
- return n, err
115
- }
116
- n++
117
- }
118
- nn, err := w.w.Write(frag)
119
- n += nn
120
- if err != nil {
121
- return n, err
122
- }
123
- }
124
- return n, nil
125
- }
126
-
127
- for i, frag := range frags {
128
- if w.complete {
129
- w.writeIndent()
130
- }
131
- nn, err := w.w.Write(frag)
132
- n += nn
133
- if err != nil {
134
- return n, err
135
- }
136
- if i+1 < len(frags) {
137
- if err := w.w.WriteByte('\n'); err != nil {
138
- return n, err
139
- }
140
- n++
141
- }
142
- }
143
- w.complete = len(frags[len(frags)-1]) == 0
144
- return n, nil
145
-}
146
-
147
-func (w *textWriter) WriteByte(c byte) error {
148
- if w.compact && c == '\n' {
149
- c = ' '
150
- }
151
- if !w.compact && w.complete {
152
- w.writeIndent()
153
- }
154
- err := w.w.WriteByte(c)
155
- w.complete = c == '\n'
156
- return err
157
-}
158
-
159
-func (w *textWriter) indent() { w.ind++ }
160
-
161
-func (w *textWriter) unindent() {
162
- if w.ind == 0 {
163
- log.Printf("proto: textWriter unindented too far")
164
- return
165
- }
166
- w.ind--
167
-}
168
-
169
-func writeName(w *textWriter, props *Properties) error {
170
- if _, err := w.WriteString(props.OrigName); err != nil {
171
- return err
172
- }
173
- if props.Wire != "group" {
174
- return w.WriteByte(':')
175
- }
176
- return nil
177
-}
178
-
179
-var (
180
- messageSetType = reflect.TypeOf((*MessageSet)(nil)).Elem()
181
-)
182
-
183
-// raw is the interface satisfied by RawMessage.
184
-type raw interface {
185
- Bytes() []byte
186
-}
187
-
188
-func writeStruct(w *textWriter, sv reflect.Value) error {
189
- if sv.Type() == messageSetType {
190
- return writeMessageSet(w, sv.Addr().Interface().(*MessageSet))
191
- }
192
-
193
- st := sv.Type()
194
- sprops := GetProperties(st)
195
- for i := 0; i < sv.NumField(); i++ {
196
- fv := sv.Field(i)
197
- props := sprops.Prop[i]
198
- name := st.Field(i).Name
199
-
200
- if strings.HasPrefix(name, "XXX_") {
201
- // There are two XXX_ fields:
202
- // XXX_unrecognized []byte
203
- // XXX_extensions map[int32]proto.Extension
204
- // The first is handled here;
205
- // the second is handled at the bottom of this function.
206
- if name == "XXX_unrecognized" && !fv.IsNil() {
207
- if err := writeUnknownStruct(w, fv.Interface().([]byte)); err != nil {
208
- return err
209
- }
210
- }
211
- continue
212
- }
213
- if fv.Kind() == reflect.Ptr && fv.IsNil() {
214
- // Field not filled in. This could be an optional field or
215
- // a required field that wasn't filled in. Either way, there
216
- // isn't anything we can show for it.
217
- continue
218
- }
219
- if fv.Kind() == reflect.Slice && fv.IsNil() {
220
- // Repeated field that is empty, or a bytes field that is unused.
221
- continue
222
- }
223
-
224
- if props.Repeated && fv.Kind() == reflect.Slice {
225
- // Repeated field.
226
- for j := 0; j < fv.Len(); j++ {
227
- if err := writeName(w, props); err != nil {
228
- return err
229
- }
230
- if !w.compact {
231
- if err := w.WriteByte(' '); err != nil {
232
- return err
233
- }
234
- }
235
- v := fv.Index(j)
236
- if v.Kind() == reflect.Ptr && v.IsNil() {
237
- // A nil message in a repeated field is not valid,
238
- // but we can handle that more gracefully than panicking.
239
- if _, err := w.Write([]byte("<nil>\n")); err != nil {
240
- return err
241
- }
242
- continue
243
- }
244
- if err := writeAny(w, v, props); err != nil {
245
- return err
246
- }
247
- if err := w.WriteByte('\n'); err != nil {
248
- return err
249
- }
250
- }
251
- continue
252
- }
253
-
254
- if err := writeName(w, props); err != nil {
255
- return err
256
- }
257
- if !w.compact {
258
- if err := w.WriteByte(' '); err != nil {
259
- return err
260
- }
261
- }
262
- if b, ok := fv.Interface().(raw); ok {
263
- if err := writeRaw(w, b.Bytes()); err != nil {
264
- return err
265
- }
266
- continue
267
- }
268
-
269
- // Enums have a String method, so writeAny will work fine.
270
- if err := writeAny(w, fv, props); err != nil {
271
- return err
272
- }
273
-
274
- if err := w.WriteByte('\n'); err != nil {
275
- return err
276
- }
277
- }
278
-
279
- // Extensions (the XXX_extensions field).
280
- pv := sv.Addr()
281
- if pv.Type().Implements(extendableProtoType) {
282
- if err := writeExtensions(w, pv); err != nil {
283
- return err
284
- }
285
- }
286
-
287
- return nil
288
-}
289
-
290
-// writeRaw writes an uninterpreted raw message.
291
-func writeRaw(w *textWriter, b []byte) error {
292
- if err := w.WriteByte('<'); err != nil {
293
- return err
294
- }
295
- if !w.compact {
296
- if err := w.WriteByte('\n'); err != nil {
297
- return err
298
- }
299
- }
300
- w.indent()
301
- if err := writeUnknownStruct(w, b); err != nil {
302
- return err
303
- }
304
- w.unindent()
305
- if err := w.WriteByte('>'); err != nil {
306
- return err
307
- }
308
- return nil
309
-}
310
-
311
-// writeAny writes an arbitrary field.
312
-func writeAny(w *textWriter, v reflect.Value, props *Properties) error {
313
- v = reflect.Indirect(v)
314
-
315
- // Floats have special cases.
316
- if v.Kind() == reflect.Float32 || v.Kind() == reflect.Float64 {
317
- x := v.Float()
318
- var b []byte
319
- switch {
320
- case math.IsInf(x, 1):
321
- b = posInf
322
- case math.IsInf(x, -1):
323
- b = negInf
324
- case math.IsNaN(x):
325
- b = nan
326
- }
327
- if b != nil {
328
- _, err := w.Write(b)
329
- return err
330
- }
331
- // Other values are handled below.
332
- }
333
-
334
- // We don't attempt to serialise every possible value type; only those
335
- // that can occur in protocol buffers.
336
- switch v.Kind() {
337
- case reflect.Slice:
338
- // Should only be a []byte; repeated fields are handled in writeStruct.
339
- if err := writeString(w, string(v.Interface().([]byte))); err != nil {
340
- return err
341
- }
342
- case reflect.String:
343
- if err := writeString(w, v.String()); err != nil {
344
- return err
345
- }
346
- case reflect.Struct:
347
- // Required/optional group/message.
348
- var bra, ket byte = '<', '>'
349
- if props != nil && props.Wire == "group" {
350
- bra, ket = '{', '}'
351
- }
352
- if err := w.WriteByte(bra); err != nil {
353
- return err
354
- }
355
- if !w.compact {
356
- if err := w.WriteByte('\n'); err != nil {
357
- return err
358
- }
359
- }
360
- w.indent()
361
- if tm, ok := v.Interface().(textMarshaler); ok {
362
- text, err := tm.MarshalText()
363
- if err != nil {
364
- return err
365
- }
366
- if _, err = w.Write(text); err != nil {
367
- return err
368
- }
369
- } else if err := writeStruct(w, v); err != nil {
370
- return err
371
- }
372
- w.unindent()
373
- if err := w.WriteByte(ket); err != nil {
374
- return err
375
- }
376
- default:
377
- _, err := fmt.Fprint(w, v.Interface())
378
- return err
379
- }
380
- return nil
381
-}
382
-
383
-// equivalent to C's isprint.
384
-func isprint(c byte) bool {
385
- return c >= 0x20 && c < 0x7f
386
-}
387
-
388
-// writeString writes a string in the protocol buffer text format.
389
-// It is similar to strconv.Quote except we don't use Go escape sequences,
390
-// we treat the string as a byte sequence, and we use octal escapes.
391
-// These differences are to maintain interoperability with the other
392
-// languages' implementations of the text format.
393
-func writeString(w *textWriter, s string) error {
394
- // use WriteByte here to get any needed indent
395
- if err := w.WriteByte('"'); err != nil {
396
- return err
397
- }
398
- // Loop over the bytes, not the runes.
399
- for i := 0; i < len(s); i++ {
400
- var err error
401
- // Divergence from C++: we don't escape apostrophes.
402
- // There's no need to escape them, and the C++ parser
403
- // copes with a naked apostrophe.
404
- switch c := s[i]; c {
405
- case '\n':
406
- _, err = w.w.Write(backslashN)
407
- case '\r':
408
- _, err = w.w.Write(backslashR)
409
- case '\t':
410
- _, err = w.w.Write(backslashT)
411
- case '"':
412
- _, err = w.w.Write(backslashDQ)
413
- case '\\':
414
- _, err = w.w.Write(backslashBS)
415
- default:
416
- if isprint(c) {
417
- err = w.w.WriteByte(c)
418
- } else {
419
- _, err = fmt.Fprintf(w.w, "\\%03o", c)
420
- }
421
- }
422
- if err != nil {
423
- return err
424
- }
425
- }
426
- return w.WriteByte('"')
427
-}
428
-
429
-func writeMessageSet(w *textWriter, ms *MessageSet) error {
430
- for _, item := range ms.Item {
431
- id := *item.TypeId
432
- if msd, ok := messageSetMap[id]; ok {
433
- // Known message set type.
434
- if _, err := fmt.Fprintf(w, "[%s]: <\n", msd.name); err != nil {
435
- return err
436
- }
437
- w.indent()
438
-
439
- pb := reflect.New(msd.t.Elem())
440
- if err := Unmarshal(item.Message, pb.Interface().(Message)); err != nil {
441
- if _, err := fmt.Fprintf(w, "/* bad message: %v */\n", err); err != nil {
442
- return err
443
- }
444
- } else {
445
- if err := writeStruct(w, pb.Elem()); err != nil {
446
- return err
447
- }
448
- }
449
- } else {
450
- // Unknown type.
451
- if _, err := fmt.Fprintf(w, "[%d]: <\n", id); err != nil {
452
- return err
453
- }
454
- w.indent()
455
- if err := writeUnknownStruct(w, item.Message); err != nil {
456
- return err
457
- }
458
- }
459
- w.unindent()
460
- if _, err := w.Write(gtNewline); err != nil {
461
- return err
462
- }
463
- }
464
- return nil
465
-}
466
-
467
-func writeUnknownStruct(w *textWriter, data []byte) (err error) {
468
- if !w.compact {
469
- if _, err := fmt.Fprintf(w, "/* %d unknown bytes */\n", len(data)); err != nil {
470
- return err
471
- }
472
- }
473
- b := NewBuffer(data)
474
- for b.index < len(b.buf) {
475
- x, err := b.DecodeVarint()
476
- if err != nil {
477
- _, err := fmt.Fprintf(w, "/* %v */\n", err)
478
- return err
479
- }
480
- wire, tag := x&7, x>>3
481
- if wire == WireEndGroup {
482
- w.unindent()
483
- if _, err := w.Write(endBraceNewline); err != nil {
484
- return err
485
- }
486
- continue
487
- }
488
- if _, err := fmt.Fprint(w, tag); err != nil {
489
- return err
490
- }
491
- if wire != WireStartGroup {
492
- if err := w.WriteByte(':'); err != nil {
493
- return err
494
- }
495
- }
496
- if !w.compact || wire == WireStartGroup {
497
- if err := w.WriteByte(' '); err != nil {
498
- return err
499
- }
500
- }
501
- switch wire {
502
- case WireBytes:
503
- buf, e := b.DecodeRawBytes(false)
504
- if e == nil {
505
- _, err = fmt.Fprintf(w, "%q", buf)
506
- } else {
507
- _, err = fmt.Fprintf(w, "/* %v */", e)
508
- }
509
- case WireFixed32:
510
- x, err = b.DecodeFixed32()
511
- err = writeUnknownInt(w, x, err)
512
- case WireFixed64:
513
- x, err = b.DecodeFixed64()
514
- err = writeUnknownInt(w, x, err)
515
- case WireStartGroup:
516
- err = w.WriteByte('{')
517
- w.indent()
518
- case WireVarint:
519
- x, err = b.DecodeVarint()
520
- err = writeUnknownInt(w, x, err)
521
- default:
522
- _, err = fmt.Fprintf(w, "/* unknown wire type %d */", wire)
523
- }
524
- if err != nil {
525
- return err
526
- }
527
- if err = w.WriteByte('\n'); err != nil {
528
- return err
529
- }
530
- }
531
- return nil
532
-}
533
-
534
-func writeUnknownInt(w *textWriter, x uint64, err error) error {
535
- if err == nil {
536
- _, err = fmt.Fprint(w, x)
537
- } else {
538
- _, err = fmt.Fprintf(w, "/* %v */", err)
539
- }
540
- return err
541
-}
542
-
543
-type int32Slice []int32
544
-
545
-func (s int32Slice) Len() int { return len(s) }
546
-func (s int32Slice) Less(i, j int) bool { return s[i] < s[j] }
547
-func (s int32Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
548
-
549
-// writeExtensions writes all the extensions in pv.
550
-// pv is assumed to be a pointer to a protocol message struct that is extendable.
551
-func writeExtensions(w *textWriter, pv reflect.Value) error {
552
- emap := extensionMaps[pv.Type().Elem()]
553
- ep := pv.Interface().(extendableProto)
554
-
555
- // Order the extensions by ID.
556
- // This isn't strictly necessary, but it will give us
557
- // canonical output, which will also make testing easier.
558
- m := ep.ExtensionMap()
559
- ids := make([]int32, 0, len(m))
560
- for id := range m {
561
- ids = append(ids, id)
562
- }
563
- sort.Sort(int32Slice(ids))
564
-
565
- for _, extNum := range ids {
566
- ext := m[extNum]
567
- var desc *ExtensionDesc
568
- if emap != nil {
569
- desc = emap[extNum]
570
- }
571
- if desc == nil {
572
- // Unknown extension.
573
- if err := writeUnknownStruct(w, ext.enc); err != nil {
574
- return err
575
- }
576
- continue
577
- }
578
-
579
- pb, err := GetExtension(ep, desc)
580
- if err != nil {
581
- if _, err := fmt.Fprintln(os.Stderr, "proto: failed getting extension: ", err); err != nil {
582
- return err
583
- }
584
- continue
585
- }
586
-
587
- // Repeated extensions will appear as a slice.
588
- if !desc.repeated() {
589
- if err := writeExtension(w, desc.Name, pb); err != nil {
590
- return err
591
- }
592
- } else {
593
- v := reflect.ValueOf(pb)
594
- for i := 0; i < v.Len(); i++ {
595
- if err := writeExtension(w, desc.Name, v.Index(i).Interface()); err != nil {
596
- return err
597
- }
598
- }
599
- }
600
- }
601
- return nil
602
-}
603
-
604
-func writeExtension(w *textWriter, name string, pb interface{}) error {
605
- if _, err := fmt.Fprintf(w, "[%s]:", name); err != nil {
606
- return err
607
- }
608
- if !w.compact {
609
- if err := w.WriteByte(' '); err != nil {
610
- return err
611
- }
612
- }
613
- if err := writeAny(w, reflect.ValueOf(pb), nil); err != nil {
614
- return err
615
- }
616
- if err := w.WriteByte('\n'); err != nil {
617
- return err
618
- }
619
- return nil
620
-}
621
-
622
-func (w *textWriter) writeIndent() {
623
- if !w.complete {
624
- return
625
- }
626
- remain := w.ind * 2
627
- for remain > 0 {
628
- n := remain
629
- if n > len(spaces) {
630
- n = len(spaces)
631
- }
632
- w.w.Write(spaces[:n])
633
- remain -= n
634
- }
635
- w.complete = false
636
-}
637
-
638
-func marshalText(w io.Writer, pb Message, compact bool) error {
639
- val := reflect.ValueOf(pb)
640
- if pb == nil || val.IsNil() {
641
- w.Write([]byte("<nil>"))
642
- return nil
643
- }
644
- var bw *bufio.Writer
645
- ww, ok := w.(writer)
646
- if !ok {
647
- bw = bufio.NewWriter(w)
648
- ww = bw
649
- }
650
- aw := &textWriter{
651
- w: ww,
652
- complete: true,
653
- compact: compact,
654
- }
655
-
656
- if tm, ok := pb.(textMarshaler); ok {
657
- text, err := tm.MarshalText()
658
- if err != nil {
659
- return err
660
- }
661
- if _, err = aw.Write(text); err != nil {
662
- return err
663
- }
664
- if bw != nil {
665
- return bw.Flush()
666
- }
667
- return nil
668
- }
669
- // Dereference the received pointer so we don't have outer < and >.
670
- v := reflect.Indirect(val)
671
- if err := writeStruct(aw, v); err != nil {
672
- return err
673
- }
674
- if bw != nil {
675
- return bw.Flush()
676
- }
677
- return nil
678
-}
679
-
680
-// MarshalText writes a given protocol buffer in text format.
681
-// The only errors returned are from w.
682
-func MarshalText(w io.Writer, pb Message) error {
683
- return marshalText(w, pb, false)
684
-}
685
-
686
-// MarshalTextString is the same as MarshalText, but returns the string directly.
687
-func MarshalTextString(pb Message) string {
688
- var buf bytes.Buffer
689
- marshalText(&buf, pb, false)
690
- return buf.String()
691
-}
692
-
693
-// CompactText writes a given protocol buffer in compact text format (one line).
694
-func CompactText(w io.Writer, pb Message) error { return marshalText(w, pb, true) }
695
-
696
-// CompactTextString is the same as CompactText, but returns the string directly.
697
-func CompactTextString(pb Message) string {
698
- var buf bytes.Buffer
699
- marshalText(&buf, pb, true)
700
- return buf.String()
701
-}
Godeps/_workspace/src/code.google.com/p/goprotobuf/proto/text_parser.go
deleted
-684
@@ -1,684 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto
33
-
34
-// Functions for parsing the Text protocol buffer format.
35
-// TODO: message sets.
36
-
37
-import (
38
- "errors"
39
- "fmt"
40
- "reflect"
41
- "strconv"
42
- "strings"
43
- "unicode/utf8"
44
-)
45
-
46
-// textUnmarshaler is implemented by Messages that can unmarshal themsleves.
47
-// It is identical to encoding.TextUnmarshaler, introduced in go 1.2,
48
-// which will eventually replace it.
49
-type textUnmarshaler interface {
50
- UnmarshalText(text []byte) error
51
-}
52
-
53
-type ParseError struct {
54
- Message string
55
- Line int // 1-based line number
56
- Offset int // 0-based byte offset from start of input
57
-}
58
-
59
-func (p *ParseError) Error() string {
60
- if p.Line == 1 {
61
- // show offset only for first line
62
- return fmt.Sprintf("line 1.%d: %v", p.Offset, p.Message)
63
- }
64
- return fmt.Sprintf("line %d: %v", p.Line, p.Message)
65
-}
66
-
67
-type token struct {
68
- value string
69
- err *ParseError
70
- line int // line number
71
- offset int // byte number from start of input, not start of line
72
- unquoted string // the unquoted version of value, if it was a quoted string
73
-}
74
-
75
-func (t *token) String() string {
76
- if t.err == nil {
77
- return fmt.Sprintf("%q (line=%d, offset=%d)", t.value, t.line, t.offset)
78
- }
79
- return fmt.Sprintf("parse error: %v", t.err)
80
-}
81
-
82
-type textParser struct {
83
- s string // remaining input
84
- done bool // whether the parsing is finished (success or error)
85
- backed bool // whether back() was called
86
- offset, line int
87
- cur token
88
-}
89
-
90
-func newTextParser(s string) *textParser {
91
- p := new(textParser)
92
- p.s = s
93
- p.line = 1
94
- p.cur.line = 1
95
- return p
96
-}
97
-
98
-func (p *textParser) errorf(format string, a ...interface{}) *ParseError {
99
- pe := &ParseError{fmt.Sprintf(format, a...), p.cur.line, p.cur.offset}
100
- p.cur.err = pe
101
- p.done = true
102
- return pe
103
-}
104
-
105
-// Numbers and identifiers are matched by [-+._A-Za-z0-9]
106
-func isIdentOrNumberChar(c byte) bool {
107
- switch {
108
- case 'A' <= c && c <= 'Z', 'a' <= c && c <= 'z':
109
- return true
110
- case '0' <= c && c <= '9':
111
- return true
112
- }
113
- switch c {
114
- case '-', '+', '.', '_':
115
- return true
116
- }
117
- return false
118
-}
119
-
120
-func isWhitespace(c byte) bool {
121
- switch c {
122
- case ' ', '\t', '\n', '\r':
123
- return true
124
- }
125
- return false
126
-}
127
-
128
-func (p *textParser) skipWhitespace() {
129
- i := 0
130
- for i < len(p.s) && (isWhitespace(p.s[i]) || p.s[i] == '#') {
131
- if p.s[i] == '#' {
132
- // comment; skip to end of line or input
133
- for i < len(p.s) && p.s[i] != '\n' {
134
- i++
135
- }
136
- if i == len(p.s) {
137
- break
138
- }
139
- }
140
- if p.s[i] == '\n' {
141
- p.line++
142
- }
143
- i++
144
- }
145
- p.offset += i
146
- p.s = p.s[i:len(p.s)]
147
- if len(p.s) == 0 {
148
- p.done = true
149
- }
150
-}
151
-
152
-func (p *textParser) advance() {
153
- // Skip whitespace
154
- p.skipWhitespace()
155
- if p.done {
156
- return
157
- }
158
-
159
- // Start of non-whitespace
160
- p.cur.err = nil
161
- p.cur.offset, p.cur.line = p.offset, p.line
162
- p.cur.unquoted = ""
163
- switch p.s[0] {
164
- case '<', '>', '{', '}', ':', '[', ']', ';', ',':
165
- // Single symbol
166
- p.cur.value, p.s = p.s[0:1], p.s[1:len(p.s)]
167
- case '"', '\'':
168
- // Quoted string
169
- i := 1
170
- for i < len(p.s) && p.s[i] != p.s[0] && p.s[i] != '\n' {
171
- if p.s[i] == '\\' && i+1 < len(p.s) {
172
- // skip escaped char
173
- i++
174
- }
175
- i++
176
- }
177
- if i >= len(p.s) || p.s[i] != p.s[0] {
178
- p.errorf("unmatched quote")
179
- return
180
- }
181
- unq, err := unquoteC(p.s[1:i], rune(p.s[0]))
182
- if err != nil {
183
- p.errorf("invalid quoted string %v", p.s[0:i+1])
184
- return
185
- }
186
- p.cur.value, p.s = p.s[0:i+1], p.s[i+1:len(p.s)]
187
- p.cur.unquoted = unq
188
- default:
189
- i := 0
190
- for i < len(p.s) && isIdentOrNumberChar(p.s[i]) {
191
- i++
192
- }
193
- if i == 0 {
194
- p.errorf("unexpected byte %#x", p.s[0])
195
- return
196
- }
197
- p.cur.value, p.s = p.s[0:i], p.s[i:len(p.s)]
198
- }
199
- p.offset += len(p.cur.value)
200
-}
201
-
202
-var (
203
- errBadUTF8 = errors.New("proto: bad UTF-8")
204
- errBadHex = errors.New("proto: bad hexadecimal")
205
-)
206
-
207
-func unquoteC(s string, quote rune) (string, error) {
208
- // This is based on C++'s tokenizer.cc.
209
- // Despite its name, this is *not* parsing C syntax.
210
- // For instance, "\0" is an invalid quoted string.
211
-
212
- // Avoid allocation in trivial cases.
213
- simple := true
214
- for _, r := range s {
215
- if r == '\\' || r == quote {
216
- simple = false
217
- break
218
- }
219
- }
220
- if simple {
221
- return s, nil
222
- }
223
-
224
- buf := make([]byte, 0, 3*len(s)/2)
225
- for len(s) > 0 {
226
- r, n := utf8.DecodeRuneInString(s)
227
- if r == utf8.RuneError && n == 1 {
228
- return "", errBadUTF8
229
- }
230
- s = s[n:]
231
- if r != '\\' {
232
- if r < utf8.RuneSelf {
233
- buf = append(buf, byte(r))
234
- } else {
235
- buf = append(buf, string(r)...)
236
- }
237
- continue
238
- }
239
-
240
- ch, tail, err := unescape(s)
241
- if err != nil {
242
- return "", err
243
- }
244
- buf = append(buf, ch...)
245
- s = tail
246
- }
247
- return string(buf), nil
248
-}
249
-
250
-func unescape(s string) (ch string, tail string, err error) {
251
- r, n := utf8.DecodeRuneInString(s)
252
- if r == utf8.RuneError && n == 1 {
253
- return "", "", errBadUTF8
254
- }
255
- s = s[n:]
256
- switch r {
257
- case 'a':
258
- return "\a", s, nil
259
- case 'b':
260
- return "\b", s, nil
261
- case 'f':
262
- return "\f", s, nil
263
- case 'n':
264
- return "\n", s, nil
265
- case 'r':
266
- return "\r", s, nil
267
- case 't':
268
- return "\t", s, nil
269
- case 'v':
270
- return "\v", s, nil
271
- case '?':
272
- return "?", s, nil // trigraph workaround
273
- case '\'', '"', '\\':
274
- return string(r), s, nil
275
- case '0', '1', '2', '3', '4', '5', '6', '7', 'x', 'X':
276
- if len(s) < 2 {
277
- return "", "", fmt.Errorf(`\%c requires 2 following digits`, r)
278
- }
279
- base := 8
280
- ss := s[:2]
281
- s = s[2:]
282
- if r == 'x' || r == 'X' {
283
- base = 16
284
- } else {
285
- ss = string(r) + ss
286
- }
287
- i, err := strconv.ParseUint(ss, base, 8)
288
- if err != nil {
289
- return "", "", err
290
- }
291
- return string([]byte{byte(i)}), s, nil
292
- case 'u', 'U':
293
- n := 4
294
- if r == 'U' {
295
- n = 8
296
- }
297
- if len(s) < n {
298
- return "", "", fmt.Errorf(`\%c requires %d digits`, r, n)
299
- }
300
-
301
- bs := make([]byte, n/2)
302
- for i := 0; i < n; i += 2 {
303
- a, ok1 := unhex(s[i])
304
- b, ok2 := unhex(s[i+1])
305
- if !ok1 || !ok2 {
306
- return "", "", errBadHex
307
- }
308
- bs[i/2] = a<<4 | b
309
- }
310
- s = s[n:]
311
- return string(bs), s, nil
312
- }
313
- return "", "", fmt.Errorf(`unknown escape \%c`, r)
314
-}
315
-
316
-// Adapted from src/pkg/strconv/quote.go.
317
-func unhex(b byte) (v byte, ok bool) {
318
- switch {
319
- case '0' <= b && b <= '9':
320
- return b - '0', true
321
- case 'a' <= b && b <= 'f':
322
- return b - 'a' + 10, true
323
- case 'A' <= b && b <= 'F':
324
- return b - 'A' + 10, true
325
- }
326
- return 0, false
327
-}
328
-
329
-// Back off the parser by one token. Can only be done between calls to next().
330
-// It makes the next advance() a no-op.
331
-func (p *textParser) back() { p.backed = true }
332
-
333
-// Advances the parser and returns the new current token.
334
-func (p *textParser) next() *token {
335
- if p.backed || p.done {
336
- p.backed = false
337
- return &p.cur
338
- }
339
- p.advance()
340
- if p.done {
341
- p.cur.value = ""
342
- } else if len(p.cur.value) > 0 && p.cur.value[0] == '"' {
343
- // Look for multiple quoted strings separated by whitespace,
344
- // and concatenate them.
345
- cat := p.cur
346
- for {
347
- p.skipWhitespace()
348
- if p.done || p.s[0] != '"' {
349
- break
350
- }
351
- p.advance()
352
- if p.cur.err != nil {
353
- return &p.cur
354
- }
355
- cat.value += " " + p.cur.value
356
- cat.unquoted += p.cur.unquoted
357
- }
358
- p.done = false // parser may have seen EOF, but we want to return cat
359
- p.cur = cat
360
- }
361
- return &p.cur
362
-}
363
-
364
-// Return an error indicating which required field was not set.
365
-func (p *textParser) missingRequiredFieldError(sv reflect.Value) *ParseError {
366
- st := sv.Type()
367
- sprops := GetProperties(st)
368
- for i := 0; i < st.NumField(); i++ {
369
- if !isNil(sv.Field(i)) {
370
- continue
371
- }
372
-
373
- props := sprops.Prop[i]
374
- if props.Required {
375
- return p.errorf("message %v missing required field %q", st, props.OrigName)
376
- }
377
- }
378
- return p.errorf("message %v missing required field", st) // should not happen
379
-}
380
-
381
-// Returns the index in the struct for the named field, as well as the parsed tag properties.
382
-func structFieldByName(st reflect.Type, name string) (int, *Properties, bool) {
383
- sprops := GetProperties(st)
384
- i, ok := sprops.decoderOrigNames[name]
385
- if ok {
386
- return i, sprops.Prop[i], true
387
- }
388
- return -1, nil, false
389
-}
390
-
391
-// Consume a ':' from the input stream (if the next token is a colon),
392
-// returning an error if a colon is needed but not present.
393
-func (p *textParser) checkForColon(props *Properties, typ reflect.Type) *ParseError {
394
- tok := p.next()
395
- if tok.err != nil {
396
- return tok.err
397
- }
398
- if tok.value != ":" {
399
- // Colon is optional when the field is a group or message.
400
- needColon := true
401
- switch props.Wire {
402
- case "group":
403
- needColon = false
404
- case "bytes":
405
- // A "bytes" field is either a message, a string, or a repeated field;
406
- // those three become *T, *string and []T respectively, so we can check for
407
- // this field being a pointer to a non-string.
408
- if typ.Kind() == reflect.Ptr {
409
- // *T or *string
410
- if typ.Elem().Kind() == reflect.String {
411
- break
412
- }
413
- } else if typ.Kind() == reflect.Slice {
414
- // []T or []*T
415
- if typ.Elem().Kind() != reflect.Ptr {
416
- break
417
- }
418
- }
419
- needColon = false
420
- }
421
- if needColon {
422
- return p.errorf("expected ':', found %q", tok.value)
423
- }
424
- p.back()
425
- }
426
- return nil
427
-}
428
-
429
-func (p *textParser) readStruct(sv reflect.Value, terminator string) *ParseError {
430
- st := sv.Type()
431
- reqCount := GetProperties(st).reqCount
432
- // A struct is a sequence of "name: value", terminated by one of
433
- // '>' or '}', or the end of the input. A name may also be
434
- // "[extension]".
435
- for {
436
- tok := p.next()
437
- if tok.err != nil {
438
- return tok.err
439
- }
440
- if tok.value == terminator {
441
- break
442
- }
443
- if tok.value == "[" {
444
- // Looks like an extension.
445
- //
446
- // TODO: Check whether we need to handle
447
- // namespace rooted names (e.g. ".something.Foo").
448
- tok = p.next()
449
- if tok.err != nil {
450
- return tok.err
451
- }
452
- var desc *ExtensionDesc
453
- // This could be faster, but it's functional.
454
- // TODO: Do something smarter than a linear scan.
455
- for _, d := range RegisteredExtensions(reflect.New(st).Interface().(Message)) {
456
- if d.Name == tok.value {
457
- desc = d
458
- break
459
- }
460
- }
461
- if desc == nil {
462
- return p.errorf("unrecognized extension %q", tok.value)
463
- }
464
- // Check the extension terminator.
465
- tok = p.next()
466
- if tok.err != nil {
467
- return tok.err
468
- }
469
- if tok.value != "]" {
470
- return p.errorf("unrecognized extension terminator %q", tok.value)
471
- }
472
-
473
- props := &Properties{}
474
- props.Parse(desc.Tag)
475
-
476
- typ := reflect.TypeOf(desc.ExtensionType)
477
- if err := p.checkForColon(props, typ); err != nil {
478
- return err
479
- }
480
-
481
- rep := desc.repeated()
482
-
483
- // Read the extension structure, and set it in
484
- // the value we're constructing.
485
- var ext reflect.Value
486
- if !rep {
487
- ext = reflect.New(typ).Elem()
488
- } else {
489
- ext = reflect.New(typ.Elem()).Elem()
490
- }
491
- if err := p.readAny(ext, props); err != nil {
492
- return err
493
- }
494
- ep := sv.Addr().Interface().(extendableProto)
495
- if !rep {
496
- SetExtension(ep, desc, ext.Interface())
497
- } else {
498
- old, err := GetExtension(ep, desc)
499
- var sl reflect.Value
500
- if err == nil {
501
- sl = reflect.ValueOf(old) // existing slice
502
- } else {
503
- sl = reflect.MakeSlice(typ, 0, 1)
504
- }
505
- sl = reflect.Append(sl, ext)
506
- SetExtension(ep, desc, sl.Interface())
507
- }
508
- } else {
509
- // This is a normal, non-extension field.
510
- fi, props, ok := structFieldByName(st, tok.value)
511
- if !ok {
512
- return p.errorf("unknown field name %q in %v", tok.value, st)
513
- }
514
-
515
- dst := sv.Field(fi)
516
- isDstNil := isNil(dst)
517
-
518
- // Check that it's not already set if it's not a repeated field.
519
- if !props.Repeated && !isDstNil {
520
- return p.errorf("non-repeated field %q was repeated", tok.value)
521
- }
522
-
523
- if err := p.checkForColon(props, st.Field(fi).Type); err != nil {
524
- return err
525
- }
526
-
527
- // Parse into the field.
528
- if err := p.readAny(dst, props); err != nil {
529
- return err
530
- }
531
-
532
- if props.Required {
533
- reqCount--
534
- }
535
- }
536
-
537
- // For backward compatibility, permit a semicolon or comma after a field.
538
- tok = p.next()
539
- if tok.err != nil {
540
- return tok.err
541
- }
542
- if tok.value != ";" && tok.value != "," {
543
- p.back()
544
- }
545
- }
546
-
547
- if reqCount > 0 {
548
- return p.missingRequiredFieldError(sv)
549
- }
550
- return nil
551
-}
552
-
553
-func (p *textParser) readAny(v reflect.Value, props *Properties) *ParseError {
554
- tok := p.next()
555
- if tok.err != nil {
556
- return tok.err
557
- }
558
- if tok.value == "" {
559
- return p.errorf("unexpected EOF")
560
- }
561
-
562
- switch fv := v; fv.Kind() {
563
- case reflect.Slice:
564
- at := v.Type()
565
- if at.Elem().Kind() == reflect.Uint8 {
566
- // Special case for []byte
567
- if tok.value[0] != '"' && tok.value[0] != '\'' {
568
- // Deliberately written out here, as the error after
569
- // this switch statement would write "invalid []byte: ...",
570
- // which is not as user-friendly.
571
- return p.errorf("invalid string: %v", tok.value)
572
- }
573
- bytes := []byte(tok.unquoted)
574
- fv.Set(reflect.ValueOf(bytes))
575
- return nil
576
- }
577
- // Repeated field. May already exist.
578
- flen := fv.Len()
579
- if flen == fv.Cap() {
580
- nav := reflect.MakeSlice(at, flen, 2*flen+1)
581
- reflect.Copy(nav, fv)
582
- fv.Set(nav)
583
- }
584
- fv.SetLen(flen + 1)
585
-
586
- // Read one.
587
- p.back()
588
- return p.readAny(fv.Index(flen), props)
589
- case reflect.Bool:
590
- // Either "true", "false", 1 or 0.
591
- switch tok.value {
592
- case "true", "1":
593
- fv.SetBool(true)
594
- return nil
595
- case "false", "0":
596
- fv.SetBool(false)
597
- return nil
598
- }
599
- case reflect.Float32, reflect.Float64:
600
- v := tok.value
601
- // Ignore 'f' for compatibility with output generated by C++, but don't
602
- // remove 'f' when the value is "-inf" or "inf".
603
- if strings.HasSuffix(v, "f") && tok.value != "-inf" && tok.value != "inf" {
604
- v = v[:len(v)-1]
605
- }
606
- if f, err := strconv.ParseFloat(v, fv.Type().Bits()); err == nil {
607
- fv.SetFloat(f)
608
- return nil
609
- }
610
- case reflect.Int32:
611
- if x, err := strconv.ParseInt(tok.value, 0, 32); err == nil {
612
- fv.SetInt(x)
613
- return nil
614
- }
615
-
616
- if len(props.Enum) == 0 {
617
- break
618
- }
619
- m, ok := enumValueMaps[props.Enum]
620
- if !ok {
621
- break
622
- }
623
- x, ok := m[tok.value]
624
- if !ok {
625
- break
626
- }
627
- fv.SetInt(int64(x))
628
- return nil
629
- case reflect.Int64:
630
- if x, err := strconv.ParseInt(tok.value, 0, 64); err == nil {
631
- fv.SetInt(x)
632
- return nil
633
- }
634
-
635
- case reflect.Ptr:
636
- // A basic field (indirected through pointer), or a repeated message/group
637
- p.back()
638
- fv.Set(reflect.New(fv.Type().Elem()))
639
- return p.readAny(fv.Elem(), props)
640
- case reflect.String:
641
- if tok.value[0] == '"' || tok.value[0] == '\'' {
642
- fv.SetString(tok.unquoted)
643
- return nil
644
- }
645
- case reflect.Struct:
646
- var terminator string
647
- switch tok.value {
648
- case "{":
649
- terminator = "}"
650
- case "<":
651
- terminator = ">"
652
- default:
653
- return p.errorf("expected '{' or '<', found %q", tok.value)
654
- }
655
- // TODO: Handle nested messages which implement textUnmarshaler.
656
- return p.readStruct(fv, terminator)
657
- case reflect.Uint32:
658
- if x, err := strconv.ParseUint(tok.value, 0, 32); err == nil {
659
- fv.SetUint(uint64(x))
660
- return nil
661
- }
662
- case reflect.Uint64:
663
- if x, err := strconv.ParseUint(tok.value, 0, 64); err == nil {
664
- fv.SetUint(x)
665
- return nil
666
- }
667
- }
668
- return p.errorf("invalid %v: %v", v.Type(), tok.value)
669
-}
670
-
671
-// UnmarshalText reads a protocol buffer in Text format. UnmarshalText resets pb
672
-// before starting to unmarshal, so any existing data in pb is always removed.
673
-func UnmarshalText(s string, pb Message) error {
674
- if um, ok := pb.(textUnmarshaler); ok {
675
- err := um.UnmarshalText([]byte(s))
676
- return err
677
- }
678
- pb.Reset()
679
- v := reflect.ValueOf(pb)
680
- if pe := newTextParser(s).readStruct(v.Elem(), ""); pe != nil {
681
- return pe
682
- }
683
- return nil
684
-}
Godeps/_workspace/src/code.google.com/p/goprotobuf/proto/text_test.go
deleted
-408
@@ -1,408 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
5
-//
6
-// Redistribution and use in source and binary forms, with or without
7
-// modification, are permitted provided that the following conditions are
8
-// met:
9
-//
10
-// * Redistributions of source code must retain the above copyright
11
-// notice, this list of conditions and the following disclaimer.
12
-// * Redistributions in binary form must reproduce the above
13
-// copyright notice, this list of conditions and the following disclaimer
14
-// in the documentation and/or other materials provided with the
15
-// distribution.
16
-// * Neither the name of Google Inc. nor the names of its
17
-// contributors may be used to endorse or promote products derived from
18
-// this software without specific prior written permission.
19
-//
20
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
32
-package proto_test
33
-
34
-import (
35
- "bytes"
36
- "errors"
37
- "io/ioutil"
38
- "math"
39
- "strings"
40
- "testing"
41
-
42
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
43
-
44
- pb "./testdata"
45
-)
46
-
47
-// textMessage implements the methods that allow it to marshal and unmarshal
48
-// itself as text.
49
-type textMessage struct {
50
-}
51
-
52
-func (*textMessage) MarshalText() ([]byte, error) {
53
- return []byte("custom"), nil
54
-}
55
-
56
-func (*textMessage) UnmarshalText(bytes []byte) error {
57
- if string(bytes) != "custom" {
58
- return errors.New("expected 'custom'")
59
- }
60
- return nil
61
-}
62
-
63
-func (*textMessage) Reset() {}
64
-func (*textMessage) String() string { return "" }
65
-func (*textMessage) ProtoMessage() {}
66
-
67
-func newTestMessage() *pb.MyMessage {
68
- msg := &pb.MyMessage{
69
- Count: proto.Int32(42),
70
- Name: proto.String("Dave"),
71
- Quote: proto.String(`"I didn't want to go."`),
72
- Pet: []string{"bunny", "kitty", "horsey"},
73
- Inner: &pb.InnerMessage{
74
- Host: proto.String("footrest.syd"),
75
- Port: proto.Int32(7001),
76
- Connected: proto.Bool(true),
77
- },
78
- Others: []*pb.OtherMessage{
79
- {
80
- Key: proto.Int64(0xdeadbeef),
81
- Value: []byte{1, 65, 7, 12},
82
- },
83
- {
84
- Weight: proto.Float32(6.022),
85
- Inner: &pb.InnerMessage{
86
- Host: proto.String("lesha.mtv"),
87
- Port: proto.Int32(8002),
88
- },
89
- },
90
- },
91
- Bikeshed: pb.MyMessage_BLUE.Enum(),
92
- Somegroup: &pb.MyMessage_SomeGroup{
93
- GroupField: proto.Int32(8),
94
- },
95
- // One normally wouldn't do this.
96
- // This is an undeclared tag 13, as a varint (wire type 0) with value 4.
97
- XXX_unrecognized: []byte{13<<3 | 0, 4},
98
- }
99
- ext := &pb.Ext{
100
- Data: proto.String("Big gobs for big rats"),
101
- }
102
- if err := proto.SetExtension(msg, pb.E_Ext_More, ext); err != nil {
103
- panic(err)
104
- }
105
- greetings := []string{"adg", "easy", "cow"}
106
- if err := proto.SetExtension(msg, pb.E_Greeting, greetings); err != nil {
107
- panic(err)
108
- }
109
-
110
- // Add an unknown extension. We marshal a pb.Ext, and fake the ID.
111
- b, err := proto.Marshal(&pb.Ext{Data: proto.String("3G skiing")})
112
- if err != nil {
113
- panic(err)
114
- }
115
- b = append(proto.EncodeVarint(201<<3|proto.WireBytes), b...)
116
- proto.SetRawExtension(msg, 201, b)
117
-
118
- // Extensions can be plain fields, too, so let's test that.
119
- b = append(proto.EncodeVarint(202<<3|proto.WireVarint), 19)
120
- proto.SetRawExtension(msg, 202, b)
121
-
122
- return msg
123
-}
124
-
125
-const text = `count: 42
126
-name: "Dave"
127
-quote: "\"I didn't want to go.\""
128
-pet: "bunny"
129
-pet: "kitty"
130
-pet: "horsey"
131
-inner: <
132
- host: "footrest.syd"
133
- port: 7001
134
- connected: true
135
->
136
-others: <
137
- key: 3735928559
138
- value: "\001A\007\014"
139
->
140
-others: <
141
- weight: 6.022
142
- inner: <
143
- host: "lesha.mtv"
144
- port: 8002
145
- >
146
->
147
-bikeshed: BLUE
148
-SomeGroup {
149
- group_field: 8
150
-}
151
-/* 2 unknown bytes */
152
-13: 4
153
-[testdata.Ext.more]: <
154
- data: "Big gobs for big rats"
155
->
156
-[testdata.greeting]: "adg"
157
-[testdata.greeting]: "easy"
158
-[testdata.greeting]: "cow"
159
-/* 13 unknown bytes */
160
-201: "\t3G skiing"
161
-/* 3 unknown bytes */
162
-202: 19
163
-`
164
-
165
-func TestMarshalText(t *testing.T) {
166
- buf := new(bytes.Buffer)
167
- if err := proto.MarshalText(buf, newTestMessage()); err != nil {
168
- t.Fatalf("proto.MarshalText: %v", err)
169
- }
170
- s := buf.String()
171
- if s != text {
172
- t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", s, text)
173
- }
174
-}
175
-
176
-func TestMarshalTextCustomMessage(t *testing.T) {
177
- buf := new(bytes.Buffer)
178
- if err := proto.MarshalText(buf, &textMessage{}); err != nil {
179
- t.Fatalf("proto.MarshalText: %v", err)
180
- }
181
- s := buf.String()
182
- if s != "custom" {
183
- t.Errorf("Got %q, expected %q", s, "custom")
184
- }
185
-}
186
-func TestMarshalTextNil(t *testing.T) {
187
- want := "<nil>"
188
- tests := []proto.Message{nil, (*pb.MyMessage)(nil)}
189
- for i, test := range tests {
190
- buf := new(bytes.Buffer)
191
- if err := proto.MarshalText(buf, test); err != nil {
192
- t.Fatal(err)
193
- }
194
- if got := buf.String(); got != want {
195
- t.Errorf("%d: got %q want %q", i, got, want)
196
- }
197
- }
198
-}
199
-
200
-func TestMarshalTextUnknownEnum(t *testing.T) {
201
- // The Color enum only specifies values 0-2.
202
- m := &pb.MyMessage{Bikeshed: pb.MyMessage_Color(3).Enum()}
203
- got := m.String()
204
- const want = `bikeshed:3 `
205
- if got != want {
206
- t.Errorf("\n got %q\nwant %q", got, want)
207
- }
208
-}
209
-
210
-func BenchmarkMarshalTextBuffered(b *testing.B) {
211
- buf := new(bytes.Buffer)
212
- m := newTestMessage()
213
- for i := 0; i < b.N; i++ {
214
- buf.Reset()
215
- proto.MarshalText(buf, m)
216
- }
217
-}
218
-
219
-func BenchmarkMarshalTextUnbuffered(b *testing.B) {
220
- w := ioutil.Discard
221
- m := newTestMessage()
222
- for i := 0; i < b.N; i++ {
223
- proto.MarshalText(w, m)
224
- }
225
-}
226
-
227
-func compact(src string) string {
228
- // s/[ \n]+/ /g; s/ $//;
229
- dst := make([]byte, len(src))
230
- space, comment := false, false
231
- j := 0
232
- for i := 0; i < len(src); i++ {
233
- if strings.HasPrefix(src[i:], "/*") {
234
- comment = true
235
- i++
236
- continue
237
- }
238
- if comment && strings.HasPrefix(src[i:], "*/") {
239
- comment = false
240
- i++
241
- continue
242
- }
243
- if comment {
244
- continue
245
- }
246
- c := src[i]
247
- if c == ' ' || c == '\n' {
248
- space = true
249
- continue
250
- }
251
- if j > 0 && (dst[j-1] == ':' || dst[j-1] == '<' || dst[j-1] == '{') {
252
- space = false
253
- }
254
- if c == '{' {
255
- space = false
256
- }
257
- if space {
258
- dst[j] = ' '
259
- j++
260
- space = false
261
- }
262
- dst[j] = c
263
- j++
264
- }
265
- if space {
266
- dst[j] = ' '
267
- j++
268
- }
269
- return string(dst[0:j])
270
-}
271
-
272
-var compactText = compact(text)
273
-
274
-func TestCompactText(t *testing.T) {
275
- s := proto.CompactTextString(newTestMessage())
276
- if s != compactText {
277
- t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v\n===\n", s, compactText)
278
- }
279
-}
280
-
281
-func TestStringEscaping(t *testing.T) {
282
- testCases := []struct {
283
- in *pb.Strings
284
- out string
285
- }{
286
- {
287
- // Test data from C++ test (TextFormatTest.StringEscape).
288
- // Single divergence: we don't escape apostrophes.
289
- &pb.Strings{StringField: proto.String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces")},
290
- "string_field: \"\\\"A string with ' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"\n",
291
- },
292
- {
293
- // Test data from the same C++ test.
294
- &pb.Strings{StringField: proto.String("\350\260\267\346\255\214")},
295
- "string_field: \"\\350\\260\\267\\346\\255\\214\"\n",
296
- },
297
- {
298
- // Some UTF-8.
299
- &pb.Strings{StringField: proto.String("\x00\x01\xff\x81")},
300
- `string_field: "\000\001\377\201"` + "\n",
301
- },
302
- }
303
-
304
- for i, tc := range testCases {
305
- var buf bytes.Buffer
306
- if err := proto.MarshalText(&buf, tc.in); err != nil {
307
- t.Errorf("proto.MarsalText: %v", err)
308
- continue
309
- }
310
- s := buf.String()
311
- if s != tc.out {
312
- t.Errorf("#%d: Got:\n%s\nExpected:\n%s\n", i, s, tc.out)
313
- continue
314
- }
315
-
316
- // Check round-trip.
317
- pb := new(pb.Strings)
318
- if err := proto.UnmarshalText(s, pb); err != nil {
319
- t.Errorf("#%d: UnmarshalText: %v", i, err)
320
- continue
321
- }
322
- if !proto.Equal(pb, tc.in) {
323
- t.Errorf("#%d: Round-trip failed:\nstart: %v\n end: %v", i, tc.in, pb)
324
- }
325
- }
326
-}
327
-
328
-// A limitedWriter accepts some output before it fails.
329
-// This is a proxy for something like a nearly-full or imminently-failing disk,
330
-// or a network connection that is about to die.
331
-type limitedWriter struct {
332
- b bytes.Buffer
333
- limit int
334
-}
335
-
336
-var outOfSpace = errors.New("proto: insufficient space")
337
-
338
-func (w *limitedWriter) Write(p []byte) (n int, err error) {
339
- var avail = w.limit - w.b.Len()
340
- if avail <= 0 {
341
- return 0, outOfSpace
342
- }
343
- if len(p) <= avail {
344
- return w.b.Write(p)
345
- }
346
- n, _ = w.b.Write(p[:avail])
347
- return n, outOfSpace
348
-}
349
-
350
-func TestMarshalTextFailing(t *testing.T) {
351
- // Try lots of different sizes to exercise more error code-paths.
352
- for lim := 0; lim < len(text); lim++ {
353
- buf := new(limitedWriter)
354
- buf.limit = lim
355
- err := proto.MarshalText(buf, newTestMessage())
356
- // We expect a certain error, but also some partial results in the buffer.
357
- if err != outOfSpace {
358
- t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", err, outOfSpace)
359
- }
360
- s := buf.b.String()
361
- x := text[:buf.limit]
362
- if s != x {
363
- t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", s, x)
364
- }
365
- }
366
-}
367
-
368
-func TestFloats(t *testing.T) {
369
- tests := []struct {
370
- f float64
371
- want string
372
- }{
373
- {0, "0"},
374
- {4.7, "4.7"},
375
- {math.Inf(1), "inf"},
376
- {math.Inf(-1), "-inf"},
377
- {math.NaN(), "nan"},
378
- }
379
- for _, test := range tests {
380
- msg := &pb.FloatingPoint{F: &test.f}
381
- got := strings.TrimSpace(msg.String())
382
- want := `f:` + test.want
383
- if got != want {
384
- t.Errorf("f=%f: got %q, want %q", test.f, got, want)
385
- }
386
- }
387
-}
388
-
389
-func TestRepeatedNilText(t *testing.T) {
390
- m := &pb.MessageList{
391
- Message: []*pb.MessageList_Message{
392
- nil,
393
- &pb.MessageList_Message{
394
- Name: proto.String("Horse"),
395
- },
396
- nil,
397
- },
398
- }
399
- want := `Message <nil>
400
-Message {
401
- name: "Horse"
402
-}
403
-Message <nil>
404
-`
405
- if s := proto.MarshalTextString(m); s != want {
406
- t.Errorf(" got: %s\nwant: %s", s, want)
407
- }
408
-}
Godeps/_workspace/src/github.com/gogo/protobuf/io/full.go
renamed
+2
-2
@@ -1,7 +1,7 @@
1
// Extensions for Protocol Buffers to create more go like structures.
2
//
3
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
4
-// http://code.google.com/p/gogoprotobuf/gogoproto
4
+// http://github.com/gogo/protobuf/gogoproto
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -29,7 +29,7 @@
29
package io
30
31
import (
32
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
32
+ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
33
"io"
34
)
35
Godeps/_workspace/src/github.com/gogo/protobuf/io/io.go
renamed
+2
-2
@@ -1,7 +1,7 @@
1
// Extensions for Protocol Buffers to create more go like structures.
2
//
3
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
4
-// http://code.google.com/p/gogoprotobuf/gogoproto
4
+// http://github.com/gogo/protobuf/gogoproto
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -29,7 +29,7 @@
29
package io
30
31
import (
32
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
32
+ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
33
"io"
34
)
35
Godeps/_workspace/src/github.com/gogo/protobuf/io/io_test.go
renamed
+103
-19
@@ -1,7 +1,7 @@
1
// Extensions for Protocol Buffers to create more go like structures.
2
//
3
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
4
-// http://code.google.com/p/gogoprotobuf/gogoproto
4
+// http://github.com/gogo/protobuf/gogoproto
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -30,28 +30,36 @@ package io_test
30
31
import (
32
"bytes"
33
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/io"
34
- "code.google.com/p/gogoprotobuf/test"
33
"encoding/binary"
34
+ "github.com/gogo/protobuf/test"
35
+ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
36
goio "io"
37
"math/rand"
38
"testing"
39
"time"
40
)
41
42
-func iotest(writer io.WriteCloser, reader io.ReadCloser) {
42
+func iotest(writer io.WriteCloser, reader io.ReadCloser) error {
43
size := 1000
44
msgs := make([]*test.NinOptNative, size)
45
r := rand.New(rand.NewSource(time.Now().UnixNano()))
46
for i := range msgs {
47
msgs[i] = test.NewPopulatedNinOptNative(r, true)
48
+ //issue 31
49
+ if i == 5 {
50
+ msgs[i] = &test.NinOptNative{}
51
+ }
52
+ //issue 31
53
+ if i == 999 {
54
+ msgs[i] = &test.NinOptNative{}
55
+ }
56
err := writer.WriteMsg(msgs[i])
57
if err != nil {
50
- panic(err)
58
+ return err
59
}
60
}
61
if err := writer.Close(); err != nil {
54
- panic(err)
62
+ return err
63
}
64
i := 0
65
for {
@@ -60,10 +68,10 @@ func iotest(writer io.WriteCloser, reader io.ReadCloser) {
68
if err == goio.EOF {
69
break
70
}
63
- panic(err)
71
+ return err
72
}
73
if err := msg.VerboseEqual(msgs[i]); err != nil {
66
- panic(err)
74
+ return err
75
}
76
i++
77
}
@@ -71,33 +79,106 @@ func iotest(writer io.WriteCloser, reader io.ReadCloser) {
79
panic("not enough messages read")
80
}
81
if err := reader.Close(); err != nil {
74
- panic(err)
82
+ return err
83
}
84
+ return nil
85
}
86
78
-func TestBigUint32(t *testing.T) {
79
- buf := bytes.NewBuffer(nil)
87
+type buffer struct {
88
+ *bytes.Buffer
89
+ closed bool
90
+}
91
+
92
+func (this *buffer) Close() error {
93
+ this.closed = true
94
+ return nil
95
+}
96
+
97
+func newBuffer() *buffer {
98
+ return &buffer{bytes.NewBuffer(nil), false}
99
+}
100
+
101
+func TestBigUint32Normal(t *testing.T) {
102
+ buf := newBuffer()
103
writer := io.NewUint32DelimitedWriter(buf, binary.BigEndian)
104
reader := io.NewUint32DelimitedReader(buf, binary.BigEndian, 1024*1024)
82
- iotest(writer, reader)
105
+ if err := iotest(writer, reader); err != nil {
106
+ t.Error(err)
107
+ }
108
+ if !buf.closed {
109
+ t.Fatalf("did not close buffer")
110
+ }
111
}
112
85
-func TestLittleUint32(t *testing.T) {
86
- buf := bytes.NewBuffer(nil)
113
+func TestBigUint32MaxSize(t *testing.T) {
114
+ buf := newBuffer()
115
+ writer := io.NewUint32DelimitedWriter(buf, binary.BigEndian)
116
+ reader := io.NewUint32DelimitedReader(buf, binary.BigEndian, 20)
117
+ if err := iotest(writer, reader); err != goio.ErrShortBuffer {
118
+ t.Error(err)
119
+ } else {
120
+ t.Logf("%s", err)
121
+ }
122
+}
123
+
124
+func TestLittleUint32Normal(t *testing.T) {
125
+ buf := newBuffer()
126
writer := io.NewUint32DelimitedWriter(buf, binary.LittleEndian)
127
reader := io.NewUint32DelimitedReader(buf, binary.LittleEndian, 1024*1024)
89
- iotest(writer, reader)
128
+ if err := iotest(writer, reader); err != nil {
129
+ t.Error(err)
130
+ }
131
+ if !buf.closed {
132
+ t.Fatalf("did not close buffer")
133
+ }
134
+}
135
+
136
+func TestLittleUint32MaxSize(t *testing.T) {
137
+ buf := newBuffer()
138
+ writer := io.NewUint32DelimitedWriter(buf, binary.LittleEndian)
139
+ reader := io.NewUint32DelimitedReader(buf, binary.LittleEndian, 20)
140
+ if err := iotest(writer, reader); err != goio.ErrShortBuffer {
141
+ t.Error(err)
142
+ } else {
143
+ t.Logf("%s", err)
144
+ }
145
+}
146
+
147
+func TestVarintNormal(t *testing.T) {
148
+ buf := newBuffer()
149
+ writer := io.NewDelimitedWriter(buf)
150
+ reader := io.NewDelimitedReader(buf, 1024*1024)
151
+ if err := iotest(writer, reader); err != nil {
152
+ t.Error(err)
153
+ }
154
+ if !buf.closed {
155
+ t.Fatalf("did not close buffer")
156
+ }
157
}
158
92
-func TestVarint(t *testing.T) {
159
+func TestVarintNoClose(t *testing.T) {
160
buf := bytes.NewBuffer(nil)
161
writer := io.NewDelimitedWriter(buf)
162
reader := io.NewDelimitedReader(buf, 1024*1024)
96
- iotest(writer, reader)
163
+ if err := iotest(writer, reader); err != nil {
164
+ t.Error(err)
165
+ }
166
+}
167
+
168
+//issue 32
169
+func TestVarintMaxSize(t *testing.T) {
170
+ buf := newBuffer()
171
+ writer := io.NewDelimitedWriter(buf)
172
+ reader := io.NewDelimitedReader(buf, 20)
173
+ if err := iotest(writer, reader); err != goio.ErrShortBuffer {
174
+ t.Error(err)
175
+ } else {
176
+ t.Logf("%s", err)
177
+ }
178
}
179
180
func TestVarintError(t *testing.T) {
100
- buf := bytes.NewBuffer(nil)
181
+ buf := newBuffer()
182
buf.Write([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f})
183
reader := io.NewDelimitedReader(buf, 1024*1024)
184
msg := &test.NinOptNative{}
@@ -108,7 +189,7 @@ func TestVarintError(t *testing.T) {
189
}
190
191
func TestFull(t *testing.T) {
111
- buf := bytes.NewBuffer(nil)
192
+ buf := newBuffer()
193
writer := io.NewFullWriter(buf)
194
reader := io.NewFullReader(buf, 1024*1024)
195
r := rand.New(rand.NewSource(time.Now().UnixNano()))
@@ -134,4 +215,7 @@ func TestFull(t *testing.T) {
215
if err := reader.Close(); err != nil {
216
panic(err)
217
}
218
+ if !buf.closed {
219
+ t.Fatalf("did not close buffer")
220
+ }
221
}
Godeps/_workspace/src/github.com/gogo/protobuf/io/uint32.go
renamed
+6
-2
@@ -1,7 +1,7 @@
1
// Extensions for Protocol Buffers to create more go like structures.
2
//
3
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
4
-// http://code.google.com/p/gogoprotobuf/gogoproto
4
+// http://github.com/gogo/protobuf/gogoproto
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -29,8 +29,8 @@
29
package io
30
31
import (
32
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
32
"encoding/binary"
33
+ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
34
"io"
35
)
36
@@ -38,6 +38,10 @@ func NewUint32DelimitedWriter(w io.Writer, byteOrder binary.ByteOrder) WriteClos
38
return &uint32Writer{w, byteOrder, nil}
39
}
40
41
+func NewSizeUint32DelimitedWriter(w io.Writer, byteOrder binary.ByteOrder, size int) WriteCloser {
42
+ return &uint32Writer{w, byteOrder, make([]byte, size)}
43
+}
44
+
45
type uint32Writer struct {
46
w io.Writer
47
byteOrder binary.ByteOrder
Godeps/_workspace/src/github.com/gogo/protobuf/io/varint.go
renamed
+21
-20
@@ -1,7 +1,7 @@
1
// Extensions for Protocol Buffers to create more go like structures.
2
//
3
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
4
-// http://code.google.com/p/gogoprotobuf/gogoproto
4
+// http://github.com/gogo/protobuf/gogoproto
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -29,9 +29,10 @@
29
package io
30
31
import (
32
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
32
+ "bufio"
33
"encoding/binary"
34
"errors"
35
+ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
36
"io"
37
)
38
@@ -86,42 +87,42 @@ func (this *varintWriter) Close() error {
87
}
88
89
func NewDelimitedReader(r io.Reader, maxSize int) ReadCloser {
89
- return &varintReader{r, make([]byte, 10), nil, maxSize}
90
+ var closer io.Closer
91
+ if c, ok := r.(io.Closer); ok {
92
+ closer = c
93
+ }
94
+ return &varintReader{bufio.NewReader(r), nil, maxSize, closer}
95
}
96
97
type varintReader struct {
93
- r io.Reader
94
- lenBuf []byte
98
+ r *bufio.Reader
99
buf []byte
100
maxSize int
101
+ closer io.Closer
102
}
103
104
func (this *varintReader) ReadMsg(msg proto.Message) error {
100
- firstLen, err := this.r.Read(this.lenBuf)
105
+ length64, err := binary.ReadUvarint(this.r)
106
if err != nil {
107
return err
108
}
104
- length64, lenLen := binary.Uvarint(this.lenBuf)
105
- if lenLen <= 0 {
106
- if lenLen == 0 {
107
- return errSmallBuffer
108
- }
109
- return errLargeValue
109
+ length := int(length64)
110
+ if length < 0 || length > this.maxSize {
111
+ return io.ErrShortBuffer
112
}
111
- msgLen := int(length64)
112
- if len(this.buf) < msgLen {
113
- this.buf = make([]byte, msgLen)
113
+ if len(this.buf) < length {
114
+ this.buf = make([]byte, length)
115
}
115
- prefixN := copy(this.buf, this.lenBuf[lenLen:firstLen])
116
- if _, err := io.ReadFull(this.r, this.buf[prefixN:msgLen]); err != nil {
116
+ buf := this.buf[:length]
117
+ if _, err := io.ReadFull(this.r, buf); err != nil {
118
return err
119
}
119
- return proto.Unmarshal(this.buf[:msgLen], msg)
120
+ return proto.Unmarshal(buf, msg)
121
}
122
123
func (this *varintReader) Close() error {
123
- if closer, ok := this.r.(io.Closer); ok {
124
- return closer.Close()
124
+ if this.closer != nil {
125
+ return this.closer.Close()
126
}
127
return nil
128
}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/Makefile
renamed
+1
-1
@@ -1,7 +1,7 @@
1
# Go support for Protocol Buffers - Google's data interchange format
2
#
3
# Copyright 2010 The Go Authors. All rights reserved.
4
-# http://code.google.com/p/goprotobuf/
4
+# https://github.com/golang/protobuf
5
#
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions are
Godeps/_workspace/src/github.com/gogo/protobuf/proto/all_test.go
renamed
+2
-2
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -45,7 +45,7 @@ import (
45
"time"
46
47
. "./testdata"
48
- . "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
48
+ . "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
49
)
50
51
var globalO *Buffer
Godeps/_workspace/src/github.com/gogo/protobuf/proto/clone.go
renamed
+9
-4
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2011 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -130,6 +130,14 @@ func mergeAny(out, in reflect.Value) {
130
if in.IsNil() {
131
return
132
}
133
+ if in.Type().Elem().Kind() == reflect.Uint8 {
134
+ // []byte is a scalar bytes field, not a repeated field.
135
+ // Make a deep copy.
136
+ // Append to []byte{} instead of []byte(nil) so that we never end up
137
+ // with a nil result.
138
+ out.SetBytes(append([]byte{}, in.Bytes()...))
139
+ return
140
+ }
141
n := in.Len()
142
if out.IsNil() {
143
out.Set(reflect.MakeSlice(in.Type(), 0, n))
@@ -138,9 +146,6 @@ func mergeAny(out, in reflect.Value) {
146
case reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int32, reflect.Int64,
147
reflect.String, reflect.Uint32, reflect.Uint64:
148
out.Set(reflect.AppendSlice(out, in))
141
- case reflect.Uint8:
142
- // []byte is a scalar bytes field.
143
- out.Set(in)
149
default:
150
for i := 0; i < n; i++ {
151
x := reflect.Indirect(reflect.New(in.Type().Elem()))
Godeps/_workspace/src/github.com/gogo/protobuf/proto/clone_test.go
renamed
+18
-3
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2011 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -34,9 +34,8 @@ package proto_test
34
import (
35
"testing"
36
37
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
38
-
37
pb "./testdata"
38
+ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
39
)
40
41
var cloneTestMessage = &pb.MyMessage{
@@ -79,6 +78,22 @@ func TestClone(t *testing.T) {
78
if proto.Equal(m, cloneTestMessage) {
79
t.Error("Mutating clone changed the original")
80
}
81
+ // Byte fields and repeated fields should be copied.
82
+ if &m.Pet[0] == &cloneTestMessage.Pet[0] {
83
+ t.Error("Pet: repeated field not copied")
84
+ }
85
+ if &m.Others[0] == &cloneTestMessage.Others[0] {
86
+ t.Error("Others: repeated field not copied")
87
+ }
88
+ if &m.Others[0].Value[0] == &cloneTestMessage.Others[0].Value[0] {
89
+ t.Error("Others[0].Value: bytes field not copied")
90
+ }
91
+ if &m.RepBytes[0] == &cloneTestMessage.RepBytes[0] {
92
+ t.Error("RepBytes: repeated field not copied")
93
+ }
94
+ if &m.RepBytes[0][0] == &cloneTestMessage.RepBytes[0][0] {
95
+ t.Error("RepBytes[0]: bytes field not copied")
96
+ }
97
}
98
99
func TestCloneNil(t *testing.T) {
Godeps/_workspace/src/github.com/gogo/protobuf/proto/decode.go
renamed
+2
-2
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -362,7 +362,7 @@ func (o *Buffer) unmarshalType(st reflect.Type, prop *StructProperties, is_group
362
}
363
tag := int(u >> 3)
364
if tag <= 0 {
365
- return fmt.Errorf("proto: %s: illegal tag %d", st, tag)
365
+ return fmt.Errorf("proto: %s: illegal tag %d (wire type %d)", st, tag, wire)
366
}
367
fieldnum, ok := prop.decoderTags.get(tag)
368
if !ok {
Godeps/_workspace/src/github.com/gogo/protobuf/proto/decode_gogo.go
renamed
+1
-1
@@ -1,5 +1,5 @@
1
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2
-// http://code.google.com/p/gogoprotobuf/gogoproto
2
+// http://github.com/gogo/protobuf/gogoproto
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
Godeps/_workspace/src/github.com/gogo/protobuf/proto/encode.go
renamed
+16
-16
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -247,7 +247,7 @@ func (p *Buffer) Marshal(pb Message) error {
247
return ErrNil
248
}
249
if err == nil {
250
- err = p.enc_struct(t.Elem(), GetProperties(t.Elem()), base)
250
+ err = p.enc_struct(GetProperties(t.Elem()), base)
251
}
252
253
if collectStats {
@@ -271,7 +271,7 @@ func Size(pb Message) (n int) {
271
return 0
272
}
273
if err == nil {
274
- n = size_struct(t.Elem(), GetProperties(t.Elem()), base)
274
+ n = size_struct(GetProperties(t.Elem()), base)
275
}
276
277
if collectStats {
@@ -429,7 +429,7 @@ func (o *Buffer) enc_struct_message(p *Properties, base structPointer) error {
429
}
430
431
o.buf = append(o.buf, p.tagcode...)
432
- return o.enc_len_struct(p.stype, p.sprop, structp, &state)
432
+ return o.enc_len_struct(p.sprop, structp, &state)
433
}
434
435
func size_struct_message(p *Properties, base structPointer) int {
@@ -448,7 +448,7 @@ func size_struct_message(p *Properties, base structPointer) int {
448
}
449
450
n0 := len(p.tagcode)
451
- n1 := size_struct(p.stype, p.sprop, structp)
451
+ n1 := size_struct(p.sprop, structp)
452
n2 := sizeVarint(uint64(n1)) // size of encoded length
453
return n0 + n1 + n2
454
}
@@ -462,7 +462,7 @@ func (o *Buffer) enc_struct_group(p *Properties, base structPointer) error {
462
}
463
464
o.EncodeVarint(uint64((p.Tag << 3) | WireStartGroup))
465
- err := o.enc_struct(p.stype, p.sprop, b)
465
+ err := o.enc_struct(p.sprop, b)
466
if err != nil && !state.shouldContinue(err, nil) {
467
return err
468
}
@@ -477,7 +477,7 @@ func size_struct_group(p *Properties, base structPointer) (n int) {
477
}
478
479
n += sizeVarint(uint64((p.Tag << 3) | WireStartGroup))
480
- n += size_struct(p.stype, p.sprop, b)
480
+ n += size_struct(p.sprop, b)
481
n += sizeVarint(uint64((p.Tag << 3) | WireEndGroup))
482
return
483
}
@@ -831,7 +831,7 @@ func (o *Buffer) enc_slice_struct_message(p *Properties, base structPointer) err
831
}
832
833
o.buf = append(o.buf, p.tagcode...)
834
- err := o.enc_len_struct(p.stype, p.sprop, structp, &state)
834
+ err := o.enc_len_struct(p.sprop, structp, &state)
835
if err != nil && !state.shouldContinue(err, nil) {
836
if err == ErrNil {
837
return ErrRepeatedHasNil
@@ -861,7 +861,7 @@ func size_slice_struct_message(p *Properties, base structPointer) (n int) {
861
continue
862
}
863
864
- n0 := size_struct(p.stype, p.sprop, structp)
864
+ n0 := size_struct(p.sprop, structp)
865
n1 := sizeVarint(uint64(n0)) // size of encoded length
866
n += n0 + n1
867
}
@@ -882,7 +882,7 @@ func (o *Buffer) enc_slice_struct_group(p *Properties, base structPointer) error
882
883
o.EncodeVarint(uint64((p.Tag << 3) | WireStartGroup))
884
885
- err := o.enc_struct(p.stype, p.sprop, b)
885
+ err := o.enc_struct(p.sprop, b)
886
887
if err != nil && !state.shouldContinue(err, nil) {
888
if err == ErrNil {
@@ -908,7 +908,7 @@ func size_slice_struct_group(p *Properties, base structPointer) (n int) {
908
return // return size up to this point
909
}
910
911
- n += size_struct(p.stype, p.sprop, b)
911
+ n += size_struct(p.sprop, b)
912
}
913
return
914
}
@@ -946,11 +946,11 @@ func size_map(p *Properties, base structPointer) int {
946
}
947
948
// Encode a struct.
949
-func (o *Buffer) enc_struct(t reflect.Type, prop *StructProperties, base structPointer) error {
949
+func (o *Buffer) enc_struct(prop *StructProperties, base structPointer) error {
950
var state errorState
951
// Encode fields in tag order so that decoders may use optimizations
952
// that depend on the ordering.
953
- // http://code.google.com/apis/protocolbuffers/docs/encoding.html#order
953
+ // https://developers.google.com/protocol-buffers/docs/encoding#order
954
for _, i := range prop.order {
955
p := prop.Prop[i]
956
if p.enc != nil {
@@ -978,7 +978,7 @@ func (o *Buffer) enc_struct(t reflect.Type, prop *StructProperties, base structP
978
return state.err
979
}
980
981
-func size_struct(t reflect.Type, prop *StructProperties, base structPointer) (n int) {
981
+func size_struct(prop *StructProperties, base structPointer) (n int) {
982
for _, i := range prop.order {
983
p := prop.Prop[i]
984
if p.size != nil {
@@ -998,11 +998,11 @@ func size_struct(t reflect.Type, prop *StructProperties, base structPointer) (n
998
var zeroes [20]byte // longer than any conceivable sizeVarint
999
1000
// Encode a struct, preceded by its encoded length (as a varint).
1001
-func (o *Buffer) enc_len_struct(t reflect.Type, prop *StructProperties, base structPointer, state *errorState) error {
1001
+func (o *Buffer) enc_len_struct(prop *StructProperties, base structPointer, state *errorState) error {
1002
iLen := len(o.buf)
1003
o.buf = append(o.buf, 0, 0, 0, 0) // reserve four bytes for length
1004
iMsg := len(o.buf)
1005
- err := o.enc_struct(t, prop, base)
1005
+ err := o.enc_struct(prop, base)
1006
if err != nil && !state.shouldContinue(err, nil) {
1007
return err
1008
}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/encode_gogo.go
renamed
+29
-7
@@ -1,12 +1,12 @@
1
// Extensions for Protocol Buffers to create more go like structures.
2
//
3
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
4
-// http://code.google.com/p/gogoprotobuf/gogoproto
4
+// http://github.com/gogo/protobuf/gogoproto
5
//
6
// Go support for Protocol Buffers - Google's data interchange format
7
//
8
// Copyright 2010 The Go Authors. All rights reserved.
9
-// http://code.google.com/p/goprotobuf/
9
+// http://github.com/golang/protobuf/
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
@@ -91,13 +91,35 @@ func (o *Buffer) enc_ref_int32(p *Properties, base structPointer) error {
91
if refWord32_IsNil(v) {
92
return ErrNil
93
}
94
- x := refWord32_Get(v)
94
+ x := int32(refWord32_Get(v))
95
o.buf = append(o.buf, p.tagcode...)
96
p.valEnc(o, uint64(x))
97
return nil
98
}
99
100
func size_ref_int32(p *Properties, base structPointer) (n int) {
101
+ v := structPointer_RefWord32(base, p.field)
102
+ if refWord32_IsNil(v) {
103
+ return 0
104
+ }
105
+ x := int32(refWord32_Get(v))
106
+ n += len(p.tagcode)
107
+ n += p.valSize(uint64(x))
108
+ return
109
+}
110
+
111
+func (o *Buffer) enc_ref_uint32(p *Properties, base structPointer) error {
112
+ v := structPointer_RefWord32(base, p.field)
113
+ if refWord32_IsNil(v) {
114
+ return ErrNil
115
+ }
116
+ x := refWord32_Get(v)
117
+ o.buf = append(o.buf, p.tagcode...)
118
+ p.valEnc(o, uint64(x))
119
+ return nil
120
+}
121
+
122
+func size_ref_uint32(p *Properties, base structPointer) (n int) {
123
v := structPointer_RefWord32(base, p.field)
124
if refWord32_IsNil(v) {
125
return 0
@@ -175,7 +197,7 @@ func (o *Buffer) enc_ref_struct_message(p *Properties, base structPointer) error
197
}
198
199
o.buf = append(o.buf, p.tagcode...)
178
- return o.enc_len_struct(p.stype, p.sprop, structp, &state)
200
+ return o.enc_len_struct(p.sprop, structp, &state)
201
}
202
203
//TODO this is only copied, please fix this
@@ -195,7 +217,7 @@ func size_ref_struct_message(p *Properties, base structPointer) int {
217
}
218
219
n0 := len(p.tagcode)
198
- n1 := size_struct(p.stype, p.sprop, structp)
220
+ n1 := size_struct(p.sprop, structp)
221
n2 := sizeVarint(uint64(n1)) // size of encoded length
222
return n0 + n1 + n2
223
}
@@ -226,7 +248,7 @@ func (o *Buffer) enc_slice_ref_struct_message(p *Properties, base structPointer)
248
}
249
250
o.buf = append(o.buf, p.tagcode...)
229
- err := o.enc_len_struct(p.stype, p.sprop, structp, &state)
251
+ err := o.enc_len_struct(p.sprop, structp, &state)
252
if err != nil && !state.shouldContinue(err, nil) {
253
if err == ErrNil {
254
return ErrRepeatedHasNil
@@ -260,7 +282,7 @@ func size_slice_ref_struct_message(p *Properties, base structPointer) (n int) {
282
continue
283
}
284
263
- n0 := size_struct(p.stype, p.sprop, structp)
285
+ n0 := size_struct(p.sprop, structp)
286
n1 := sizeVarint(uint64(n0)) // size of encoded length
287
n += n0 + n1
288
}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/equal.go
renamed
+2
-2
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2011 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -57,7 +57,7 @@ Equality is defined in this way:
57
although represented by []byte, is not a repeated field)
58
- Two unset fields are equal.
59
- Two unknown field sets are equal if their current
60
- encoded state is equal. (TODO)
60
+ encoded state is equal.
61
- Two extension sets are equal iff they have corresponding
62
elements that are pairwise equal.
63
- Every other combination of things are not equal.
Godeps/_workspace/src/github.com/gogo/protobuf/proto/equal_test.go
renamed
+2
-2
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2011 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -35,7 +35,7 @@ import (
35
"testing"
36
37
pb "./testdata"
38
- . "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
38
+ . "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
39
)
40
41
// Four identical base messages.
Godeps/_workspace/src/github.com/gogo/protobuf/proto/extensions.go
renamed
+33
-21
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -174,32 +174,39 @@ func extensionProperties(ed *ExtensionDesc) *Properties {
174
// encodeExtensionMap encodes any unmarshaled (unencoded) extensions in m.
175
func encodeExtensionMap(m map[int32]Extension) error {
176
for k, e := range m {
177
- if e.value == nil || e.desc == nil {
178
- // Extension is only in its encoded form.
179
- continue
180
- }
181
-
182
- // We don't skip extensions that have an encoded form set,
183
- // because the extension value may have been mutated after
184
- // the last time this function was called.
185
-
186
- et := reflect.TypeOf(e.desc.ExtensionType)
187
- props := extensionProperties(e.desc)
188
-
189
- p := NewBuffer(nil)
190
- // If e.value has type T, the encoder expects a *struct{ X T }.
191
- // Pass a *T with a zero field and hope it all works out.
192
- x := reflect.New(et)
193
- x.Elem().Set(reflect.ValueOf(e.value))
194
- if err := props.enc(p, props, toStructPointer(x)); err != nil {
177
+ err := encodeExtension(&e)
178
+ if err != nil {
179
return err
180
}
197
- e.enc = p.buf
181
m[k] = e
182
}
183
return nil
184
}
185
186
+func encodeExtension(e *Extension) error {
187
+ if e.value == nil || e.desc == nil {
188
+ // Extension is only in its encoded form.
189
+ return nil
190
+ }
191
+ // We don't skip extensions that have an encoded form set,
192
+ // because the extension value may have been mutated after
193
+ // the last time this function was called.
194
+
195
+ et := reflect.TypeOf(e.desc.ExtensionType)
196
+ props := extensionProperties(e.desc)
197
+
198
+ p := NewBuffer(nil)
199
+ // If e.value has type T, the encoder expects a *struct{ X T }.
200
+ // Pass a *T with a zero field and hope it all works out.
201
+ x := reflect.New(et)
202
+ x.Elem().Set(reflect.ValueOf(e.value))
203
+ if err := props.enc(p, props, toStructPointer(x)); err != nil {
204
+ return err
205
+ }
206
+ e.enc = p.buf
207
+ return nil
208
+}
209
+
210
func sizeExtensionMap(m map[int32]Extension) (n int) {
211
for _, e := range m {
212
if e.value == nil || e.desc == nil {
@@ -300,7 +307,8 @@ func GetExtension(pb extendableProto, extension *ExtensionDesc) (interface{}, er
307
}
308
309
if epb, doki := pb.(extensionsMap); doki {
303
- e, ok := epb.ExtensionMap()[extension.Field]
310
+ emap := epb.ExtensionMap()
311
+ e, ok := emap[extension.Field]
312
if !ok {
313
return nil, ErrMissingExtension
314
}
@@ -325,6 +333,7 @@ func GetExtension(pb extendableProto, extension *ExtensionDesc) (interface{}, er
333
e.value = v
334
e.desc = extension
335
e.enc = nil
336
+ emap[extension.Field] = e
337
return e.value, nil
338
} else if epb, doki := pb.(extensionsBytes); doki {
339
ext := epb.GetExtensions()
@@ -414,7 +423,10 @@ func SetExtension(pb extendableProto, extension *ExtensionDesc, value interface{
423
if typ != reflect.TypeOf(value) {
424
return errors.New("proto: bad extension value type")
425
}
426
+ return setExtension(pb, extension, value)
427
+}
428
429
+func setExtension(pb extendableProto, extension *ExtensionDesc, value interface{}) error {
430
if epb, doki := pb.(extensionsMap); doki {
431
epb.ExtensionMap()[extension.Field] = Extension{desc: extension, value: value}
432
} else if epb, doki := pb.(extensionsBytes); doki {
Godeps/_workspace/src/github.com/gogo/protobuf/proto/extensions_gogo.go
renamed
+33
-1
@@ -1,5 +1,5 @@
1
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2
-// http://code.google.com/p/gogoprotobuf/gogoproto
2
+// http://github.com/gogo/protobuf/gogoproto
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
@@ -28,6 +28,7 @@ package proto
28
29
import (
30
"bytes"
31
+ "errors"
32
"fmt"
33
"reflect"
34
"sort"
@@ -185,5 +186,36 @@ func NewExtension(e []byte) Extension {
186
}
187
188
func (this Extension) GoString() string {
189
+ if this.enc == nil {
190
+ if err := encodeExtension(&this); err != nil {
191
+ panic(err)
192
+ }
193
+ }
194
return fmt.Sprintf("proto.NewExtension(%#v)", this.enc)
195
}
196
+
197
+func SetUnsafeExtension(pb extendableProto, fieldNum int32, value interface{}) error {
198
+ typ := reflect.TypeOf(pb).Elem()
199
+ ext, ok := extensionMaps[typ]
200
+ if !ok {
201
+ return fmt.Errorf("proto: bad extended type; %s is not extendable", typ.String())
202
+ }
203
+ desc, ok := ext[fieldNum]
204
+ if !ok {
205
+ return errors.New("proto: bad extension number; not in declared ranges")
206
+ }
207
+ return setExtension(pb, desc, value)
208
+}
209
+
210
+func GetUnsafeExtension(pb extendableProto, fieldNum int32) (interface{}, error) {
211
+ typ := reflect.TypeOf(pb).Elem()
212
+ ext, ok := extensionMaps[typ]
213
+ if !ok {
214
+ return nil, fmt.Errorf("proto: bad extended type; %s is not extendable", typ.String())
215
+ }
216
+ desc, ok := ext[fieldNum]
217
+ if !ok {
218
+ return nil, fmt.Errorf("unregistered field number %d", fieldNum)
219
+ }
220
+ return GetExtension(pb, desc)
221
+}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/extensions_test.go
renamed
+36
-2
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2014 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -35,7 +35,7 @@ import (
35
"testing"
36
37
pb "./testdata"
38
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
38
+ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
39
)
40
41
func TestGetExtensionsWithMissingExtensions(t *testing.T) {
@@ -58,3 +58,37 @@ func TestGetExtensionsWithMissingExtensions(t *testing.T) {
58
t.Errorf("ext2 in returned extensions: %T %v", exts[1], exts[1])
59
}
60
}
61
+
62
+func TestGetExtensionStability(t *testing.T) {
63
+ check := func(m *pb.MyMessage) bool {
64
+ ext1, err := proto.GetExtension(m, pb.E_Ext_More)
65
+ if err != nil {
66
+ t.Fatalf("GetExtension() failed: %s", err)
67
+ }
68
+ ext2, err := proto.GetExtension(m, pb.E_Ext_More)
69
+ if err != nil {
70
+ t.Fatalf("GetExtension() failed: %s", err)
71
+ }
72
+ return ext1 == ext2
73
+ }
74
+ msg := &pb.MyMessage{Count: proto.Int32(4)}
75
+ ext0 := &pb.Ext{}
76
+ if err := proto.SetExtension(msg, pb.E_Ext_More, ext0); err != nil {
77
+ t.Fatalf("Could not set ext1: %s", ext0)
78
+ }
79
+ if !check(msg) {
80
+ t.Errorf("GetExtension() not stable before marshaling")
81
+ }
82
+ bb, err := proto.Marshal(msg)
83
+ if err != nil {
84
+ t.Fatalf("Marshal() failed: %s", err)
85
+ }
86
+ msg1 := &pb.MyMessage{}
87
+ err = proto.Unmarshal(bb, msg1)
88
+ if err != nil {
89
+ t.Fatalf("Unmarshal() failed: %s", err)
90
+ }
91
+ if !check(msg1) {
92
+ t.Errorf("GetExtension() not stable after unmarshaling")
93
+ }
94
+}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/lib.go
renamed
+3
-3
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -89,7 +89,7 @@
89
90
package example
91
92
- import "code.google.com/p/goprotobuf/proto"
92
+ import "github.com/gogo/protobuf/proto"
93
94
type FOO int32
95
const (
@@ -168,7 +168,7 @@
168
import (
169
"log"
170
171
- "code.google.com/p/goprotobuf/proto"
171
+ "github.com/gogo/protobuf/proto"
172
"./example.pb"
173
)
174
Godeps/_workspace/src/github.com/gogo/protobuf/proto/lib_gogo.go
renamed
+1
-1
@@ -1,5 +1,5 @@
1
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2
-// http://code.google.com/p/gogoprotobuf/gogoproto
2
+// http://github.com/gogo/protobuf/gogoproto
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
Godeps/_workspace/src/github.com/gogo/protobuf/proto/message_set.go
renamed
+62
-4
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -36,7 +36,10 @@ package proto
36
*/
37
38
import (
39
+ "bytes"
40
+ "encoding/json"
41
"errors"
42
+ "fmt"
43
"reflect"
44
"sort"
45
)
@@ -211,6 +214,61 @@ func UnmarshalMessageSet(buf []byte, m map[int32]Extension) error {
214
return nil
215
}
216
217
+// MarshalMessageSetJSON encodes the extension map represented by m in JSON format.
218
+// It is called by generated MarshalJSON methods on protocol buffer messages with the message_set_wire_format option.
219
+func MarshalMessageSetJSON(m map[int32]Extension) ([]byte, error) {
220
+ var b bytes.Buffer
221
+ b.WriteByte('{')
222
+
223
+ // Process the map in key order for deterministic output.
224
+ ids := make([]int32, 0, len(m))
225
+ for id := range m {
226
+ ids = append(ids, id)
227
+ }
228
+ sort.Sort(int32Slice(ids)) // int32Slice defined in text.go
229
+
230
+ for i, id := range ids {
231
+ ext := m[id]
232
+ if i > 0 {
233
+ b.WriteByte(',')
234
+ }
235
+
236
+ msd, ok := messageSetMap[id]
237
+ if !ok {
238
+ // Unknown type; we can't render it, so skip it.
239
+ continue
240
+ }
241
+ fmt.Fprintf(&b, `"[%s]":`, msd.name)
242
+
243
+ x := ext.value
244
+ if x == nil {
245
+ x = reflect.New(msd.t.Elem()).Interface()
246
+ if err := Unmarshal(ext.enc, x.(Message)); err != nil {
247
+ return nil, err
248
+ }
249
+ }
250
+ d, err := json.Marshal(x)
251
+ if err != nil {
252
+ return nil, err
253
+ }
254
+ b.Write(d)
255
+ }
256
+ b.WriteByte('}')
257
+ return b.Bytes(), nil
258
+}
259
+
260
+// UnmarshalMessageSetJSON decodes the extension map encoded in buf in JSON format.
261
+// It is called by generated UnmarshalJSON methods on protocol buffer messages with the message_set_wire_format option.
262
+func UnmarshalMessageSetJSON(buf []byte, m map[int32]Extension) error {
263
+ // Common-case fast path.
264
+ if len(buf) == 0 || bytes.Equal(buf, []byte("{}")) {
265
+ return nil
266
+ }
267
+
268
+ // This is fairly tricky, and it's not clear that it is needed.
269
+ return errors.New("TODO: UnmarshalMessageSetJSON not yet implemented")
270
+}
271
+
272
// A global registry of types that can be used in a MessageSet.
273
274
var messageSetMap = make(map[int32]messageSetDesc)
@@ -221,9 +279,9 @@ type messageSetDesc struct {
279
}
280
281
// RegisterMessageSetType is called from the generated code.
224
-func RegisterMessageSetType(i messageTypeIder, name string) {
225
- messageSetMap[i.MessageTypeId()] = messageSetDesc{
226
- t: reflect.TypeOf(i),
282
+func RegisterMessageSetType(m Message, fieldNum int32, name string) {
283
+ messageSetMap[fieldNum] = messageSetDesc{
284
+ t: reflect.TypeOf(m),
285
name: name,
286
}
287
}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/message_set_test.go
renamed
+1
-1
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2014 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
Godeps/_workspace/src/github.com/gogo/protobuf/proto/pointer_reflect.go
renamed
+1
-1
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2012 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
Godeps/_workspace/src/github.com/gogo/protobuf/proto/pointer_unsafe.go
renamed
+1
-1
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2012 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
Godeps/_workspace/src/github.com/gogo/protobuf/proto/pointer_unsafe_gogo.go
renamed
+1
-1
@@ -1,5 +1,5 @@
1
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2
-// http://code.google.com/p/gogoprotobuf/gogoproto
2
+// http://github.com/gogo/protobuf/gogoproto
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
Godeps/_workspace/src/github.com/gogo/protobuf/proto/properties.go
renamed
+44
-19
@@ -1,7 +1,12 @@
1
+// Extensions for Protocol Buffers to create more go like structures.
2
+//
3
+// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
4
+// http://github.com/gogo/protobuf/gogoproto
5
+//
6
// Go support for Protocol Buffers - Google's data interchange format
7
//
8
// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
9
+// https://github.com/golang/protobuf
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
@@ -158,6 +163,7 @@ type Properties struct {
163
164
Default string // default value
165
HasDefault bool // whether an explicit default was provided
166
+ CustomType string
167
def_uint64 uint64
168
169
enc encoder
@@ -166,6 +172,8 @@ type Properties struct {
172
tagcode []byte // encoding of EncodeVarint((Tag<<3)|WireType)
173
tagbuf [8]byte
174
stype reflect.Type // set for struct types only
175
+ sstype reflect.Type // set for slices of structs types only
176
+ ctype reflect.Type // set for custom types only
177
sprop *StructProperties // set for struct types only
178
isMarshaler bool
179
isUnmarshaler bool
@@ -282,6 +290,10 @@ func (p *Properties) Parse(s string) {
290
p.Default += "," + strings.Join(fields[i+1:], ",")
291
break
292
}
293
+ case strings.HasPrefix(f, "embedded="):
294
+ p.OrigName = strings.Split(f, "=")[1]
295
+ case strings.HasPrefix(f, "customtype="):
296
+ p.CustomType = strings.Split(f, "=")[1]
297
}
298
}
299
}
@@ -297,11 +309,16 @@ func (p *Properties) setEncAndDec(typ reflect.Type, lockGetProp bool) {
309
p.enc = nil
310
p.dec = nil
311
p.size = nil
300
-
312
+ if len(p.CustomType) > 0 {
313
+ p.setCustomEncAndDec(typ)
314
+ p.setTag(lockGetProp)
315
+ return
316
+ }
317
switch t1 := typ; t1.Kind() {
318
default:
303
- fmt.Fprintf(os.Stderr, "proto: no coders for %T\n", t1)
304
-
319
+ if !p.setNonNullableEncAndDec(t1) {
320
+ fmt.Fprintf(os.Stderr, "proto: no coders for %v\n", t1)
321
+ }
322
case reflect.Ptr:
323
switch t2 := t1.Elem(); t2.Kind() {
324
default:
@@ -460,9 +477,14 @@ func (p *Properties) setEncAndDec(typ reflect.Type, lockGetProp bool) {
477
p.dec = (*Buffer).dec_slice_slice_byte
478
p.size = size_slice_slice_byte
479
}
480
+ case reflect.Struct:
481
+ p.setSliceOfNonPointerStructs(t1)
482
}
483
}
484
+ p.setTag(lockGetProp)
485
+}
486
487
+func (p *Properties) setTag(lockGetProp bool) {
488
// precalculate tag code
489
wire := p.WireType
490
if p.Packed {
@@ -493,23 +515,11 @@ var (
515
516
// isMarshaler reports whether type t implements Marshaler.
517
func isMarshaler(t reflect.Type) bool {
496
- // We're checking for (likely) pointer-receiver methods
497
- // so if t is not a pointer, something is very wrong.
498
- // The calls above only invoke isMarshaler on pointer types.
499
- if t.Kind() != reflect.Ptr {
500
- panic("proto: misuse of isMarshaler")
501
- }
518
return t.Implements(marshalerType)
519
}
520
521
// isUnmarshaler reports whether type t implements Unmarshaler.
522
func isUnmarshaler(t reflect.Type) bool {
507
- // We're checking for (likely) pointer-receiver methods
508
- // so if t is not a pointer, something is very wrong.
509
- // The calls above only invoke isUnmarshaler on pointer types.
510
- if t.Kind() != reflect.Ptr {
511
- panic("proto: misuse of isUnmarshaler")
512
- }
523
return t.Implements(unmarshalerType)
524
}
525
@@ -538,7 +548,11 @@ var (
548
)
549
550
// GetProperties returns the list of properties for the type represented by t.
551
+// t must represent a generated struct type of a protocol message.
552
func GetProperties(t reflect.Type) *StructProperties {
553
+ if t.Kind() != reflect.Struct {
554
+ panic("proto: type must have kind struct")
555
+ }
556
mutex.Lock()
557
sprop := getPropertiesLocked(t)
558
mutex.Unlock()
@@ -574,9 +588,15 @@ func getPropertiesLocked(t reflect.Type) *StructProperties {
588
p.init(f.Type, name, f.Tag.Get("protobuf"), &f, false)
589
590
if f.Name == "XXX_extensions" { // special case
577
- p.enc = (*Buffer).enc_map
578
- p.dec = nil // not needed
579
- p.size = size_map
591
+ if len(f.Tag.Get("protobuf")) > 0 {
592
+ p.enc = (*Buffer).enc_ext_slice_byte
593
+ p.dec = nil // not needed
594
+ p.size = size_ext_slice_byte
595
+ } else {
596
+ p.enc = (*Buffer).enc_map
597
+ p.dec = nil // not needed
598
+ p.size = size_map
599
+ }
600
}
601
if f.Name == "XXX_unrecognized" { // special case
602
prop.unrecField = toField(&f)
@@ -647,6 +667,7 @@ func getbase(pb Message) (t reflect.Type, b structPointer, err error) {
667
// The generated code will register the generated maps by calling RegisterEnum.
668
669
var enumValueMaps = make(map[string]map[string]int32)
670
+var enumStringMaps = make(map[string]map[int32]string)
671
672
// RegisterEnum is called from the generated code to install the enum descriptor
673
// maps into the global table to aid parsing text format protocol buffers.
@@ -655,4 +676,8 @@ func RegisterEnum(typeName string, unusedNameMap map[int32]string, valueMap map[
676
panic("proto: duplicate enum registered: " + typeName)
677
}
678
enumValueMaps[typeName] = valueMap
679
+ if _, ok := enumStringMaps[typeName]; ok {
680
+ panic("proto: duplicate enum registered: " + typeName)
681
+ }
682
+ enumStringMaps[typeName] = unusedNameMap
683
}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/properties_gogo.go
renamed
+8
-4
@@ -1,5 +1,5 @@
1
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2
-// http://code.google.com/p/gogoprotobuf/gogoproto
2
+// http://github.com/gogo/protobuf/gogoproto
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
@@ -55,18 +55,22 @@ func (p *Properties) setNonNullableEncAndDec(typ reflect.Type) bool {
55
p.enc = (*Buffer).enc_ref_bool
56
p.dec = (*Buffer).dec_ref_bool
57
p.size = size_ref_bool
58
- case reflect.Int32, reflect.Uint32:
58
+ case reflect.Int32:
59
p.enc = (*Buffer).enc_ref_int32
60
p.dec = (*Buffer).dec_ref_int32
61
p.size = size_ref_int32
62
+ case reflect.Uint32:
63
+ p.enc = (*Buffer).enc_ref_uint32
64
+ p.dec = (*Buffer).dec_ref_int32
65
+ p.size = size_ref_uint32
66
case reflect.Int64, reflect.Uint64:
67
p.enc = (*Buffer).enc_ref_int64
68
p.dec = (*Buffer).dec_ref_int64
69
p.size = size_ref_int64
70
case reflect.Float32:
67
- p.enc = (*Buffer).enc_ref_int32 // can just treat them as bits
71
+ p.enc = (*Buffer).enc_ref_uint32 // can just treat them as bits
72
p.dec = (*Buffer).dec_ref_int32
69
- p.size = size_ref_int32
73
+ p.size = size_ref_uint32
74
case reflect.Float64:
75
p.enc = (*Buffer).enc_ref_int64 // can just treat them as bits
76
p.dec = (*Buffer).dec_ref_int64
Godeps/_workspace/src/github.com/gogo/protobuf/proto/size2_test.go
renamed
+1
-1
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2012 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
Godeps/_workspace/src/github.com/gogo/protobuf/proto/size_test.go
renamed
+2
-2
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2012 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -36,7 +36,7 @@ import (
36
"testing"
37
38
pb "./testdata"
39
- . "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
39
+ . "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
40
)
41
42
var messageWithExtension1 = &pb.MyMessage{Count: Int32(7)}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/skip_gogo.go
renamed
+1
-1
@@ -1,5 +1,5 @@
1
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2
-// http://code.google.com/p/gogoprotobuf/gogoproto
2
+// http://github.com/gogo/protobuf/gogoproto
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
Godeps/_workspace/src/github.com/gogo/protobuf/proto/testdata/Makefile
renamed
+1
-1
@@ -1,7 +1,7 @@
1
# Go support for Protocol Buffers - Google's data interchange format
2
#
3
# Copyright 2010 The Go Authors. All rights reserved.
4
-# http://code.google.com/p/goprotobuf/
4
+# https://github.com/golang/protobuf
5
#
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions are
Godeps/_workspace/src/github.com/gogo/protobuf/proto/testdata/golden_test.go
renamed
+1
-1
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2012 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
Godeps/_workspace/src/github.com/gogo/protobuf/proto/testdata/test.pb.go
renamed
+8
-2
@@ -1,4 +1,4 @@
1
-// Code generated by protoc-gen-go.
1
+// Code generated by protoc-gen-gogo.
2
// source: test.proto
3
// DO NOT EDIT!
4
@@ -36,7 +36,7 @@ It has these top-level messages:
36
*/
37
package testdata
38
39
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
39
+import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
40
import math "math"
41
42
// Reference imports to suppress errors if they are not otherwise used.
@@ -1416,6 +1416,12 @@ func (m *MyMessageSet) Marshal() ([]byte, error) {
1416
func (m *MyMessageSet) Unmarshal(buf []byte) error {
1417
return proto.UnmarshalMessageSet(buf, m.ExtensionMap())
1418
}
1419
+func (m *MyMessageSet) MarshalJSON() ([]byte, error) {
1420
+ return proto.MarshalMessageSetJSON(m.XXX_extensions)
1421
+}
1422
+func (m *MyMessageSet) UnmarshalJSON(buf []byte) error {
1423
+ return proto.UnmarshalMessageSetJSON(buf, m.XXX_extensions)
1424
+}
1425
1426
// ensure MyMessageSet satisfies proto.Marshaler and proto.Unmarshaler
1427
var _ proto.Marshaler = (*MyMessageSet)(nil)
Godeps/_workspace/src/github.com/gogo/protobuf/proto/testdata/test.pb.go.golden
renamed
+1
-1
@@ -4,7 +4,7 @@
4
5
package testdata
6
7
-import proto "code.google.com/p/gogoprotobuf/proto"
7
+import proto "github.com/gogo/protobuf/proto"
8
import json "encoding/json"
9
import math "math"
10
Godeps/_workspace/src/github.com/gogo/protobuf/proto/testdata/test.proto
renamed
+1
-1
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
Godeps/_workspace/src/github.com/gogo/protobuf/proto/text.go
renamed
+5
-11
@@ -1,12 +1,12 @@
1
// Extensions for Protocol Buffers to create more go like structures.
2
//
3
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
4
-// http://code.google.com/p/gogoprotobuf/gogoproto
4
+// http://github.com/gogo/protobuf/gogoproto
5
//
6
// Go support for Protocol Buffers - Google's data interchange format
7
//
8
// Copyright 2010 The Go Authors. All rights reserved.
9
-// http://code.google.com/p/goprotobuf/
9
+// https://github.com/golang/protobuf
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
@@ -41,6 +41,7 @@ package proto
41
import (
42
"bufio"
43
"bytes"
44
+ "encoding"
45
"fmt"
46
"io"
47
"log"
@@ -79,13 +80,6 @@ type textWriter struct {
80
w writer
81
}
82
82
-// textMarshaler is implemented by Messages that can marshal themsleves.
83
-// It is identical to encoding.TextMarshaler, introduced in go 1.2,
84
-// which will eventually replace it.
85
-type textMarshaler interface {
86
- MarshalText() (text []byte, err error)
87
-}
88
-
83
func (w *textWriter) WriteString(s string) (n int, err error) {
84
if !strings.Contains(s, "\n") {
85
if !w.compact && w.complete {
@@ -382,7 +376,7 @@ func writeAny(w *textWriter, v reflect.Value, props *Properties) error {
376
}
377
}
378
w.indent()
385
- if tm, ok := v.Interface().(textMarshaler); ok {
379
+ if tm, ok := v.Interface().(encoding.TextMarshaler); ok {
380
text, err := tm.MarshalText()
381
if err != nil {
382
return err
@@ -688,7 +682,7 @@ func marshalText(w io.Writer, pb Message, compact bool) error {
682
compact: compact,
683
}
684
691
- if tm, ok := pb.(textMarshaler); ok {
685
+ if tm, ok := pb.(encoding.TextMarshaler); ok {
686
text, err := tm.MarshalText()
687
if err != nil {
688
return err
Godeps/_workspace/src/github.com/gogo/protobuf/proto/text_gogo.go
renamed
+1
-1
@@ -1,5 +1,5 @@
1
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
2
-// http://code.google.com/p/gogoprotobuf/gogoproto
2
+// http://github.com/gogo/protobuf/gogoproto
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are
Godeps/_workspace/src/github.com/gogo/protobuf/proto/text_parser.go
renamed
+31
-28
@@ -1,12 +1,12 @@
1
// Extensions for Protocol Buffers to create more go like structures.
2
//
3
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
4
-// http://code.google.com/p/gogoprotobuf/gogoproto
4
+// http://github.com/gogo/protobuf/gogoproto
5
//
6
// Go support for Protocol Buffers - Google's data interchange format
7
//
8
// Copyright 2010 The Go Authors. All rights reserved.
9
-// http://code.google.com/p/goprotobuf/
9
+// https://github.com/golang/protobuf
10
//
11
// Redistribution and use in source and binary forms, with or without
12
// modification, are permitted provided that the following conditions are
@@ -40,6 +40,7 @@ package proto
40
// TODO: message sets.
41
42
import (
43
+ "encoding"
44
"errors"
45
"fmt"
46
"reflect"
@@ -48,13 +49,6 @@ import (
49
"unicode/utf8"
50
)
51
51
-// textUnmarshaler is implemented by Messages that can unmarshal themsleves.
52
-// It is identical to encoding.TextUnmarshaler, introduced in go 1.2,
53
-// which will eventually replace it.
54
-type textUnmarshaler interface {
55
- UnmarshalText(text []byte) error
56
-}
57
-
52
type ParseError struct {
53
Message string
54
Line int // 1-based line number
@@ -366,8 +360,8 @@ func (p *textParser) next() *token {
360
return &p.cur
361
}
362
369
-// Return an error indicating which required field was not set.
370
-func (p *textParser) missingRequiredFieldError(sv reflect.Value) *ParseError {
363
+// Return a RequiredNotSetError indicating which required field was not set.
364
+func (p *textParser) missingRequiredFieldError(sv reflect.Value) *RequiredNotSetError {
365
st := sv.Type()
366
sprops := GetProperties(st)
367
for i := 0; i < st.NumField(); i++ {
@@ -377,10 +371,10 @@ func (p *textParser) missingRequiredFieldError(sv reflect.Value) *ParseError {
371
372
props := sprops.Prop[i]
373
if props.Required {
380
- return p.errorf("message %v missing required field %q", st, props.OrigName)
374
+ return &RequiredNotSetError{fmt.Sprintf("%v.%v", st, props.OrigName)}
375
}
376
}
383
- return p.errorf("message %v missing required field", st) // should not happen
377
+ return &RequiredNotSetError{fmt.Sprintf("%v.<unknown field name>", st)} // should not happen
378
}
379
380
// Returns the index in the struct for the named field, as well as the parsed tag properties.
@@ -431,9 +425,11 @@ func (p *textParser) checkForColon(props *Properties, typ reflect.Type) *ParseEr
425
return nil
426
}
427
434
-func (p *textParser) readStruct(sv reflect.Value, terminator string) *ParseError {
428
+func (p *textParser) readStruct(sv reflect.Value, terminator string) error {
429
st := sv.Type()
430
reqCount := GetProperties(st).reqCount
431
+ var reqFieldErr error
432
+ fieldSet := make(map[string]bool)
433
// A struct is a sequence of "name: value", terminated by one of
434
// '>' or '}', or the end of the input. A name may also be
435
// "[extension]".
@@ -494,7 +490,10 @@ func (p *textParser) readStruct(sv reflect.Value, terminator string) *ParseError
490
ext = reflect.New(typ.Elem()).Elem()
491
}
492
if err := p.readAny(ext, props); err != nil {
497
- return err
493
+ if _, ok := err.(*RequiredNotSetError); !ok {
494
+ return err
495
+ }
496
+ reqFieldErr = err
497
}
498
ep := sv.Addr().Interface().(extendableProto)
499
if !rep {
@@ -512,17 +511,17 @@ func (p *textParser) readStruct(sv reflect.Value, terminator string) *ParseError
511
}
512
} else {
513
// This is a normal, non-extension field.
515
- fi, props, ok := structFieldByName(st, tok.value)
514
+ name := tok.value
515
+ fi, props, ok := structFieldByName(st, name)
516
if !ok {
517
- return p.errorf("unknown field name %q in %v", tok.value, st)
517
+ return p.errorf("unknown field name %q in %v", name, st)
518
}
519
520
dst := sv.Field(fi)
521
- isDstNil := isNil(dst)
521
522
// Check that it's not already set if it's not a repeated field.
524
- if !props.Repeated && !isDstNil && dst.Kind() == reflect.Ptr {
525
- return p.errorf("non-repeated field %q was repeated", tok.value)
523
+ if !props.Repeated && fieldSet[name] {
524
+ return p.errorf("non-repeated field %q was repeated", name)
525
}
526
527
if err := p.checkForColon(props, st.Field(fi).Type); err != nil {
@@ -530,11 +529,13 @@ func (p *textParser) readStruct(sv reflect.Value, terminator string) *ParseError
529
}
530
531
// Parse into the field.
532
+ fieldSet[name] = true
533
if err := p.readAny(dst, props); err != nil {
534
- return err
535
- }
536
-
537
- if props.Required {
534
+ if _, ok := err.(*RequiredNotSetError); !ok {
535
+ return err
536
+ }
537
+ reqFieldErr = err
538
+ } else if props.Required {
539
reqCount--
540
}
541
}
@@ -552,10 +553,10 @@ func (p *textParser) readStruct(sv reflect.Value, terminator string) *ParseError
553
if reqCount > 0 {
554
return p.missingRequiredFieldError(sv)
555
}
555
- return nil
556
+ return reqFieldErr
557
}
558
558
-func (p *textParser) readAny(v reflect.Value, props *Properties) *ParseError {
559
+func (p *textParser) readAny(v reflect.Value, props *Properties) error {
560
tok := p.next()
561
if tok.err != nil {
562
return tok.err
@@ -695,7 +696,7 @@ func (p *textParser) readAny(v reflect.Value, props *Properties) *ParseError {
696
default:
697
return p.errorf("expected '{' or '<', found %q", tok.value)
698
}
698
- // TODO: Handle nested messages which implement textUnmarshaler.
699
+ // TODO: Handle nested messages which implement encoding.TextUnmarshaler.
700
return p.readStruct(fv, terminator)
701
case reflect.Uint32:
702
if x, err := strconv.ParseUint(tok.value, 0, 32); err == nil {
@@ -713,8 +714,10 @@ func (p *textParser) readAny(v reflect.Value, props *Properties) *ParseError {
714
715
// UnmarshalText reads a protocol buffer in Text format. UnmarshalText resets pb
716
// before starting to unmarshal, so any existing data in pb is always removed.
717
+// If a required field is not set and no other error occurs,
718
+// UnmarshalText returns *RequiredNotSetError.
719
func UnmarshalText(s string, pb Message) error {
717
- if um, ok := pb.(textUnmarshaler); ok {
720
+ if um, ok := pb.(encoding.TextUnmarshaler); ok {
721
err := um.UnmarshalText([]byte(s))
722
return err
723
}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/text_parser_test.go
renamed
+10
-4
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -37,7 +37,7 @@ import (
37
"testing"
38
39
. "./testdata"
40
- . "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
40
+ . "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
41
)
42
43
type UnmarshalTextTest struct {
@@ -294,8 +294,11 @@ var unMarshalTextTests = []UnmarshalTextTest{
294
295
// Missing required field
296
{
297
- in: ``,
298
- err: `line 1.0: message testdata.MyMessage missing required field "count"`,
297
+ in: `name: "Pawel"`,
298
+ err: `proto: required field "testdata.MyMessage.count" not set`,
299
+ out: &MyMessage{
300
+ Name: String("Pawel"),
301
+ },
302
},
303
304
// Repeated non-repeated field
@@ -408,6 +411,9 @@ func TestUnmarshalText(t *testing.T) {
411
} else if err.Error() != test.err {
412
t.Errorf("Test %d: Incorrect error.\nHave: %v\nWant: %v",
413
i, err.Error(), test.err)
414
+ } else if _, ok := err.(*RequiredNotSetError); ok && test.out != nil && !reflect.DeepEqual(pb, test.out) {
415
+ t.Errorf("Test %d: Incorrect populated \nHave: %v\nWant: %v",
416
+ i, pb, test.out)
417
}
418
}
419
}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/text_test.go
renamed
+2
-3
@@ -1,7 +1,7 @@
1
// Go support for Protocol Buffers - Google's data interchange format
2
//
3
// Copyright 2010 The Go Authors. All rights reserved.
4
-// http://code.google.com/p/goprotobuf/
4
+// https://github.com/golang/protobuf
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are
@@ -39,9 +39,8 @@ import (
39
"strings"
40
"testing"
41
42
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
43
-
42
pb "./testdata"
43
+ "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
44
)
45
46
// textMessage implements the methods that allow it to marshal and unmarshal
diagnostics/diag.go
+6
-7
@@ -4,25 +4,24 @@
4
package diagnostics
5
6
import (
7
+ "crypto/rand"
8
"encoding/json"
9
"errors"
10
"fmt"
11
"sync"
12
"time"
13
13
- "crypto/rand"
14
-
15
- ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/io"
16
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
14
+ ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
15
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
16
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
17
+
18
+ pb "github.com/ipfs/go-ipfs/diagnostics/internal/pb"
19
host "github.com/ipfs/go-ipfs/p2p/host"
20
inet "github.com/ipfs/go-ipfs/p2p/net"
21
peer "github.com/ipfs/go-ipfs/p2p/peer"
22
protocol "github.com/ipfs/go-ipfs/p2p/protocol"
22
- ctxutil "github.com/ipfs/go-ipfs/util/ctx"
23
-
24
- pb "github.com/ipfs/go-ipfs/diagnostics/internal/pb"
23
util "github.com/ipfs/go-ipfs/util"
24
+ ctxutil "github.com/ipfs/go-ipfs/util/ctx"
25
)
26
27
var log = util.Logger("diagnostics")
diagnostics/internal/pb/diagnostics.pb.go
+2
-4
@@ -13,13 +13,11 @@ It has these top-level messages:
13
*/
14
package diagnostics_pb
15
16
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
17
-import json "encoding/json"
16
+import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
17
import math "math"
18
20
-// Reference proto, json, and math imports to suppress error if they are not otherwise used.
19
+// Reference imports to suppress errors if they are not otherwise used.
20
var _ = proto.Marshal
22
-var _ = &json.SyntaxError{}
21
var _ = math.Inf
22
23
type Message struct {
exchange/bitswap/message/internal/pb/message.pb.go
+1
-1
@@ -13,7 +13,7 @@ It has these top-level messages:
13
*/
14
package bitswap_message_pb
15
16
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
16
+import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
17
import math "math"
18
19
// Reference imports to suppress errors if they are not otherwise used.
exchange/bitswap/message/message.go
+2
-2
@@ -9,8 +9,8 @@ import (
9
inet "github.com/ipfs/go-ipfs/p2p/net"
10
u "github.com/ipfs/go-ipfs/util"
11
12
- ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/io"
13
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
12
+ ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
13
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
14
)
15
16
// TODO move message.go into the bitswap package
exchange/bitswap/message/message_test.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"bytes"
5
"testing"
6
7
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
7
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
8
9
blocks "github.com/ipfs/go-ipfs/blocks"
10
pb "github.com/ipfs/go-ipfs/exchange/bitswap/message/internal/pb"
fuse/readonly/readonly_unix.go
+1
-1
@@ -9,7 +9,7 @@ import (
9
10
fuse "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
11
fs "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs"
12
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
12
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
13
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
14
core "github.com/ipfs/go-ipfs/core"
15
mdag "github.com/ipfs/go-ipfs/merkledag"
merkledag/internal/pb/merkledag.pb.go
+48
-48
@@ -14,27 +14,21 @@
14
*/
15
package merkledag_pb
16
17
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
17
+import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
18
import math "math"
19
20
// discarding unused import gogoproto "code.google.com/p/gogoprotobuf/gogoproto/gogo.pb"
21
22
import io "io"
23
import fmt "fmt"
24
-import code_google_com_p_gogoprotobuf_proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
24
+import github_com_gogo_protobuf_proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
25
26
-import fmt1 "fmt"
26
import strings "strings"
27
import reflect "reflect"
28
30
-import fmt2 "fmt"
31
-import strings1 "strings"
32
-import code_google_com_p_gogoprotobuf_proto1 "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
29
import sort "sort"
30
import strconv "strconv"
35
-import reflect1 "reflect"
31
37
-import fmt3 "fmt"
32
import bytes "bytes"
33
34
// Reference imports to suppress errors if they are not otherwise used.
@@ -143,7 +137,7 @@ func (m *PBLink) Unmarshal(data []byte) error {
137
if postIndex > l {
138
return io.ErrUnexpectedEOF
139
}
146
- m.Hash = append(m.Hash, data[index:postIndex]...)
140
+ m.Hash = append([]byte{}, data[index:postIndex]...)
141
index = postIndex
142
case 2:
143
if wireType != 2 {
@@ -195,7 +189,7 @@ func (m *PBLink) Unmarshal(data []byte) error {
189
}
190
}
191
index -= sizeOfWire
198
- skippy, err := code_google_com_p_gogoprotobuf_proto.Skip(data[index:])
192
+ skippy, err := github_com_gogo_protobuf_proto.Skip(data[index:])
193
if err != nil {
194
return err
195
}
@@ -270,7 +264,7 @@ func (m *PBNode) Unmarshal(data []byte) error {
264
if postIndex > l {
265
return io.ErrUnexpectedEOF
266
}
273
- m.Data = append(m.Data, data[index:postIndex]...)
267
+ m.Data = append([]byte{}, data[index:postIndex]...)
268
index = postIndex
269
default:
270
var sizeOfWire int
@@ -282,7 +276,7 @@ func (m *PBNode) Unmarshal(data []byte) error {
276
}
277
}
278
index -= sizeOfWire
285
- skippy, err := code_google_com_p_gogoprotobuf_proto.Skip(data[index:])
279
+ skippy, err := github_com_gogo_protobuf_proto.Skip(data[index:])
280
if err != nil {
281
return err
282
}
@@ -303,7 +297,7 @@ func (this *PBLink) String() string {
297
`Hash:` + valueToStringMerkledag(this.Hash) + `,`,
298
`Name:` + valueToStringMerkledag(this.Name) + `,`,
299
`Tsize:` + valueToStringMerkledag(this.Tsize) + `,`,
306
- `XXX_unrecognized:` + fmt1.Sprintf("%v", this.XXX_unrecognized) + `,`,
300
+ `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`,
301
`}`,
302
}, "")
303
return s
@@ -313,9 +307,9 @@ func (this *PBNode) String() string {
307
return "nil"
308
}
309
s := strings.Join([]string{`&PBNode{`,
316
- `Links:` + strings.Replace(fmt1.Sprintf("%v", this.Links), "PBLink", "PBLink", 1) + `,`,
310
+ `Links:` + strings.Replace(fmt.Sprintf("%v", this.Links), "PBLink", "PBLink", 1) + `,`,
311
`Data:` + valueToStringMerkledag(this.Data) + `,`,
318
- `XXX_unrecognized:` + fmt1.Sprintf("%v", this.XXX_unrecognized) + `,`,
312
+ `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`,
313
`}`,
314
}, "")
315
return s
@@ -326,7 +320,7 @@ func valueToStringMerkledag(v interface{}) string {
320
return "nil"
321
}
322
pv := reflect.Indirect(rv).Interface()
329
- return fmt1.Sprintf("*%v", pv)
323
+ return fmt.Sprintf("*%v", pv)
324
}
325
func (m *PBLink) Size() (n int) {
326
var l int
@@ -347,6 +341,7 @@ func (m *PBLink) Size() (n int) {
341
}
342
return n
343
}
344
+
345
func (m *PBNode) Size() (n int) {
346
var l int
347
_ = l
@@ -434,11 +429,7 @@ type randyMerkledag interface {
429
}
430
431
func randUTF8RuneMerkledag(r randyMerkledag) rune {
437
- res := rune(r.Uint32() % 1112064)
438
- if 55296 <= res {
439
- res += 2047
440
- }
441
- return res
432
+ return rune(r.Intn(126-43) + 43)
433
}
434
func randStringMerkledag(r randyMerkledag) string {
435
v6 := r.Intn(100)
@@ -531,6 +522,7 @@ func (m *PBLink) MarshalTo(data []byte) (n int, err error) {
522
}
523
return i, nil
524
}
525
+
526
func (m *PBNode) Marshal() (data []byte, err error) {
527
size := m.Size()
528
data = make([]byte, size)
@@ -569,6 +561,7 @@ func (m *PBNode) MarshalTo(data []byte) (n int, err error) {
561
}
562
return i, nil
563
}
564
+
565
func encodeFixed64Merkledag(data []byte, offset int, v uint64) int {
566
data[offset] = uint8(v)
567
data[offset+1] = uint8(v >> 8)
@@ -600,25 +593,32 @@ func (this *PBLink) GoString() string {
593
if this == nil {
594
return "nil"
595
}
603
- 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) + `}`}, ", ")
596
+ s := strings.Join([]string{`&merkledag_pb.PBLink{` +
597
+ `Hash:` + valueToGoStringMerkledag(this.Hash, "byte"),
598
+ `Name:` + valueToGoStringMerkledag(this.Name, "string"),
599
+ `Tsize:` + valueToGoStringMerkledag(this.Tsize, "uint64"),
600
+ `XXX_unrecognized:` + fmt.Sprintf("%#v", this.XXX_unrecognized) + `}`}, ", ")
601
return s
602
}
603
func (this *PBNode) GoString() string {
604
if this == nil {
605
return "nil"
606
}
610
- 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) + `}`}, ", ")
607
+ s := strings.Join([]string{`&merkledag_pb.PBNode{` +
608
+ `Links:` + fmt.Sprintf("%#v", this.Links),
609
+ `Data:` + valueToGoStringMerkledag(this.Data, "byte"),
610
+ `XXX_unrecognized:` + fmt.Sprintf("%#v", this.XXX_unrecognized) + `}`}, ", ")
611
return s
612
}
613
func valueToGoStringMerkledag(v interface{}, typ string) string {
614
- rv := reflect1.ValueOf(v)
614
+ rv := reflect.ValueOf(v)
615
if rv.IsNil() {
616
return "nil"
617
}
618
- pv := reflect1.Indirect(rv).Interface()
619
- return fmt2.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv)
618
+ pv := reflect.Indirect(rv).Interface()
619
+ return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv)
620
}
621
-func extensionToGoStringMerkledag(e map[int32]code_google_com_p_gogoprotobuf_proto1.Extension) string {
621
+func extensionToGoStringMerkledag(e map[int32]github_com_gogo_protobuf_proto.Extension) string {
622
if e == nil {
623
return "nil"
624
}
@@ -632,7 +632,7 @@ func extensionToGoStringMerkledag(e map[int32]code_google_com_p_gogoprotobuf_pro
632
for _, k := range keys {
633
ss = append(ss, strconv.Itoa(k)+": "+e[int32(k)].GoString())
634
}
635
- s += strings1.Join(ss, ",") + "}"
635
+ s += strings.Join(ss, ",") + "}"
636
return s
637
}
638
func (this *PBLink) VerboseEqual(that interface{}) error {
@@ -640,44 +640,44 @@ func (this *PBLink) VerboseEqual(that interface{}) error {
640
if this == nil {
641
return nil
642
}
643
- return fmt3.Errorf("that == nil && this != nil")
643
+ return fmt.Errorf("that == nil && this != nil")
644
}
645
646
that1, ok := that.(*PBLink)
647
if !ok {
648
- return fmt3.Errorf("that is not of type *PBLink")
648
+ return fmt.Errorf("that is not of type *PBLink")
649
}
650
if that1 == nil {
651
if this == nil {
652
return nil
653
}
654
- return fmt3.Errorf("that is type *PBLink but is nil && this != nil")
654
+ return fmt.Errorf("that is type *PBLink but is nil && this != nil")
655
} else if this == nil {
656
- return fmt3.Errorf("that is type *PBLinkbut is not nil && this == nil")
656
+ return fmt.Errorf("that is type *PBLinkbut is not nil && this == nil")
657
}
658
if !bytes.Equal(this.Hash, that1.Hash) {
659
- return fmt3.Errorf("Hash this(%v) Not Equal that(%v)", this.Hash, that1.Hash)
659
+ return fmt.Errorf("Hash this(%v) Not Equal that(%v)", this.Hash, that1.Hash)
660
}
661
if this.Name != nil && that1.Name != nil {
662
if *this.Name != *that1.Name {
663
- return fmt3.Errorf("Name this(%v) Not Equal that(%v)", *this.Name, *that1.Name)
663
+ return fmt.Errorf("Name this(%v) Not Equal that(%v)", *this.Name, *that1.Name)
664
}
665
} else if this.Name != nil {
666
- return fmt3.Errorf("this.Name == nil && that.Name != nil")
666
+ return fmt.Errorf("this.Name == nil && that.Name != nil")
667
} else if that1.Name != nil {
668
- return fmt3.Errorf("Name this(%v) Not Equal that(%v)", this.Name, that1.Name)
668
+ return fmt.Errorf("Name this(%v) Not Equal that(%v)", this.Name, that1.Name)
669
}
670
if this.Tsize != nil && that1.Tsize != nil {
671
if *this.Tsize != *that1.Tsize {
672
- return fmt3.Errorf("Tsize this(%v) Not Equal that(%v)", *this.Tsize, *that1.Tsize)
672
+ return fmt.Errorf("Tsize this(%v) Not Equal that(%v)", *this.Tsize, *that1.Tsize)
673
}
674
} else if this.Tsize != nil {
675
- return fmt3.Errorf("this.Tsize == nil && that.Tsize != nil")
675
+ return fmt.Errorf("this.Tsize == nil && that.Tsize != nil")
676
} else if that1.Tsize != nil {
677
- return fmt3.Errorf("Tsize this(%v) Not Equal that(%v)", this.Tsize, that1.Tsize)
677
+ return fmt.Errorf("Tsize this(%v) Not Equal that(%v)", this.Tsize, that1.Tsize)
678
}
679
if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) {
680
- return fmt3.Errorf("XXX_unrecognized this(%v) Not Equal that(%v)", this.XXX_unrecognized, that1.XXX_unrecognized)
680
+ return fmt.Errorf("XXX_unrecognized this(%v) Not Equal that(%v)", this.XXX_unrecognized, that1.XXX_unrecognized)
681
}
682
return nil
683
}
@@ -732,34 +732,34 @@ func (this *PBNode) VerboseEqual(that interface{}) error {
732
if this == nil {
733
return nil
734
}
735
- return fmt3.Errorf("that == nil && this != nil")
735
+ return fmt.Errorf("that == nil && this != nil")
736
}
737
738
that1, ok := that.(*PBNode)
739
if !ok {
740
- return fmt3.Errorf("that is not of type *PBNode")
740
+ return fmt.Errorf("that is not of type *PBNode")
741
}
742
if that1 == nil {
743
if this == nil {
744
return nil
745
}
746
- return fmt3.Errorf("that is type *PBNode but is nil && this != nil")
746
+ return fmt.Errorf("that is type *PBNode but is nil && this != nil")
747
} else if this == nil {
748
- return fmt3.Errorf("that is type *PBNodebut is not nil && this == nil")
748
+ return fmt.Errorf("that is type *PBNodebut is not nil && this == nil")
749
}
750
if len(this.Links) != len(that1.Links) {
751
- return fmt3.Errorf("Links this(%v) Not Equal that(%v)", len(this.Links), len(that1.Links))
751
+ return fmt.Errorf("Links this(%v) Not Equal that(%v)", len(this.Links), len(that1.Links))
752
}
753
for i := range this.Links {
754
if !this.Links[i].Equal(that1.Links[i]) {
755
- return fmt3.Errorf("Links this[%v](%v) Not Equal that[%v](%v)", i, this.Links[i], i, that1.Links[i])
755
+ return fmt.Errorf("Links this[%v](%v) Not Equal that[%v](%v)", i, this.Links[i], i, that1.Links[i])
756
}
757
}
758
if !bytes.Equal(this.Data, that1.Data) {
759
- return fmt3.Errorf("Data this(%v) Not Equal that(%v)", this.Data, that1.Data)
759
+ return fmt.Errorf("Data this(%v) Not Equal that(%v)", this.Data, that1.Data)
760
}
761
if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) {
762
- return fmt3.Errorf("XXX_unrecognized this(%v) Not Equal that(%v)", this.XXX_unrecognized, that1.XXX_unrecognized)
762
+ return fmt.Errorf("XXX_unrecognized this(%v) Not Equal that(%v)", this.XXX_unrecognized, that1.XXX_unrecognized)
763
}
764
return nil
765
}
merkledag/internal/pb/merkledagpb_test.go
+66
-88
@@ -17,42 +17,20 @@ package merkledag_pb
17
import testing "testing"
18
import math_rand "math/rand"
19
import time "time"
20
-import code_google_com_p_gogoprotobuf_proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
21
-import testing1 "testing"
22
-import math_rand1 "math/rand"
23
-import time1 "time"
20
+import github_com_gogo_protobuf_proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
21
import encoding_json "encoding/json"
25
-import testing2 "testing"
26
-import math_rand2 "math/rand"
27
-import time2 "time"
28
-import code_google_com_p_gogoprotobuf_proto1 "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
29
-import math_rand3 "math/rand"
30
-import time3 "time"
31
-import testing3 "testing"
22
import fmt "fmt"
33
-import math_rand4 "math/rand"
34
-import time4 "time"
35
-import testing4 "testing"
36
-import code_google_com_p_gogoprotobuf_proto2 "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
37
-import math_rand5 "math/rand"
38
-import time5 "time"
39
-import testing5 "testing"
40
-import fmt1 "fmt"
23
import go_parser "go/parser"
42
-import math_rand6 "math/rand"
43
-import time6 "time"
44
-import testing6 "testing"
45
-import code_google_com_p_gogoprotobuf_proto3 "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
24
25
func TestPBLinkProto(t *testing.T) {
26
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
27
p := NewPopulatedPBLink(popr, false)
50
- data, err := code_google_com_p_gogoprotobuf_proto.Marshal(p)
28
+ data, err := github_com_gogo_protobuf_proto.Marshal(p)
29
if err != nil {
30
panic(err)
31
}
32
msg := &PBLink{}
55
- if err := code_google_com_p_gogoprotobuf_proto.Unmarshal(data, msg); err != nil {
33
+ if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
34
panic(err)
35
}
36
for i := range data {
@@ -79,7 +57,7 @@ func TestPBLinkMarshalTo(t *testing.T) {
57
panic(err)
58
}
59
msg := &PBLink{}
82
- if err := code_google_com_p_gogoprotobuf_proto.Unmarshal(data, msg); err != nil {
60
+ if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
61
panic(err)
62
}
63
for i := range data {
@@ -102,7 +80,7 @@ func BenchmarkPBLinkProtoMarshal(b *testing.B) {
80
}
81
b.ResetTimer()
82
for i := 0; i < b.N; i++ {
105
- data, err := code_google_com_p_gogoprotobuf_proto.Marshal(pops[i%10000])
83
+ data, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
84
if err != nil {
85
panic(err)
86
}
@@ -116,7 +94,7 @@ func BenchmarkPBLinkProtoUnmarshal(b *testing.B) {
94
total := 0
95
datas := make([][]byte, 10000)
96
for i := 0; i < 10000; i++ {
119
- data, err := code_google_com_p_gogoprotobuf_proto.Marshal(NewPopulatedPBLink(popr, false))
97
+ data, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedPBLink(popr, false))
98
if err != nil {
99
panic(err)
100
}
@@ -126,7 +104,7 @@ func BenchmarkPBLinkProtoUnmarshal(b *testing.B) {
104
b.ResetTimer()
105
for i := 0; i < b.N; i++ {
106
total += len(datas[i%10000])
129
- if err := code_google_com_p_gogoprotobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
107
+ if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
108
panic(err)
109
}
110
}
@@ -136,12 +114,12 @@ func BenchmarkPBLinkProtoUnmarshal(b *testing.B) {
114
func TestPBNodeProto(t *testing.T) {
115
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
116
p := NewPopulatedPBNode(popr, false)
139
- data, err := code_google_com_p_gogoprotobuf_proto.Marshal(p)
117
+ data, err := github_com_gogo_protobuf_proto.Marshal(p)
118
if err != nil {
119
panic(err)
120
}
121
msg := &PBNode{}
144
- if err := code_google_com_p_gogoprotobuf_proto.Unmarshal(data, msg); err != nil {
122
+ if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
123
panic(err)
124
}
125
for i := range data {
@@ -168,7 +146,7 @@ func TestPBNodeMarshalTo(t *testing.T) {
146
panic(err)
147
}
148
msg := &PBNode{}
171
- if err := code_google_com_p_gogoprotobuf_proto.Unmarshal(data, msg); err != nil {
149
+ if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
150
panic(err)
151
}
152
for i := range data {
@@ -191,7 +169,7 @@ func BenchmarkPBNodeProtoMarshal(b *testing.B) {
169
}
170
b.ResetTimer()
171
for i := 0; i < b.N; i++ {
194
- data, err := code_google_com_p_gogoprotobuf_proto.Marshal(pops[i%10000])
172
+ data, err := github_com_gogo_protobuf_proto.Marshal(pops[i%10000])
173
if err != nil {
174
panic(err)
175
}
@@ -205,7 +183,7 @@ func BenchmarkPBNodeProtoUnmarshal(b *testing.B) {
183
total := 0
184
datas := make([][]byte, 10000)
185
for i := 0; i < 10000; i++ {
208
- data, err := code_google_com_p_gogoprotobuf_proto.Marshal(NewPopulatedPBNode(popr, false))
186
+ data, err := github_com_gogo_protobuf_proto.Marshal(NewPopulatedPBNode(popr, false))
187
if err != nil {
188
panic(err)
189
}
@@ -215,15 +193,15 @@ func BenchmarkPBNodeProtoUnmarshal(b *testing.B) {
193
b.ResetTimer()
194
for i := 0; i < b.N; i++ {
195
total += len(datas[i%10000])
218
- if err := code_google_com_p_gogoprotobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
196
+ if err := github_com_gogo_protobuf_proto.Unmarshal(datas[i%10000], msg); err != nil {
197
panic(err)
198
}
199
}
200
b.SetBytes(int64(total / b.N))
201
}
202
225
-func TestPBLinkJSON(t *testing1.T) {
226
- popr := math_rand1.New(math_rand1.NewSource(time1.Now().UnixNano()))
203
+func TestPBLinkJSON(t *testing.T) {
204
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
205
p := NewPopulatedPBLink(popr, true)
206
jsondata, err := encoding_json.Marshal(p)
207
if err != nil {
@@ -241,8 +219,8 @@ func TestPBLinkJSON(t *testing1.T) {
219
t.Fatalf("%#v !Json Equal %#v", msg, p)
220
}
221
}
244
-func TestPBNodeJSON(t *testing1.T) {
245
- popr := math_rand1.New(math_rand1.NewSource(time1.Now().UnixNano()))
222
+func TestPBNodeJSON(t *testing.T) {
223
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
224
p := NewPopulatedPBNode(popr, true)
225
jsondata, err := encoding_json.Marshal(p)
226
if err != nil {
@@ -260,12 +238,12 @@ func TestPBNodeJSON(t *testing1.T) {
238
t.Fatalf("%#v !Json Equal %#v", msg, p)
239
}
240
}
263
-func TestPBLinkProtoText(t *testing2.T) {
264
- popr := math_rand2.New(math_rand2.NewSource(time2.Now().UnixNano()))
241
+func TestPBLinkProtoText(t *testing.T) {
242
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
243
p := NewPopulatedPBLink(popr, true)
266
- data := code_google_com_p_gogoprotobuf_proto1.MarshalTextString(p)
244
+ data := github_com_gogo_protobuf_proto.MarshalTextString(p)
245
msg := &PBLink{}
268
- if err := code_google_com_p_gogoprotobuf_proto1.UnmarshalText(data, msg); err != nil {
246
+ if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
247
panic(err)
248
}
249
if err := p.VerboseEqual(msg); err != nil {
@@ -276,12 +254,12 @@ func TestPBLinkProtoText(t *testing2.T) {
254
}
255
}
256
279
-func TestPBLinkProtoCompactText(t *testing2.T) {
280
- popr := math_rand2.New(math_rand2.NewSource(time2.Now().UnixNano()))
257
+func TestPBLinkProtoCompactText(t *testing.T) {
258
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
259
p := NewPopulatedPBLink(popr, true)
282
- data := code_google_com_p_gogoprotobuf_proto1.CompactTextString(p)
260
+ data := github_com_gogo_protobuf_proto.CompactTextString(p)
261
msg := &PBLink{}
284
- if err := code_google_com_p_gogoprotobuf_proto1.UnmarshalText(data, msg); err != nil {
262
+ if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
263
panic(err)
264
}
265
if err := p.VerboseEqual(msg); err != nil {
@@ -292,12 +270,12 @@ func TestPBLinkProtoCompactText(t *testing2.T) {
270
}
271
}
272
295
-func TestPBNodeProtoText(t *testing2.T) {
296
- popr := math_rand2.New(math_rand2.NewSource(time2.Now().UnixNano()))
273
+func TestPBNodeProtoText(t *testing.T) {
274
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
275
p := NewPopulatedPBNode(popr, true)
298
- data := code_google_com_p_gogoprotobuf_proto1.MarshalTextString(p)
276
+ data := github_com_gogo_protobuf_proto.MarshalTextString(p)
277
msg := &PBNode{}
300
- if err := code_google_com_p_gogoprotobuf_proto1.UnmarshalText(data, msg); err != nil {
278
+ if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
279
panic(err)
280
}
281
if err := p.VerboseEqual(msg); err != nil {
@@ -308,12 +286,12 @@ func TestPBNodeProtoText(t *testing2.T) {
286
}
287
}
288
311
-func TestPBNodeProtoCompactText(t *testing2.T) {
312
- popr := math_rand2.New(math_rand2.NewSource(time2.Now().UnixNano()))
289
+func TestPBNodeProtoCompactText(t *testing.T) {
290
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
291
p := NewPopulatedPBNode(popr, true)
314
- data := code_google_com_p_gogoprotobuf_proto1.CompactTextString(p)
292
+ data := github_com_gogo_protobuf_proto.CompactTextString(p)
293
msg := &PBNode{}
316
- if err := code_google_com_p_gogoprotobuf_proto1.UnmarshalText(data, msg); err != nil {
294
+ if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
295
panic(err)
296
}
297
if err := p.VerboseEqual(msg); err != nil {
@@ -324,8 +302,8 @@ func TestPBNodeProtoCompactText(t *testing2.T) {
302
}
303
}
304
327
-func TestPBLinkStringer(t *testing3.T) {
328
- popr := math_rand3.New(math_rand3.NewSource(time3.Now().UnixNano()))
305
+func TestPBLinkStringer(t *testing.T) {
306
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
307
p := NewPopulatedPBLink(popr, false)
308
s1 := p.String()
309
s2 := fmt.Sprintf("%v", p)
@@ -333,8 +311,8 @@ func TestPBLinkStringer(t *testing3.T) {
311
t.Fatalf("String want %v got %v", s1, s2)
312
}
313
}
336
-func TestPBNodeStringer(t *testing3.T) {
337
- popr := math_rand3.New(math_rand3.NewSource(time3.Now().UnixNano()))
314
+func TestPBNodeStringer(t *testing.T) {
315
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
316
p := NewPopulatedPBNode(popr, false)
317
s1 := p.String()
318
s2 := fmt.Sprintf("%v", p)
@@ -342,11 +320,11 @@ func TestPBNodeStringer(t *testing3.T) {
320
t.Fatalf("String want %v got %v", s1, s2)
321
}
322
}
345
-func TestPBLinkSize(t *testing4.T) {
346
- popr := math_rand4.New(math_rand4.NewSource(time4.Now().UnixNano()))
323
+func TestPBLinkSize(t *testing.T) {
324
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
325
p := NewPopulatedPBLink(popr, true)
348
- size2 := code_google_com_p_gogoprotobuf_proto2.Size(p)
349
- data, err := code_google_com_p_gogoprotobuf_proto2.Marshal(p)
326
+ size2 := github_com_gogo_protobuf_proto.Size(p)
327
+ data, err := github_com_gogo_protobuf_proto.Marshal(p)
328
if err != nil {
329
panic(err)
330
}
@@ -357,14 +335,14 @@ func TestPBLinkSize(t *testing4.T) {
335
if size2 != size {
336
t.Fatalf("size %v != before marshal proto.Size %v", size, size2)
337
}
360
- size3 := code_google_com_p_gogoprotobuf_proto2.Size(p)
338
+ size3 := github_com_gogo_protobuf_proto.Size(p)
339
if size3 != size {
340
t.Fatalf("size %v != after marshal proto.Size %v", size, size3)
341
}
342
}
343
366
-func BenchmarkPBLinkSize(b *testing4.B) {
367
- popr := math_rand4.New(math_rand4.NewSource(616))
344
+func BenchmarkPBLinkSize(b *testing.B) {
345
+ popr := math_rand.New(math_rand.NewSource(616))
346
total := 0
347
pops := make([]*PBLink, 1000)
348
for i := 0; i < 1000; i++ {
@@ -377,11 +355,11 @@ func BenchmarkPBLinkSize(b *testing4.B) {
355
b.SetBytes(int64(total / b.N))
356
}
357
380
-func TestPBNodeSize(t *testing4.T) {
381
- popr := math_rand4.New(math_rand4.NewSource(time4.Now().UnixNano()))
358
+func TestPBNodeSize(t *testing.T) {
359
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
360
p := NewPopulatedPBNode(popr, true)
383
- size2 := code_google_com_p_gogoprotobuf_proto2.Size(p)
384
- data, err := code_google_com_p_gogoprotobuf_proto2.Marshal(p)
361
+ size2 := github_com_gogo_protobuf_proto.Size(p)
362
+ data, err := github_com_gogo_protobuf_proto.Marshal(p)
363
if err != nil {
364
panic(err)
365
}
@@ -392,14 +370,14 @@ func TestPBNodeSize(t *testing4.T) {
370
if size2 != size {
371
t.Fatalf("size %v != before marshal proto.Size %v", size, size2)
372
}
395
- size3 := code_google_com_p_gogoprotobuf_proto2.Size(p)
373
+ size3 := github_com_gogo_protobuf_proto.Size(p)
374
if size3 != size {
375
t.Fatalf("size %v != after marshal proto.Size %v", size, size3)
376
}
377
}
378
401
-func BenchmarkPBNodeSize(b *testing4.B) {
402
- popr := math_rand4.New(math_rand4.NewSource(616))
379
+func BenchmarkPBNodeSize(b *testing.B) {
380
+ popr := math_rand.New(math_rand.NewSource(616))
381
total := 0
382
pops := make([]*PBNode, 1000)
383
for i := 0; i < 1000; i++ {
@@ -412,11 +390,11 @@ func BenchmarkPBNodeSize(b *testing4.B) {
390
b.SetBytes(int64(total / b.N))
391
}
392
415
-func TestPBLinkGoString(t *testing5.T) {
416
- popr := math_rand5.New(math_rand5.NewSource(time5.Now().UnixNano()))
393
+func TestPBLinkGoString(t *testing.T) {
394
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
395
p := NewPopulatedPBLink(popr, false)
396
s1 := p.GoString()
419
- s2 := fmt1.Sprintf("%#v", p)
397
+ s2 := fmt.Sprintf("%#v", p)
398
if s1 != s2 {
399
t.Fatalf("GoString want %v got %v", s1, s2)
400
}
@@ -425,11 +403,11 @@ func TestPBLinkGoString(t *testing5.T) {
403
panic(err)
404
}
405
}
428
-func TestPBNodeGoString(t *testing5.T) {
429
- popr := math_rand5.New(math_rand5.NewSource(time5.Now().UnixNano()))
406
+func TestPBNodeGoString(t *testing.T) {
407
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
408
p := NewPopulatedPBNode(popr, false)
409
s1 := p.GoString()
432
- s2 := fmt1.Sprintf("%#v", p)
410
+ s2 := fmt.Sprintf("%#v", p)
411
if s1 != s2 {
412
t.Fatalf("GoString want %v got %v", s1, s2)
413
}
@@ -438,30 +416,30 @@ func TestPBNodeGoString(t *testing5.T) {
416
panic(err)
417
}
418
}
441
-func TestPBLinkVerboseEqual(t *testing6.T) {
442
- popr := math_rand6.New(math_rand6.NewSource(time6.Now().UnixNano()))
419
+func TestPBLinkVerboseEqual(t *testing.T) {
420
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
421
p := NewPopulatedPBLink(popr, false)
444
- data, err := code_google_com_p_gogoprotobuf_proto3.Marshal(p)
422
+ data, err := github_com_gogo_protobuf_proto.Marshal(p)
423
if err != nil {
424
panic(err)
425
}
426
msg := &PBLink{}
449
- if err := code_google_com_p_gogoprotobuf_proto3.Unmarshal(data, msg); err != nil {
427
+ if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
428
panic(err)
429
}
430
if err := p.VerboseEqual(msg); err != nil {
431
t.Fatalf("%#v !VerboseEqual %#v, since %v", msg, p, err)
432
}
433
}
456
-func TestPBNodeVerboseEqual(t *testing6.T) {
457
- popr := math_rand6.New(math_rand6.NewSource(time6.Now().UnixNano()))
434
+func TestPBNodeVerboseEqual(t *testing.T) {
435
+ popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
436
p := NewPopulatedPBNode(popr, false)
459
- data, err := code_google_com_p_gogoprotobuf_proto3.Marshal(p)
437
+ data, err := github_com_gogo_protobuf_proto.Marshal(p)
438
if err != nil {
439
panic(err)
440
}
441
msg := &PBNode{}
464
- if err := code_google_com_p_gogoprotobuf_proto3.Unmarshal(data, msg); err != nil {
442
+ if err := github_com_gogo_protobuf_proto.Unmarshal(data, msg); err != nil {
443
panic(err)
444
}
445
if err := p.VerboseEqual(msg); err != nil {
@@ -469,4 +447,4 @@ func TestPBNodeVerboseEqual(t *testing6.T) {
447
}
448
}
449
472
-//These tests are generated by code.google.com/p/gogoprotobuf/plugin/testgen
450
+//These tests are generated by github.com/gogo/protobuf/plugin/testgen
namesys/internal/pb/namesys.pb.go
+1
-1
@@ -13,7 +13,7 @@ It has these top-level messages:
13
*/
14
package namesys_pb
15
16
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
16
+import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
17
import math "math"
18
19
// Reference imports to suppress errors if they are not otherwise used.
namesys/publisher.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
"fmt"
7
"time"
8
9
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
9
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
10
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
11
12
dag "github.com/ipfs/go-ipfs/merkledag"
namesys/routing.go
+2
-1
@@ -3,9 +3,10 @@ package namesys
3
import (
4
"fmt"
5
6
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
6
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
7
mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
8
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
9
+
10
pb "github.com/ipfs/go-ipfs/namesys/internal/pb"
11
path "github.com/ipfs/go-ipfs/path"
12
routing "github.com/ipfs/go-ipfs/routing"
p2p/crypto/internal/pb/crypto.pb.go
+1
-1
@@ -14,7 +14,7 @@ It has these top-level messages:
14
*/
15
package crypto_pb
16
17
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
17
+import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
18
import math "math"
19
20
// Reference imports to suppress errors if they are not otherwise used.
p2p/crypto/key.go
+1
-1
@@ -19,7 +19,7 @@ import (
19
"crypto/sha512"
20
"hash"
21
22
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
22
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
23
24
pb "github.com/ipfs/go-ipfs/p2p/crypto/internal/pb"
25
u "github.com/ipfs/go-ipfs/util"
p2p/crypto/rsa.go
+1
-1
@@ -8,7 +8,7 @@ import (
8
"crypto/x509"
9
"errors"
10
11
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
11
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
12
13
pb "github.com/ipfs/go-ipfs/p2p/crypto/internal/pb"
14
)
p2p/crypto/secio/internal/pb/spipe.pb.go
+2
-4
@@ -14,13 +14,11 @@ It has these top-level messages:
14
*/
15
package spipe_pb
16
17
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
18
-import json "encoding/json"
17
+import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
18
import math "math"
19
21
-// Reference proto, json, and math imports to suppress error if they are not otherwise used.
20
+// Reference imports to suppress errors if they are not otherwise used.
21
var _ = proto.Marshal
23
-var _ = &json.SyntaxError{}
22
var _ = math.Inf
23
24
type Propose struct {
p2p/crypto/secio/rw.go
+1
-1
@@ -9,7 +9,7 @@ import (
9
10
"crypto/hmac"
11
12
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
12
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
13
msgio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-msgio"
14
mpool "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-msgio/mpool"
15
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
p2p/protocol/identify/id.go
+1
-1
@@ -4,8 +4,8 @@ import (
4
"strings"
5
"sync"
6
7
- ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/io"
7
semver "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
8
+ ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
9
ma "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
10
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
11
p2p/protocol/identify/pb/identify.pb.go
+2
-4
@@ -13,13 +13,11 @@ It has these top-level messages:
13
*/
14
package identify_pb
15
16
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
17
-import json "encoding/json"
16
+import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
17
import math "math"
18
20
-// Reference proto, json, and math imports to suppress error if they are not otherwise used.
19
+// Reference imports to suppress errors if they are not otherwise used.
20
var _ = proto.Marshal
22
-var _ = &json.SyntaxError{}
21
var _ = math.Inf
22
23
type Identify struct {
routing/dht/dht.go
+1
-1
@@ -21,7 +21,7 @@ import (
21
"github.com/ipfs/go-ipfs/thirdparty/eventlog"
22
u "github.com/ipfs/go-ipfs/util"
23
24
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
24
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
25
ctxgroup "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-ctxgroup"
26
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
27
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
routing/dht/dht_net.go
+1
-1
@@ -9,7 +9,7 @@ import (
9
pb "github.com/ipfs/go-ipfs/routing/dht/pb"
10
ctxutil "github.com/ipfs/go-ipfs/util/ctx"
11
12
- ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/io"
12
+ ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
13
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
14
)
15
routing/dht/ext_test.go
+5
-5
@@ -7,6 +7,11 @@ import (
7
"testing"
8
"time"
9
10
+ ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
11
+ ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
12
+ dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
13
+ context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
14
+
15
inet "github.com/ipfs/go-ipfs/p2p/net"
16
mocknet "github.com/ipfs/go-ipfs/p2p/net/mock"
17
peer "github.com/ipfs/go-ipfs/p2p/peer"
@@ -14,11 +19,6 @@ import (
19
pb "github.com/ipfs/go-ipfs/routing/dht/pb"
20
record "github.com/ipfs/go-ipfs/routing/record"
21
u "github.com/ipfs/go-ipfs/util"
17
-
18
- ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/io"
19
- ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
20
- dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
21
- context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
22
)
23
24
func TestGetFailures(t *testing.T) {
routing/dht/handlers.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"errors"
5
"fmt"
6
7
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
7
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
8
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
9
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
10
peer "github.com/ipfs/go-ipfs/p2p/peer"
routing/dht/pb/dht.pb.go
+2
-4
@@ -14,13 +14,11 @@ It has these top-level messages:
14
*/
15
package dht_pb
16
17
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
18
-import json "encoding/json"
17
+import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
18
import math "math"
19
21
-// Reference proto, json, and math imports to suppress error if they are not otherwise used.
20
+// Reference imports to suppress errors if they are not otherwise used.
21
var _ = proto.Marshal
23
-var _ = &json.SyntaxError{}
22
var _ = math.Inf
23
24
type Message_MessageType int32
routing/offline/offline.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"errors"
5
"time"
6
7
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
7
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
8
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
9
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
10
ci "github.com/ipfs/go-ipfs/p2p/crypto"
routing/record/record.go
+1
-1
@@ -3,7 +3,7 @@ package record
3
import (
4
"bytes"
5
6
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
6
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
7
8
ci "github.com/ipfs/go-ipfs/p2p/crypto"
9
pb "github.com/ipfs/go-ipfs/routing/dht/pb"
routing/supernode/client.go
+2
-1
@@ -5,8 +5,9 @@ import (
5
"errors"
6
"time"
7
8
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
8
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
9
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
10
+
11
"github.com/ipfs/go-ipfs/p2p/host"
12
peer "github.com/ipfs/go-ipfs/p2p/peer"
13
routing "github.com/ipfs/go-ipfs/routing"
routing/supernode/proxy/loopback.go
+2
-1
@@ -1,8 +1,9 @@
1
package proxy
2
3
import (
4
- ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/io"
4
+ ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
5
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
6
+
7
inet "github.com/ipfs/go-ipfs/p2p/net"
8
peer "github.com/ipfs/go-ipfs/p2p/peer"
9
dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb"
routing/supernode/proxy/standard.go
+3
-2
@@ -3,15 +3,16 @@ package proxy
3
import (
4
"errors"
5
6
- ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/io"
6
+ ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
7
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
8
+
9
host "github.com/ipfs/go-ipfs/p2p/host"
10
inet "github.com/ipfs/go-ipfs/p2p/net"
11
peer "github.com/ipfs/go-ipfs/p2p/peer"
12
dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb"
13
kbucket "github.com/ipfs/go-ipfs/routing/kbucket"
14
eventlog "github.com/ipfs/go-ipfs/thirdparty/eventlog"
14
- "github.com/ipfs/go-ipfs/util"
15
+ util "github.com/ipfs/go-ipfs/util"
16
)
17
18
const ProtocolSNR = "/ipfs/supernoderouting"
routing/supernode/server.go
+2
-1
@@ -4,9 +4,10 @@ import (
4
"errors"
5
"fmt"
6
7
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
7
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
8
datastore "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
9
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
10
+
11
peer "github.com/ipfs/go-ipfs/p2p/peer"
12
dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb"
13
record "github.com/ipfs/go-ipfs/routing/record"
unixfs/format.go
+1
-1
@@ -5,7 +5,7 @@ package unixfs
5
import (
6
"errors"
7
8
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
8
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
9
pb "github.com/ipfs/go-ipfs/unixfs/pb"
10
)
11
unixfs/format_test.go
+2
-1
@@ -3,7 +3,8 @@ package unixfs
3
import (
4
"testing"
5
6
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
6
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
7
+
8
pb "github.com/ipfs/go-ipfs/unixfs/pb"
9
)
10
unixfs/io/dagreader.go
+2
-1
@@ -7,8 +7,9 @@ import (
7
"io"
8
"os"
9
10
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
10
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
11
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
12
+
13
mdag "github.com/ipfs/go-ipfs/merkledag"
14
ft "github.com/ipfs/go-ipfs/unixfs"
15
ftpb "github.com/ipfs/go-ipfs/unixfs/pb"
unixfs/mod/dagmodifier.go
+1
-1
@@ -7,7 +7,7 @@ import (
7
"os"
8
"time"
9
10
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
10
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
11
mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
12
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
13
unixfs/pb/unixfs.pb.go
+1
-1
@@ -14,7 +14,7 @@ It has these top-level messages:
14
*/
15
package unixfs_pb
16
17
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/gogoprotobuf/proto"
17
+import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
18
import math "math"
19
20
// Reference imports to suppress errors if they are not otherwise used.
unixfs/tar/reader.go
+2
-2
@@ -8,13 +8,13 @@ import (
8
gopath "path"
9
"time"
10
11
+ proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
12
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
13
+
14
mdag "github.com/ipfs/go-ipfs/merkledag"
15
path "github.com/ipfs/go-ipfs/path"
16
uio "github.com/ipfs/go-ipfs/unixfs/io"
17
upb "github.com/ipfs/go-ipfs/unixfs/pb"
16
-
17
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
18
)
19
20
type Reader struct {