remove gogo-protobuf from godeps, use gx vendored
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Feb 9, 2016 at 10:07 UTC
171952b795b6373a9b9e9c0eb18bc72add290d4c
74 files changed
+41
-16673
Godeps/_workspace/src/github.com/gogo/protobuf/io/full.go
deleted
-96
@@ -1,96 +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://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
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
-//
17
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
-
29
-package io
30
-
31
-import (
32
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
33
- "io"
34
-)
35
-
36
-func NewFullWriter(w io.Writer) WriteCloser {
37
- return &fullWriter{w, nil}
38
-}
39
-
40
-type fullWriter struct {
41
- w io.Writer
42
- buffer []byte
43
-}
44
-
45
-func (this *fullWriter) WriteMsg(msg proto.Message) (err error) {
46
- var data []byte
47
- if m, ok := msg.(marshaler); ok {
48
- n := m.Size()
49
- if n >= len(this.buffer) {
50
- this.buffer = make([]byte, n)
51
- }
52
- _, err = m.MarshalTo(this.buffer)
53
- if err != nil {
54
- return err
55
- }
56
- data = this.buffer[:n]
57
- } else {
58
- data, err = proto.Marshal(msg)
59
- if err != nil {
60
- return err
61
- }
62
- }
63
- _, err = this.w.Write(data)
64
- return err
65
-}
66
-
67
-func (this *fullWriter) Close() error {
68
- if closer, ok := this.w.(io.Closer); ok {
69
- return closer.Close()
70
- }
71
- return nil
72
-}
73
-
74
-type fullReader struct {
75
- r io.Reader
76
- buf []byte
77
-}
78
-
79
-func NewFullReader(r io.Reader, maxSize int) ReadCloser {
80
- return &fullReader{r, make([]byte, maxSize)}
81
-}
82
-
83
-func (this *fullReader) ReadMsg(msg proto.Message) error {
84
- length, err := this.r.Read(this.buf)
85
- if err != nil {
86
- return err
87
- }
88
- return proto.Unmarshal(this.buf[:length], msg)
89
-}
90
-
91
-func (this *fullReader) Close() error {
92
- if closer, ok := this.r.(io.Closer); ok {
93
- return closer.Close()
94
- }
95
- return nil
96
-}
Godeps/_workspace/src/github.com/gogo/protobuf/io/io.go
deleted
-57
@@ -1,57 +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://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
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
-//
17
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
-
29
-package io
30
-
31
-import (
32
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
33
- "io"
34
-)
35
-
36
-type Writer interface {
37
- WriteMsg(proto.Message) error
38
-}
39
-
40
-type WriteCloser interface {
41
- Writer
42
- io.Closer
43
-}
44
-
45
-type Reader interface {
46
- ReadMsg(msg proto.Message) error
47
-}
48
-
49
-type ReadCloser interface {
50
- Reader
51
- io.Closer
52
-}
53
-
54
-type marshaler interface {
55
- MarshalTo(data []byte) (n int, err error)
56
- Size() (n int)
57
-}
Godeps/_workspace/src/github.com/gogo/protobuf/io/io_test.go
deleted
-221
@@ -1,221 +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://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
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
-//
17
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
-
29
-package io_test
30
-
31
-import (
32
- "bytes"
33
- "encoding/binary"
34
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
35
- "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/test"
36
- goio "io"
37
- "math/rand"
38
- "testing"
39
- "time"
40
-)
41
-
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 {
58
- return err
59
- }
60
- }
61
- if err := writer.Close(); err != nil {
62
- return err
63
- }
64
- i := 0
65
- for {
66
- msg := &test.NinOptNative{}
67
- if err := reader.ReadMsg(msg); err != nil {
68
- if err == goio.EOF {
69
- break
70
- }
71
- return err
72
- }
73
- if err := msg.VerboseEqual(msgs[i]); err != nil {
74
- return err
75
- }
76
- i++
77
- }
78
- if i != size {
79
- panic("not enough messages read")
80
- }
81
- if err := reader.Close(); err != nil {
82
- return err
83
- }
84
- return nil
85
-}
86
-
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)
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
-
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)
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
-
159
-func TestVarintNoClose(t *testing.T) {
160
- buf := bytes.NewBuffer(nil)
161
- writer := io.NewDelimitedWriter(buf)
162
- reader := io.NewDelimitedReader(buf, 1024*1024)
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) {
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{}
185
- err := reader.ReadMsg(msg)
186
- if err == nil {
187
- t.Fatalf("Expected error")
188
- }
189
-}
190
-
191
-func TestFull(t *testing.T) {
192
- buf := newBuffer()
193
- writer := io.NewFullWriter(buf)
194
- reader := io.NewFullReader(buf, 1024*1024)
195
- r := rand.New(rand.NewSource(time.Now().UnixNano()))
196
- msgIn := test.NewPopulatedNinOptNative(r, true)
197
- if err := writer.WriteMsg(msgIn); err != nil {
198
- panic(err)
199
- }
200
- if err := writer.Close(); err != nil {
201
- panic(err)
202
- }
203
- msgOut := &test.NinOptNative{}
204
- if err := reader.ReadMsg(msgOut); err != nil {
205
- panic(err)
206
- }
207
- if err := msgIn.VerboseEqual(msgOut); err != nil {
208
- panic(err)
209
- }
210
- if err := reader.ReadMsg(msgOut); err != nil {
211
- if err != goio.EOF {
212
- panic(err)
213
- }
214
- }
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
deleted
-120
@@ -1,120 +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://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
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
-//
17
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
-
29
-package io
30
-
31
-import (
32
- "encoding/binary"
33
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
34
- "io"
35
-)
36
-
37
-func NewUint32DelimitedWriter(w io.Writer, byteOrder binary.ByteOrder) WriteCloser {
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
48
- buffer []byte
49
-}
50
-
51
-func (this *uint32Writer) WriteMsg(msg proto.Message) (err error) {
52
- var data []byte
53
- if m, ok := msg.(marshaler); ok {
54
- n := m.Size()
55
- if n >= len(this.buffer) {
56
- this.buffer = make([]byte, n)
57
- }
58
- _, err = m.MarshalTo(this.buffer)
59
- if err != nil {
60
- return err
61
- }
62
- data = this.buffer[:n]
63
- } else {
64
- data, err = proto.Marshal(msg)
65
- if err != nil {
66
- return err
67
- }
68
- }
69
- length := uint32(len(data))
70
- if err := binary.Write(this.w, this.byteOrder, &length); err != nil {
71
- return err
72
- }
73
- _, err = this.w.Write(data)
74
- return err
75
-}
76
-
77
-func (this *uint32Writer) Close() error {
78
- if closer, ok := this.w.(io.Closer); ok {
79
- return closer.Close()
80
- }
81
- return nil
82
-}
83
-
84
-type uint32Reader struct {
85
- r io.Reader
86
- byteOrder binary.ByteOrder
87
- lenBuf []byte
88
- buf []byte
89
- maxSize int
90
-}
91
-
92
-func NewUint32DelimitedReader(r io.Reader, byteOrder binary.ByteOrder, maxSize int) ReadCloser {
93
- return &uint32Reader{r, byteOrder, make([]byte, 4), nil, maxSize}
94
-}
95
-
96
-func (this *uint32Reader) ReadMsg(msg proto.Message) error {
97
- if _, err := io.ReadFull(this.r, this.lenBuf); err != nil {
98
- return err
99
- }
100
- length32 := this.byteOrder.Uint32(this.lenBuf)
101
- length := int(length32)
102
- if length < 0 || length > this.maxSize {
103
- return io.ErrShortBuffer
104
- }
105
- if length >= len(this.buf) {
106
- this.buf = make([]byte, length)
107
- }
108
- _, err := io.ReadFull(this.r, this.buf[:length])
109
- if err != nil {
110
- return err
111
- }
112
- return proto.Unmarshal(this.buf[:length], msg)
113
-}
114
-
115
-func (this *uint32Reader) Close() error {
116
- if closer, ok := this.r.(io.Closer); ok {
117
- return closer.Close()
118
- }
119
- return nil
120
-}
Godeps/_workspace/src/github.com/gogo/protobuf/io/varint.go
deleted
-128
@@ -1,128 +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://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
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
-//
17
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
-
29
-package io
30
-
31
-import (
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
-
39
-var (
40
- errSmallBuffer = errors.New("Buffer Too Small")
41
- errLargeValue = errors.New("Value is Larger than 64 bits")
42
-)
43
-
44
-func NewDelimitedWriter(w io.Writer) WriteCloser {
45
- return &varintWriter{w, make([]byte, 10), nil}
46
-}
47
-
48
-type varintWriter struct {
49
- w io.Writer
50
- lenBuf []byte
51
- buffer []byte
52
-}
53
-
54
-func (this *varintWriter) WriteMsg(msg proto.Message) (err error) {
55
- var data []byte
56
- if m, ok := msg.(marshaler); ok {
57
- n := m.Size()
58
- if n >= len(this.buffer) {
59
- this.buffer = make([]byte, n)
60
- }
61
- _, err = m.MarshalTo(this.buffer)
62
- if err != nil {
63
- return err
64
- }
65
- data = this.buffer[:n]
66
- } else {
67
- data, err = proto.Marshal(msg)
68
- if err != nil {
69
- return err
70
- }
71
- }
72
- length := uint64(len(data))
73
- n := binary.PutUvarint(this.lenBuf, length)
74
- _, err = this.w.Write(this.lenBuf[:n])
75
- if err != nil {
76
- return err
77
- }
78
- _, err = this.w.Write(data)
79
- return err
80
-}
81
-
82
-func (this *varintWriter) Close() error {
83
- if closer, ok := this.w.(io.Closer); ok {
84
- return closer.Close()
85
- }
86
- return nil
87
-}
88
-
89
-func NewDelimitedReader(r io.Reader, maxSize int) ReadCloser {
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 {
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 {
105
- length64, err := binary.ReadUvarint(this.r)
106
- if err != nil {
107
- return err
108
- }
109
- length := int(length64)
110
- if length < 0 || length > this.maxSize {
111
- return io.ErrShortBuffer
112
- }
113
- if len(this.buf) < length {
114
- this.buf = make([]byte, length)
115
- }
116
- buf := this.buf[:length]
117
- if _, err := io.ReadFull(this.r, buf); err != nil {
118
- return err
119
- }
120
- return proto.Unmarshal(buf, msg)
121
-}
122
-
123
-func (this *varintReader) Close() error {
124
- if this.closer != nil {
125
- return this.closer.Close()
126
- }
127
- return nil
128
-}
Godeps/_workspace/src/github.com/gogo/protobuf/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
-# 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
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/github.com/gogo/protobuf/proto/all_test.go
deleted
-1979
@@ -1,1979 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
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
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/github.com/gogo/protobuf/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 an int32 field can be upgraded to an int64 field.
1051
-func TestNegativeInt32(t *testing.T) {
1052
- om := &OldMessage{
1053
- Num: Int32(-1),
1054
- }
1055
- b, err := Marshal(om)
1056
- if err != nil {
1057
- t.Fatalf("Marshal of OldMessage: %v", err)
1058
- }
1059
-
1060
- // Check the size. It should be 11 bytes;
1061
- // 1 for the field/wire type, and 10 for the negative number.
1062
- if len(b) != 11 {
1063
- t.Errorf("%v marshaled as %q, wanted 11 bytes", om, b)
1064
- }
1065
-
1066
- // Unmarshal into a NewMessage.
1067
- nm := new(NewMessage)
1068
- if err := Unmarshal(b, nm); err != nil {
1069
- t.Fatalf("Unmarshal to NewMessage: %v", err)
1070
- }
1071
- want := &NewMessage{
1072
- Num: Int64(-1),
1073
- }
1074
- if !Equal(nm, want) {
1075
- t.Errorf("nm = %v, want %v", nm, want)
1076
- }
1077
-}
1078
-
1079
-// Check that we can grow an array (repeated field) to have many elements.
1080
-// This test doesn't depend only on our encoding; for variety, it makes sure
1081
-// we create, encode, and decode the correct contents explicitly. It's therefore
1082
-// a bit messier.
1083
-// This test also uses (and hence tests) the Marshal/Unmarshal functions
1084
-// instead of the methods.
1085
-func TestBigRepeated(t *testing.T) {
1086
- pb := initGoTest(true)
1087
-
1088
- // Create the arrays
1089
- const N = 50 // Internally the library starts much smaller.
1090
- pb.Repeatedgroup = make([]*GoTest_RepeatedGroup, N)
1091
- pb.F_Sint64Repeated = make([]int64, N)
1092
- pb.F_Sint32Repeated = make([]int32, N)
1093
- pb.F_BytesRepeated = make([][]byte, N)
1094
- pb.F_StringRepeated = make([]string, N)
1095
- pb.F_DoubleRepeated = make([]float64, N)
1096
- pb.F_FloatRepeated = make([]float32, N)
1097
- pb.F_Uint64Repeated = make([]uint64, N)
1098
- pb.F_Uint32Repeated = make([]uint32, N)
1099
- pb.F_Fixed64Repeated = make([]uint64, N)
1100
- pb.F_Fixed32Repeated = make([]uint32, N)
1101
- pb.F_Int64Repeated = make([]int64, N)
1102
- pb.F_Int32Repeated = make([]int32, N)
1103
- pb.F_BoolRepeated = make([]bool, N)
1104
- pb.RepeatedField = make([]*GoTestField, N)
1105
-
1106
- // Fill in the arrays with checkable values.
1107
- igtf := initGoTestField()
1108
- igtrg := initGoTest_RepeatedGroup()
1109
- for i := 0; i < N; i++ {
1110
- pb.Repeatedgroup[i] = igtrg
1111
- pb.F_Sint64Repeated[i] = int64(i)
1112
- pb.F_Sint32Repeated[i] = int32(i)
1113
- s := fmt.Sprint(i)
1114
- pb.F_BytesRepeated[i] = []byte(s)
1115
- pb.F_StringRepeated[i] = s
1116
- pb.F_DoubleRepeated[i] = float64(i)
1117
- pb.F_FloatRepeated[i] = float32(i)
1118
- pb.F_Uint64Repeated[i] = uint64(i)
1119
- pb.F_Uint32Repeated[i] = uint32(i)
1120
- pb.F_Fixed64Repeated[i] = uint64(i)
1121
- pb.F_Fixed32Repeated[i] = uint32(i)
1122
- pb.F_Int64Repeated[i] = int64(i)
1123
- pb.F_Int32Repeated[i] = int32(i)
1124
- pb.F_BoolRepeated[i] = i%2 == 0
1125
- pb.RepeatedField[i] = igtf
1126
- }
1127
-
1128
- // Marshal.
1129
- buf, _ := Marshal(pb)
1130
-
1131
- // Now test Unmarshal by recreating the original buffer.
1132
- pbd := new(GoTest)
1133
- Unmarshal(buf, pbd)
1134
-
1135
- // Check the checkable values
1136
- for i := uint64(0); i < N; i++ {
1137
- if pbd.Repeatedgroup[i] == nil { // TODO: more checking?
1138
- t.Error("pbd.Repeatedgroup bad")
1139
- }
1140
- var x uint64
1141
- x = uint64(pbd.F_Sint64Repeated[i])
1142
- if x != i {
1143
- t.Error("pbd.F_Sint64Repeated bad", x, i)
1144
- }
1145
- x = uint64(pbd.F_Sint32Repeated[i])
1146
- if x != i {
1147
- t.Error("pbd.F_Sint32Repeated bad", x, i)
1148
- }
1149
- s := fmt.Sprint(i)
1150
- equalbytes(pbd.F_BytesRepeated[i], []byte(s), t)
1151
- if pbd.F_StringRepeated[i] != s {
1152
- t.Error("pbd.F_Sint32Repeated bad", pbd.F_StringRepeated[i], i)
1153
- }
1154
- x = uint64(pbd.F_DoubleRepeated[i])
1155
- if x != i {
1156
- t.Error("pbd.F_DoubleRepeated bad", x, i)
1157
- }
1158
- x = uint64(pbd.F_FloatRepeated[i])
1159
- if x != i {
1160
- t.Error("pbd.F_FloatRepeated bad", x, i)
1161
- }
1162
- x = pbd.F_Uint64Repeated[i]
1163
- if x != i {
1164
- t.Error("pbd.F_Uint64Repeated bad", x, i)
1165
- }
1166
- x = uint64(pbd.F_Uint32Repeated[i])
1167
- if x != i {
1168
- t.Error("pbd.F_Uint32Repeated bad", x, i)
1169
- }
1170
- x = pbd.F_Fixed64Repeated[i]
1171
- if x != i {
1172
- t.Error("pbd.F_Fixed64Repeated bad", x, i)
1173
- }
1174
- x = uint64(pbd.F_Fixed32Repeated[i])
1175
- if x != i {
1176
- t.Error("pbd.F_Fixed32Repeated bad", x, i)
1177
- }
1178
- x = uint64(pbd.F_Int64Repeated[i])
1179
- if x != i {
1180
- t.Error("pbd.F_Int64Repeated bad", x, i)
1181
- }
1182
- x = uint64(pbd.F_Int32Repeated[i])
1183
- if x != i {
1184
- t.Error("pbd.F_Int32Repeated bad", x, i)
1185
- }
1186
- if pbd.F_BoolRepeated[i] != (i%2 == 0) {
1187
- t.Error("pbd.F_BoolRepeated bad", x, i)
1188
- }
1189
- if pbd.RepeatedField[i] == nil { // TODO: more checking?
1190
- t.Error("pbd.RepeatedField bad")
1191
- }
1192
- }
1193
-}
1194
-
1195
-// Verify we give a useful message when decoding to the wrong structure type.
1196
-func TestTypeMismatch(t *testing.T) {
1197
- pb1 := initGoTest(true)
1198
-
1199
- // Marshal
1200
- o := old()
1201
- o.Marshal(pb1)
1202
-
1203
- // Now Unmarshal it to the wrong type.
1204
- pb2 := initGoTestField()
1205
- err := o.Unmarshal(pb2)
1206
- if err == nil {
1207
- t.Error("expected error, got no error")
1208
- } else if !strings.Contains(err.Error(), "bad wiretype") {
1209
- t.Error("expected bad wiretype error, got", err)
1210
- }
1211
-}
1212
-
1213
-func encodeDecode(t *testing.T, in, out Message, msg string) {
1214
- buf, err := Marshal(in)
1215
- if err != nil {
1216
- t.Fatalf("failed marshaling %v: %v", msg, err)
1217
- }
1218
- if err := Unmarshal(buf, out); err != nil {
1219
- t.Fatalf("failed unmarshaling %v: %v", msg, err)
1220
- }
1221
-}
1222
-
1223
-func TestPackedNonPackedDecoderSwitching(t *testing.T) {
1224
- np, p := new(NonPackedTest), new(PackedTest)
1225
-
1226
- // non-packed -> packed
1227
- np.A = []int32{0, 1, 1, 2, 3, 5}
1228
- encodeDecode(t, np, p, "non-packed -> packed")
1229
- if !reflect.DeepEqual(np.A, p.B) {
1230
- t.Errorf("failed non-packed -> packed; np.A=%+v, p.B=%+v", np.A, p.B)
1231
- }
1232
-
1233
- // packed -> non-packed
1234
- np.Reset()
1235
- p.B = []int32{3, 1, 4, 1, 5, 9}
1236
- encodeDecode(t, p, np, "packed -> non-packed")
1237
- if !reflect.DeepEqual(p.B, np.A) {
1238
- t.Errorf("failed packed -> non-packed; p.B=%+v, np.A=%+v", p.B, np.A)
1239
- }
1240
-}
1241
-
1242
-func TestProto1RepeatedGroup(t *testing.T) {
1243
- pb := &MessageList{
1244
- Message: []*MessageList_Message{
1245
- {
1246
- Name: String("blah"),
1247
- Count: Int32(7),
1248
- },
1249
- // NOTE: pb.Message[1] is a nil
1250
- nil,
1251
- },
1252
- }
1253
-
1254
- o := old()
1255
- if err := o.Marshal(pb); err != ErrRepeatedHasNil {
1256
- t.Fatalf("unexpected or no error when marshaling: %v", err)
1257
- }
1258
-}
1259
-
1260
-// Test that enums work. Checks for a bug introduced by making enums
1261
-// named types instead of int32: newInt32FromUint64 would crash with
1262
-// a type mismatch in reflect.PointTo.
1263
-func TestEnum(t *testing.T) {
1264
- pb := new(GoEnum)
1265
- pb.Foo = FOO_FOO1.Enum()
1266
- o := old()
1267
- if err := o.Marshal(pb); err != nil {
1268
- t.Fatal("error encoding enum:", err)
1269
- }
1270
- pb1 := new(GoEnum)
1271
- if err := o.Unmarshal(pb1); err != nil {
1272
- t.Fatal("error decoding enum:", err)
1273
- }
1274
- if *pb1.Foo != FOO_FOO1 {
1275
- t.Error("expected 7 but got ", *pb1.Foo)
1276
- }
1277
-}
1278
-
1279
-// Enum types have String methods. Check that enum fields can be printed.
1280
-// We don't care what the value actually is, just as long as it doesn't crash.
1281
-func TestPrintingNilEnumFields(t *testing.T) {
1282
- pb := new(GoEnum)
1283
- fmt.Sprintf("%+v", pb)
1284
-}
1285
-
1286
-// Verify that absent required fields cause Marshal/Unmarshal to return errors.
1287
-func TestRequiredFieldEnforcement(t *testing.T) {
1288
- pb := new(GoTestField)
1289
- _, err := Marshal(pb)
1290
- if err == nil {
1291
- t.Error("marshal: expected error, got nil")
1292
- } else if strings.Index(err.Error(), "Label") < 0 {
1293
- t.Errorf("marshal: bad error type: %v", err)
1294
- }
1295
-
1296
- // A slightly sneaky, yet valid, proto. It encodes the same required field twice,
1297
- // so simply counting the required fields is insufficient.
1298
- // field 1, encoding 2, value "hi"
1299
- buf := []byte("\x0A\x02hi\x0A\x02hi")
1300
- err = Unmarshal(buf, pb)
1301
- if err == nil {
1302
- t.Error("unmarshal: expected error, got nil")
1303
- } else if strings.Index(err.Error(), "{Unknown}") < 0 {
1304
- t.Errorf("unmarshal: bad error type: %v", err)
1305
- }
1306
-}
1307
-
1308
-func TestTypedNilMarshal(t *testing.T) {
1309
- // A typed nil should return ErrNil and not crash.
1310
- _, err := Marshal((*GoEnum)(nil))
1311
- if err != ErrNil {
1312
- t.Errorf("Marshal: got err %v, want ErrNil", err)
1313
- }
1314
-}
1315
-
1316
-// A type that implements the Marshaler interface, but is not nillable.
1317
-type nonNillableInt uint64
1318
-
1319
-func (nni nonNillableInt) Marshal() ([]byte, error) {
1320
- return EncodeVarint(uint64(nni)), nil
1321
-}
1322
-
1323
-type NNIMessage struct {
1324
- nni nonNillableInt
1325
-}
1326
-
1327
-func (*NNIMessage) Reset() {}
1328
-func (*NNIMessage) String() string { return "" }
1329
-func (*NNIMessage) ProtoMessage() {}
1330
-
1331
-// A type that implements the Marshaler interface and is nillable.
1332
-type nillableMessage struct {
1333
- x uint64
1334
-}
1335
-
1336
-func (nm *nillableMessage) Marshal() ([]byte, error) {
1337
- return EncodeVarint(nm.x), nil
1338
-}
1339
-
1340
-type NMMessage struct {
1341
- nm *nillableMessage
1342
-}
1343
-
1344
-func (*NMMessage) Reset() {}
1345
-func (*NMMessage) String() string { return "" }
1346
-func (*NMMessage) ProtoMessage() {}
1347
-
1348
-// Verify a type that uses the Marshaler interface, but has a nil pointer.
1349
-func TestNilMarshaler(t *testing.T) {
1350
- // Try a struct with a Marshaler field that is nil.
1351
- // It should be directly marshable.
1352
- nmm := new(NMMessage)
1353
- if _, err := Marshal(nmm); err != nil {
1354
- t.Error("unexpected error marshaling nmm: ", err)
1355
- }
1356
-
1357
- // Try a struct with a Marshaler field that is not nillable.
1358
- nnim := new(NNIMessage)
1359
- nnim.nni = 7
1360
- var _ Marshaler = nnim.nni // verify it is truly a Marshaler
1361
- if _, err := Marshal(nnim); err != nil {
1362
- t.Error("unexpected error marshaling nnim: ", err)
1363
- }
1364
-}
1365
-
1366
-func TestAllSetDefaults(t *testing.T) {
1367
- // Exercise SetDefaults with all scalar field types.
1368
- m := &Defaults{
1369
- // NaN != NaN, so override that here.
1370
- F_Nan: Float32(1.7),
1371
- }
1372
- expected := &Defaults{
1373
- F_Bool: Bool(true),
1374
- F_Int32: Int32(32),
1375
- F_Int64: Int64(64),
1376
- F_Fixed32: Uint32(320),
1377
- F_Fixed64: Uint64(640),
1378
- F_Uint32: Uint32(3200),
1379
- F_Uint64: Uint64(6400),
1380
- F_Float: Float32(314159),
1381
- F_Double: Float64(271828),
1382
- F_String: String(`hello, "world!"` + "\n"),
1383
- F_Bytes: []byte("Bignose"),
1384
- F_Sint32: Int32(-32),
1385
- F_Sint64: Int64(-64),
1386
- F_Enum: Defaults_GREEN.Enum(),
1387
- F_Pinf: Float32(float32(math.Inf(1))),
1388
- F_Ninf: Float32(float32(math.Inf(-1))),
1389
- F_Nan: Float32(1.7),
1390
- StrZero: String(""),
1391
- }
1392
- SetDefaults(m)
1393
- if !Equal(m, expected) {
1394
- t.Errorf("SetDefaults failed\n got %v\nwant %v", m, expected)
1395
- }
1396
-}
1397
-
1398
-func TestSetDefaultsWithSetField(t *testing.T) {
1399
- // Check that a set value is not overridden.
1400
- m := &Defaults{
1401
- F_Int32: Int32(12),
1402
- }
1403
- SetDefaults(m)
1404
- if v := m.GetF_Int32(); v != 12 {
1405
- t.Errorf("m.FInt32 = %v, want 12", v)
1406
- }
1407
-}
1408
-
1409
-func TestSetDefaultsWithSubMessage(t *testing.T) {
1410
- m := &OtherMessage{
1411
- Key: Int64(123),
1412
- Inner: &InnerMessage{
1413
- Host: String("gopher"),
1414
- },
1415
- }
1416
- expected := &OtherMessage{
1417
- Key: Int64(123),
1418
- Inner: &InnerMessage{
1419
- Host: String("gopher"),
1420
- Port: Int32(4000),
1421
- },
1422
- }
1423
- SetDefaults(m)
1424
- if !Equal(m, expected) {
1425
- t.Errorf("\n got %v\nwant %v", m, expected)
1426
- }
1427
-}
1428
-
1429
-func TestSetDefaultsWithRepeatedSubMessage(t *testing.T) {
1430
- m := &MyMessage{
1431
- RepInner: []*InnerMessage{{}},
1432
- }
1433
- expected := &MyMessage{
1434
- RepInner: []*InnerMessage{{
1435
- Port: Int32(4000),
1436
- }},
1437
- }
1438
- SetDefaults(m)
1439
- if !Equal(m, expected) {
1440
- t.Errorf("\n got %v\nwant %v", m, expected)
1441
- }
1442
-}
1443
-
1444
-func TestMaximumTagNumber(t *testing.T) {
1445
- m := &MaxTag{
1446
- LastField: String("natural goat essence"),
1447
- }
1448
- buf, err := Marshal(m)
1449
- if err != nil {
1450
- t.Fatalf("proto.Marshal failed: %v", err)
1451
- }
1452
- m2 := new(MaxTag)
1453
- if err := Unmarshal(buf, m2); err != nil {
1454
- t.Fatalf("proto.Unmarshal failed: %v", err)
1455
- }
1456
- if got, want := m2.GetLastField(), *m.LastField; got != want {
1457
- t.Errorf("got %q, want %q", got, want)
1458
- }
1459
-}
1460
-
1461
-func TestJSON(t *testing.T) {
1462
- m := &MyMessage{
1463
- Count: Int32(4),
1464
- Pet: []string{"bunny", "kitty"},
1465
- Inner: &InnerMessage{
1466
- Host: String("cauchy"),
1467
- },
1468
- Bikeshed: MyMessage_GREEN.Enum(),
1469
- }
1470
- const expected = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":1}`
1471
-
1472
- b, err := json.Marshal(m)
1473
- if err != nil {
1474
- t.Fatalf("json.Marshal failed: %v", err)
1475
- }
1476
- s := string(b)
1477
- if s != expected {
1478
- t.Errorf("got %s\nwant %s", s, expected)
1479
- }
1480
-
1481
- received := new(MyMessage)
1482
- if err := json.Unmarshal(b, received); err != nil {
1483
- t.Fatalf("json.Unmarshal failed: %v", err)
1484
- }
1485
- if !Equal(received, m) {
1486
- t.Fatalf("got %s, want %s", received, m)
1487
- }
1488
-
1489
- // Test unmarshalling of JSON with symbolic enum name.
1490
- const old = `{"count":4,"pet":["bunny","kitty"],"inner":{"host":"cauchy"},"bikeshed":"GREEN"}`
1491
- received.Reset()
1492
- if err := json.Unmarshal([]byte(old), received); err != nil {
1493
- t.Fatalf("json.Unmarshal failed: %v", err)
1494
- }
1495
- if !Equal(received, m) {
1496
- t.Fatalf("got %s, want %s", received, m)
1497
- }
1498
-}
1499
-
1500
-func TestBadWireType(t *testing.T) {
1501
- b := []byte{7<<3 | 6} // field 7, wire type 6
1502
- pb := new(OtherMessage)
1503
- if err := Unmarshal(b, pb); err == nil {
1504
- t.Errorf("Unmarshal did not fail")
1505
- } else if !strings.Contains(err.Error(), "unknown wire type") {
1506
- t.Errorf("wrong error: %v", err)
1507
- }
1508
-}
1509
-
1510
-func TestBytesWithInvalidLength(t *testing.T) {
1511
- // If a byte sequence has an invalid (negative) length, Unmarshal should not panic.
1512
- b := []byte{2<<3 | WireBytes, 0xff, 0xff, 0xff, 0xff, 0xff, 0}
1513
- Unmarshal(b, new(MyMessage))
1514
-}
1515
-
1516
-func TestLengthOverflow(t *testing.T) {
1517
- // Overflowing a length should not panic.
1518
- b := []byte{2<<3 | WireBytes, 1, 1, 3<<3 | WireBytes, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x01}
1519
- Unmarshal(b, new(MyMessage))
1520
-}
1521
-
1522
-func TestVarintOverflow(t *testing.T) {
1523
- // Overflowing a 64-bit length should not be allowed.
1524
- b := []byte{1<<3 | WireVarint, 0x01, 3<<3 | WireBytes, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x01}
1525
- if err := Unmarshal(b, new(MyMessage)); err == nil {
1526
- t.Fatalf("Overflowed uint64 length without error")
1527
- }
1528
-}
1529
-
1530
-func TestUnmarshalFuzz(t *testing.T) {
1531
- const N = 1000
1532
- seed := time.Now().UnixNano()
1533
- t.Logf("RNG seed is %d", seed)
1534
- rng := rand.New(rand.NewSource(seed))
1535
- buf := make([]byte, 20)
1536
- for i := 0; i < N; i++ {
1537
- for j := range buf {
1538
- buf[j] = byte(rng.Intn(256))
1539
- }
1540
- fuzzUnmarshal(t, buf)
1541
- }
1542
-}
1543
-
1544
-func TestMergeMessages(t *testing.T) {
1545
- pb := &MessageList{Message: []*MessageList_Message{{Name: String("x"), Count: Int32(1)}}}
1546
- data, err := Marshal(pb)
1547
- if err != nil {
1548
- t.Fatalf("Marshal: %v", err)
1549
- }
1550
-
1551
- pb1 := new(MessageList)
1552
- if err := Unmarshal(data, pb1); err != nil {
1553
- t.Fatalf("first Unmarshal: %v", err)
1554
- }
1555
- if err := Unmarshal(data, pb1); err != nil {
1556
- t.Fatalf("second Unmarshal: %v", err)
1557
- }
1558
- if len(pb1.Message) != 1 {
1559
- t.Errorf("two Unmarshals produced %d Messages, want 1", len(pb1.Message))
1560
- }
1561
-
1562
- pb2 := new(MessageList)
1563
- if err := UnmarshalMerge(data, pb2); err != nil {
1564
- t.Fatalf("first UnmarshalMerge: %v", err)
1565
- }
1566
- if err := UnmarshalMerge(data, pb2); err != nil {
1567
- t.Fatalf("second UnmarshalMerge: %v", err)
1568
- }
1569
- if len(pb2.Message) != 2 {
1570
- t.Errorf("two UnmarshalMerges produced %d Messages, want 2", len(pb2.Message))
1571
- }
1572
-}
1573
-
1574
-func TestExtensionMarshalOrder(t *testing.T) {
1575
- m := &MyMessage{Count: Int(123)}
1576
- if err := SetExtension(m, E_Ext_More, &Ext{Data: String("alpha")}); err != nil {
1577
- t.Fatalf("SetExtension: %v", err)
1578
- }
1579
- if err := SetExtension(m, E_Ext_Text, String("aleph")); err != nil {
1580
- t.Fatalf("SetExtension: %v", err)
1581
- }
1582
- if err := SetExtension(m, E_Ext_Number, Int32(1)); err != nil {
1583
- t.Fatalf("SetExtension: %v", err)
1584
- }
1585
-
1586
- // Serialize m several times, and check we get the same bytes each time.
1587
- var orig []byte
1588
- for i := 0; i < 100; i++ {
1589
- b, err := Marshal(m)
1590
- if err != nil {
1591
- t.Fatalf("Marshal: %v", err)
1592
- }
1593
- if i == 0 {
1594
- orig = b
1595
- continue
1596
- }
1597
- if !bytes.Equal(b, orig) {
1598
- t.Errorf("Bytes differ on attempt #%d", i)
1599
- }
1600
- }
1601
-}
1602
-
1603
-// Many extensions, because small maps might not iterate differently on each iteration.
1604
-var exts = []*ExtensionDesc{
1605
- E_X201,
1606
- E_X202,
1607
- E_X203,
1608
- E_X204,
1609
- E_X205,
1610
- E_X206,
1611
- E_X207,
1612
- E_X208,
1613
- E_X209,
1614
- E_X210,
1615
- E_X211,
1616
- E_X212,
1617
- E_X213,
1618
- E_X214,
1619
- E_X215,
1620
- E_X216,
1621
- E_X217,
1622
- E_X218,
1623
- E_X219,
1624
- E_X220,
1625
- E_X221,
1626
- E_X222,
1627
- E_X223,
1628
- E_X224,
1629
- E_X225,
1630
- E_X226,
1631
- E_X227,
1632
- E_X228,
1633
- E_X229,
1634
- E_X230,
1635
- E_X231,
1636
- E_X232,
1637
- E_X233,
1638
- E_X234,
1639
- E_X235,
1640
- E_X236,
1641
- E_X237,
1642
- E_X238,
1643
- E_X239,
1644
- E_X240,
1645
- E_X241,
1646
- E_X242,
1647
- E_X243,
1648
- E_X244,
1649
- E_X245,
1650
- E_X246,
1651
- E_X247,
1652
- E_X248,
1653
- E_X249,
1654
- E_X250,
1655
-}
1656
-
1657
-func TestMessageSetMarshalOrder(t *testing.T) {
1658
- m := &MyMessageSet{}
1659
- for _, x := range exts {
1660
- if err := SetExtension(m, x, &Empty{}); err != nil {
1661
- t.Fatalf("SetExtension: %v", err)
1662
- }
1663
- }
1664
-
1665
- buf, err := Marshal(m)
1666
- if err != nil {
1667
- t.Fatalf("Marshal: %v", err)
1668
- }
1669
-
1670
- // Serialize m several times, and check we get the same bytes each time.
1671
- for i := 0; i < 10; i++ {
1672
- b1, err := Marshal(m)
1673
- if err != nil {
1674
- t.Fatalf("Marshal: %v", err)
1675
- }
1676
- if !bytes.Equal(b1, buf) {
1677
- t.Errorf("Bytes differ on re-Marshal #%d", i)
1678
- }
1679
-
1680
- m2 := &MyMessageSet{}
1681
- if err := Unmarshal(buf, m2); err != nil {
1682
- t.Errorf("Unmarshal: %v", err)
1683
- }
1684
- b2, err := Marshal(m2)
1685
- if err != nil {
1686
- t.Errorf("re-Marshal: %v", err)
1687
- }
1688
- if !bytes.Equal(b2, buf) {
1689
- t.Errorf("Bytes differ on round-trip #%d", i)
1690
- }
1691
- }
1692
-}
1693
-
1694
-func TestUnmarshalMergesMessages(t *testing.T) {
1695
- // If a nested message occurs twice in the input,
1696
- // the fields should be merged when decoding.
1697
- a := &OtherMessage{
1698
- Key: Int64(123),
1699
- Inner: &InnerMessage{
1700
- Host: String("polhode"),
1701
- Port: Int32(1234),
1702
- },
1703
- }
1704
- aData, err := Marshal(a)
1705
- if err != nil {
1706
- t.Fatalf("Marshal(a): %v", err)
1707
- }
1708
- b := &OtherMessage{
1709
- Weight: Float32(1.2),
1710
- Inner: &InnerMessage{
1711
- Host: String("herpolhode"),
1712
- Connected: Bool(true),
1713
- },
1714
- }
1715
- bData, err := Marshal(b)
1716
- if err != nil {
1717
- t.Fatalf("Marshal(b): %v", err)
1718
- }
1719
- want := &OtherMessage{
1720
- Key: Int64(123),
1721
- Weight: Float32(1.2),
1722
- Inner: &InnerMessage{
1723
- Host: String("herpolhode"),
1724
- Port: Int32(1234),
1725
- Connected: Bool(true),
1726
- },
1727
- }
1728
- got := new(OtherMessage)
1729
- if err := Unmarshal(append(aData, bData...), got); err != nil {
1730
- t.Fatalf("Unmarshal: %v", err)
1731
- }
1732
- if !Equal(got, want) {
1733
- t.Errorf("\n got %v\nwant %v", got, want)
1734
- }
1735
-}
1736
-
1737
-func TestEncodingSizes(t *testing.T) {
1738
- tests := []struct {
1739
- m Message
1740
- n int
1741
- }{
1742
- {&Defaults{F_Int32: Int32(math.MaxInt32)}, 6},
1743
- {&Defaults{F_Int32: Int32(math.MinInt32)}, 11},
1744
- {&Defaults{F_Uint32: Uint32(uint32(math.MaxInt32) + 1)}, 6},
1745
- {&Defaults{F_Uint32: Uint32(math.MaxUint32)}, 6},
1746
- }
1747
- for _, test := range tests {
1748
- b, err := Marshal(test.m)
1749
- if err != nil {
1750
- t.Errorf("Marshal(%v): %v", test.m, err)
1751
- continue
1752
- }
1753
- if len(b) != test.n {
1754
- t.Errorf("Marshal(%v) yielded %d bytes, want %d bytes", test.m, len(b), test.n)
1755
- }
1756
- }
1757
-}
1758
-
1759
-func TestRequiredNotSetError(t *testing.T) {
1760
- pb := initGoTest(false)
1761
- pb.RequiredField.Label = nil
1762
- pb.F_Int32Required = nil
1763
- pb.F_Int64Required = nil
1764
-
1765
- expected := "0807" + // field 1, encoding 0, value 7
1766
- "2206" + "120474797065" + // field 4, encoding 2 (GoTestField)
1767
- "5001" + // field 10, encoding 0, value 1
1768
- "6d20000000" + // field 13, encoding 5, value 0x20
1769
- "714000000000000000" + // field 14, encoding 1, value 0x40
1770
- "78a019" + // field 15, encoding 0, value 0xca0 = 3232
1771
- "8001c032" + // field 16, encoding 0, value 0x1940 = 6464
1772
- "8d0100004a45" + // field 17, encoding 5, value 3232.0
1773
- "9101000000000040b940" + // field 18, encoding 1, value 6464.0
1774
- "9a0106" + "737472696e67" + // field 19, encoding 2, string "string"
1775
- "b304" + // field 70, encoding 3, start group
1776
- "ba0408" + "7265717569726564" + // field 71, encoding 2, string "required"
1777
- "b404" + // field 70, encoding 4, end group
1778
- "aa0605" + "6279746573" + // field 101, encoding 2, string "bytes"
1779
- "b0063f" + // field 102, encoding 0, 0x3f zigzag32
1780
- "b8067f" // field 103, encoding 0, 0x7f zigzag64
1781
-
1782
- o := old()
1783
- bytes, err := Marshal(pb)
1784
- if _, ok := err.(*RequiredNotSetError); !ok {
1785
- fmt.Printf("marshal-1 err = %v, want *RequiredNotSetError", err)
1786
- o.DebugPrint("", bytes)
1787
- t.Fatalf("expected = %s", expected)
1788
- }
1789
- if strings.Index(err.Error(), "RequiredField.Label") < 0 {
1790
- t.Errorf("marshal-1 wrong err msg: %v", err)
1791
- }
1792
- if !equal(bytes, expected, t) {
1793
- o.DebugPrint("neq 1", bytes)
1794
- t.Fatalf("expected = %s", expected)
1795
- }
1796
-
1797
- // Now test Unmarshal by recreating the original buffer.
1798
- pbd := new(GoTest)
1799
- err = Unmarshal(bytes, pbd)
1800
- if _, ok := err.(*RequiredNotSetError); !ok {
1801
- t.Fatalf("unmarshal err = %v, want *RequiredNotSetError", err)
1802
- o.DebugPrint("", bytes)
1803
- t.Fatalf("string = %s", expected)
1804
- }
1805
- if strings.Index(err.Error(), "RequiredField.{Unknown}") < 0 {
1806
- t.Errorf("unmarshal wrong err msg: %v", err)
1807
- }
1808
- bytes, err = Marshal(pbd)
1809
- if _, ok := err.(*RequiredNotSetError); !ok {
1810
- t.Errorf("marshal-2 err = %v, want *RequiredNotSetError", err)
1811
- o.DebugPrint("", bytes)
1812
- t.Fatalf("string = %s", expected)
1813
- }
1814
- if strings.Index(err.Error(), "RequiredField.Label") < 0 {
1815
- t.Errorf("marshal-2 wrong err msg: %v", err)
1816
- }
1817
- if !equal(bytes, expected, t) {
1818
- o.DebugPrint("neq 2", bytes)
1819
- t.Fatalf("string = %s", expected)
1820
- }
1821
-}
1822
-
1823
-func fuzzUnmarshal(t *testing.T, data []byte) {
1824
- defer func() {
1825
- if e := recover(); e != nil {
1826
- t.Errorf("These bytes caused a panic: %+v", data)
1827
- t.Logf("Stack:\n%s", debug.Stack())
1828
- t.FailNow()
1829
- }
1830
- }()
1831
-
1832
- pb := new(MyMessage)
1833
- Unmarshal(data, pb)
1834
-}
1835
-
1836
-// Benchmarks
1837
-
1838
-func testMsg() *GoTest {
1839
- pb := initGoTest(true)
1840
- const N = 1000 // Internally the library starts much smaller.
1841
- pb.F_Int32Repeated = make([]int32, N)
1842
- pb.F_DoubleRepeated = make([]float64, N)
1843
- for i := 0; i < N; i++ {
1844
- pb.F_Int32Repeated[i] = int32(i)
1845
- pb.F_DoubleRepeated[i] = float64(i)
1846
- }
1847
- return pb
1848
-}
1849
-
1850
-func bytesMsg() *GoTest {
1851
- pb := initGoTest(true)
1852
- buf := make([]byte, 4000)
1853
- for i := range buf {
1854
- buf[i] = byte(i)
1855
- }
1856
- pb.F_BytesDefaulted = buf
1857
- return pb
1858
-}
1859
-
1860
-func benchmarkMarshal(b *testing.B, pb Message, marshal func(Message) ([]byte, error)) {
1861
- d, _ := marshal(pb)
1862
- b.SetBytes(int64(len(d)))
1863
- b.ResetTimer()
1864
- for i := 0; i < b.N; i++ {
1865
- marshal(pb)
1866
- }
1867
-}
1868
-
1869
-func benchmarkBufferMarshal(b *testing.B, pb Message) {
1870
- p := NewBuffer(nil)
1871
- benchmarkMarshal(b, pb, func(pb0 Message) ([]byte, error) {
1872
- p.Reset()
1873
- err := p.Marshal(pb0)
1874
- return p.Bytes(), err
1875
- })
1876
-}
1877
-
1878
-func benchmarkSize(b *testing.B, pb Message) {
1879
- benchmarkMarshal(b, pb, func(pb0 Message) ([]byte, error) {
1880
- Size(pb)
1881
- return nil, nil
1882
- })
1883
-}
1884
-
1885
-func newOf(pb Message) Message {
1886
- in := reflect.ValueOf(pb)
1887
- if in.IsNil() {
1888
- return pb
1889
- }
1890
- return reflect.New(in.Type().Elem()).Interface().(Message)
1891
-}
1892
-
1893
-func benchmarkUnmarshal(b *testing.B, pb Message, unmarshal func([]byte, Message) error) {
1894
- d, _ := Marshal(pb)
1895
- b.SetBytes(int64(len(d)))
1896
- pbd := newOf(pb)
1897
-
1898
- b.ResetTimer()
1899
- for i := 0; i < b.N; i++ {
1900
- unmarshal(d, pbd)
1901
- }
1902
-}
1903
-
1904
-func benchmarkBufferUnmarshal(b *testing.B, pb Message) {
1905
- p := NewBuffer(nil)
1906
- benchmarkUnmarshal(b, pb, func(d []byte, pb0 Message) error {
1907
- p.SetBuf(d)
1908
- return p.Unmarshal(pb0)
1909
- })
1910
-}
1911
-
1912
-// Benchmark{Marshal,BufferMarshal,Size,Unmarshal,BufferUnmarshal}{,Bytes}
1913
-
1914
-func BenchmarkMarshal(b *testing.B) {
1915
- benchmarkMarshal(b, testMsg(), Marshal)
1916
-}
1917
-
1918
-func BenchmarkBufferMarshal(b *testing.B) {
1919
- benchmarkBufferMarshal(b, testMsg())
1920
-}
1921
-
1922
-func BenchmarkSize(b *testing.B) {
1923
- benchmarkSize(b, testMsg())
1924
-}
1925
-
1926
-func BenchmarkUnmarshal(b *testing.B) {
1927
- benchmarkUnmarshal(b, testMsg(), Unmarshal)
1928
-}
1929
-
1930
-func BenchmarkBufferUnmarshal(b *testing.B) {
1931
- benchmarkBufferUnmarshal(b, testMsg())
1932
-}
1933
-
1934
-func BenchmarkMarshalBytes(b *testing.B) {
1935
- benchmarkMarshal(b, bytesMsg(), Marshal)
1936
-}
1937
-
1938
-func BenchmarkBufferMarshalBytes(b *testing.B) {
1939
- benchmarkBufferMarshal(b, bytesMsg())
1940
-}
1941
-
1942
-func BenchmarkSizeBytes(b *testing.B) {
1943
- benchmarkSize(b, bytesMsg())
1944
-}
1945
-
1946
-func BenchmarkUnmarshalBytes(b *testing.B) {
1947
- benchmarkUnmarshal(b, bytesMsg(), Unmarshal)
1948
-}
1949
-
1950
-func BenchmarkBufferUnmarshalBytes(b *testing.B) {
1951
- benchmarkBufferUnmarshal(b, bytesMsg())
1952
-}
1953
-
1954
-func BenchmarkUnmarshalUnrecognizedFields(b *testing.B) {
1955
- b.StopTimer()
1956
- pb := initGoTestField()
1957
- skip := &GoSkipTest{
1958
- SkipInt32: Int32(32),
1959
- SkipFixed32: Uint32(3232),
1960
- SkipFixed64: Uint64(6464),
1961
- SkipString: String("skipper"),
1962
- Skipgroup: &GoSkipTest_SkipGroup{
1963
- GroupInt32: Int32(75),
1964
- GroupString: String("wxyz"),
1965
- },
1966
- }
1967
-
1968
- pbd := new(GoTestField)
1969
- p := NewBuffer(nil)
1970
- p.Marshal(pb)
1971
- p.Marshal(skip)
1972
- p2 := NewBuffer(nil)
1973
-
1974
- b.StartTimer()
1975
- for i := 0; i < b.N; i++ {
1976
- p2.SetBuf(p.Bytes())
1977
- p2.Unmarshal(pbd)
1978
- }
1979
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/clone.go
deleted
-179
@@ -1,179 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2011 The Go Authors. All rights reserved.
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
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().(extensionsMap); ok {
87
- emOut := out.Addr().Interface().(extensionsMap)
88
- mergeExtension(emOut.ExtensionMap(), emIn.ExtensionMap())
89
- } else if emIn, ok := in.Addr().Interface().(extensionsBytes); ok {
90
- emOut := out.Addr().Interface().(extensionsBytes)
91
- bIn := emIn.GetExtensions()
92
- bOut := emOut.GetExtensions()
93
- *bOut = append(*bOut, *bIn...)
94
- }
95
-
96
- uf := in.FieldByName("XXX_unrecognized")
97
- if !uf.IsValid() {
98
- return
99
- }
100
- uin := uf.Bytes()
101
- if len(uin) > 0 {
102
- out.FieldByName("XXX_unrecognized").SetBytes(append([]byte(nil), uin...))
103
- }
104
-}
105
-
106
-func mergeAny(out, in reflect.Value) {
107
- if in.Type() == protoMessageType {
108
- if !in.IsNil() {
109
- if out.IsNil() {
110
- out.Set(reflect.ValueOf(Clone(in.Interface().(Message))))
111
- } else {
112
- Merge(out.Interface().(Message), in.Interface().(Message))
113
- }
114
- }
115
- return
116
- }
117
- switch in.Kind() {
118
- case reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int32, reflect.Int64,
119
- reflect.String, reflect.Uint32, reflect.Uint64:
120
- out.Set(in)
121
- case reflect.Ptr:
122
- if in.IsNil() {
123
- return
124
- }
125
- if out.IsNil() {
126
- out.Set(reflect.New(in.Elem().Type()))
127
- }
128
- mergeAny(out.Elem(), in.Elem())
129
- case reflect.Slice:
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))
144
- }
145
- switch in.Type().Elem().Kind() {
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))
149
- default:
150
- for i := 0; i < n; i++ {
151
- x := reflect.Indirect(reflect.New(in.Type().Elem()))
152
- mergeAny(x, in.Index(i))
153
- out.Set(reflect.Append(out, x))
154
- }
155
- }
156
- case reflect.Struct:
157
- mergeStruct(out, in)
158
- default:
159
- // unknown type, so not a protocol buffer
160
- log.Printf("proto: don't know how to copy %v", in)
161
- }
162
-}
163
-
164
-func mergeExtension(out, in map[int32]Extension) {
165
- for extNum, eIn := range in {
166
- eOut := Extension{desc: eIn.desc}
167
- if eIn.value != nil {
168
- v := reflect.New(reflect.TypeOf(eIn.value)).Elem()
169
- mergeAny(v, reflect.ValueOf(eIn.value))
170
- eOut.value = v.Interface()
171
- }
172
- if eIn.enc != nil {
173
- eOut.enc = make([]byte, len(eIn.enc))
174
- copy(eOut.enc, eIn.enc)
175
- }
176
-
177
- out[extNum] = eOut
178
- }
179
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/clone_test.go
deleted
-201
@@ -1,201 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2011 The Go Authors. All rights reserved.
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
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/github.com/gogo/protobuf/proto"
39
-)
40
-
41
-var cloneTestMessage = &pb.MyMessage{
42
- Count: proto.Int32(42),
43
- Name: proto.String("Dave"),
44
- Pet: []string{"bunny", "kitty", "horsey"},
45
- Inner: &pb.InnerMessage{
46
- Host: proto.String("niles"),
47
- Port: proto.Int32(9099),
48
- Connected: proto.Bool(true),
49
- },
50
- Others: []*pb.OtherMessage{
51
- {
52
- Value: []byte("some bytes"),
53
- },
54
- },
55
- Somegroup: &pb.MyMessage_SomeGroup{
56
- GroupField: proto.Int32(6),
57
- },
58
- RepBytes: [][]byte{[]byte("sham"), []byte("wow")},
59
-}
60
-
61
-func init() {
62
- ext := &pb.Ext{
63
- Data: proto.String("extension"),
64
- }
65
- if err := proto.SetExtension(cloneTestMessage, pb.E_Ext_More, ext); err != nil {
66
- panic("SetExtension: " + err.Error())
67
- }
68
-}
69
-
70
-func TestClone(t *testing.T) {
71
- m := proto.Clone(cloneTestMessage).(*pb.MyMessage)
72
- if !proto.Equal(m, cloneTestMessage) {
73
- t.Errorf("Clone(%v) = %v", cloneTestMessage, m)
74
- }
75
-
76
- // Verify it was a deep copy.
77
- *m.Inner.Port++
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) {
100
- var m *pb.MyMessage
101
- if c := proto.Clone(m); !proto.Equal(m, c) {
102
- t.Errorf("Clone(%v) = %v", m, c)
103
- }
104
-}
105
-
106
-var mergeTests = []struct {
107
- src, dst, want proto.Message
108
-}{
109
- {
110
- src: &pb.MyMessage{
111
- Count: proto.Int32(42),
112
- },
113
- dst: &pb.MyMessage{
114
- Name: proto.String("Dave"),
115
- },
116
- want: &pb.MyMessage{
117
- Count: proto.Int32(42),
118
- Name: proto.String("Dave"),
119
- },
120
- },
121
- {
122
- src: &pb.MyMessage{
123
- Inner: &pb.InnerMessage{
124
- Host: proto.String("hey"),
125
- Connected: proto.Bool(true),
126
- },
127
- Pet: []string{"horsey"},
128
- Others: []*pb.OtherMessage{
129
- {
130
- Value: []byte("some bytes"),
131
- },
132
- },
133
- },
134
- dst: &pb.MyMessage{
135
- Inner: &pb.InnerMessage{
136
- Host: proto.String("niles"),
137
- Port: proto.Int32(9099),
138
- },
139
- Pet: []string{"bunny", "kitty"},
140
- Others: []*pb.OtherMessage{
141
- {
142
- Key: proto.Int64(31415926535),
143
- },
144
- {
145
- // Explicitly test a src=nil field
146
- Inner: nil,
147
- },
148
- },
149
- },
150
- want: &pb.MyMessage{
151
- Inner: &pb.InnerMessage{
152
- Host: proto.String("hey"),
153
- Connected: proto.Bool(true),
154
- Port: proto.Int32(9099),
155
- },
156
- Pet: []string{"bunny", "kitty", "horsey"},
157
- Others: []*pb.OtherMessage{
158
- {
159
- Key: proto.Int64(31415926535),
160
- },
161
- {},
162
- {
163
- Value: []byte("some bytes"),
164
- },
165
- },
166
- },
167
- },
168
- {
169
- src: &pb.MyMessage{
170
- RepBytes: [][]byte{[]byte("wow")},
171
- },
172
- dst: &pb.MyMessage{
173
- Somegroup: &pb.MyMessage_SomeGroup{
174
- GroupField: proto.Int32(6),
175
- },
176
- RepBytes: [][]byte{[]byte("sham")},
177
- },
178
- want: &pb.MyMessage{
179
- Somegroup: &pb.MyMessage_SomeGroup{
180
- GroupField: proto.Int32(6),
181
- },
182
- RepBytes: [][]byte{[]byte("sham"), []byte("wow")},
183
- },
184
- },
185
- // Check that a scalar bytes field replaces rather than appends.
186
- {
187
- src: &pb.OtherMessage{Value: []byte("foo")},
188
- dst: &pb.OtherMessage{Value: []byte("bar")},
189
- want: &pb.OtherMessage{Value: []byte("foo")},
190
- },
191
-}
192
-
193
-func TestMerge(t *testing.T) {
194
- for _, m := range mergeTests {
195
- got := proto.Clone(m.dst)
196
- proto.Merge(got, m.src)
197
- if !proto.Equal(got, m.want) {
198
- t.Errorf("Merge(%v, %v)\n got %v\nwant %v\n", m.dst, m.src, got, m.want)
199
- }
200
- }
201
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/decode.go
deleted
-726
@@ -1,726 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
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
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 (wire type %d)", st, tag, wire)
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
- if ee, ok := e.(extensionsMap); ok {
374
- ext := ee.ExtensionMap()[int32(tag)] // may be missing
375
- ext.enc = append(ext.enc, o.buf[oi:o.index]...)
376
- ee.ExtensionMap()[int32(tag)] = ext
377
- } else if ee, ok := e.(extensionsBytes); ok {
378
- ext := ee.GetExtensions()
379
- *ext = append(*ext, o.buf[oi:o.index]...)
380
- }
381
- }
382
- continue
383
- }
384
- }
385
- err = o.skipAndSave(st, tag, wire, base, prop.unrecField)
386
- continue
387
- }
388
- p := prop.Prop[fieldnum]
389
-
390
- if p.dec == nil {
391
- fmt.Fprintf(os.Stderr, "proto: no protobuf decoder for %s.%s\n", st, st.Field(fieldnum).Name)
392
- continue
393
- }
394
- dec := p.dec
395
- if wire != WireStartGroup && wire != p.WireType {
396
- if wire == WireBytes && p.packedDec != nil {
397
- // a packable field
398
- dec = p.packedDec
399
- } else {
400
- err = fmt.Errorf("proto: bad wiretype for field %s.%s: got wiretype %d, want %d", st, st.Field(fieldnum).Name, wire, p.WireType)
401
- continue
402
- }
403
- }
404
- decErr := dec(o, p, base)
405
- if decErr != nil && !state.shouldContinue(decErr, p) {
406
- err = decErr
407
- }
408
- if err == nil && p.Required {
409
- // Successfully decoded a required field.
410
- if tag <= 64 {
411
- // use bitmap for fields 1-64 to catch field reuse.
412
- var mask uint64 = 1 << uint64(tag-1)
413
- if reqFields&mask == 0 {
414
- // new required field
415
- reqFields |= mask
416
- required--
417
- }
418
- } else {
419
- // This is imprecise. It can be fooled by a required field
420
- // with a tag > 64 that is encoded twice; that's very rare.
421
- // A fully correct implementation would require allocating
422
- // a data structure, which we would like to avoid.
423
- required--
424
- }
425
- }
426
- }
427
- if err == nil {
428
- if is_group {
429
- return io.ErrUnexpectedEOF
430
- }
431
- if state.err != nil {
432
- return state.err
433
- }
434
- if required > 0 {
435
- // Not enough information to determine the exact field. If we use extra
436
- // CPU, we could determine the field only if the missing required field
437
- // has a tag <= 64 and we check reqFields.
438
- return &RequiredNotSetError{"{Unknown}"}
439
- }
440
- }
441
- return err
442
-}
443
-
444
-// Individual type decoders
445
-// For each,
446
-// u is the decoded value,
447
-// v is a pointer to the field (pointer) in the struct
448
-
449
-// Sizes of the pools to allocate inside the Buffer.
450
-// The goal is modest amortization and allocation
451
-// on at least 16-byte boundaries.
452
-const (
453
- boolPoolSize = 16
454
- uint32PoolSize = 8
455
- uint64PoolSize = 4
456
-)
457
-
458
-// Decode a bool.
459
-func (o *Buffer) dec_bool(p *Properties, base structPointer) error {
460
- u, err := p.valDec(o)
461
- if err != nil {
462
- return err
463
- }
464
- if len(o.bools) == 0 {
465
- o.bools = make([]bool, boolPoolSize)
466
- }
467
- o.bools[0] = u != 0
468
- *structPointer_Bool(base, p.field) = &o.bools[0]
469
- o.bools = o.bools[1:]
470
- return nil
471
-}
472
-
473
-// Decode an int32.
474
-func (o *Buffer) dec_int32(p *Properties, base structPointer) error {
475
- u, err := p.valDec(o)
476
- if err != nil {
477
- return err
478
- }
479
- word32_Set(structPointer_Word32(base, p.field), o, uint32(u))
480
- return nil
481
-}
482
-
483
-// Decode an int64.
484
-func (o *Buffer) dec_int64(p *Properties, base structPointer) error {
485
- u, err := p.valDec(o)
486
- if err != nil {
487
- return err
488
- }
489
- word64_Set(structPointer_Word64(base, p.field), o, u)
490
- return nil
491
-}
492
-
493
-// Decode a string.
494
-func (o *Buffer) dec_string(p *Properties, base structPointer) error {
495
- s, err := o.DecodeStringBytes()
496
- if err != nil {
497
- return err
498
- }
499
- sp := new(string)
500
- *sp = s
501
- *structPointer_String(base, p.field) = sp
502
- return nil
503
-}
504
-
505
-// Decode a slice of bytes ([]byte).
506
-func (o *Buffer) dec_slice_byte(p *Properties, base structPointer) error {
507
- b, err := o.DecodeRawBytes(true)
508
- if err != nil {
509
- return err
510
- }
511
- *structPointer_Bytes(base, p.field) = b
512
- return nil
513
-}
514
-
515
-// Decode a slice of bools ([]bool).
516
-func (o *Buffer) dec_slice_bool(p *Properties, base structPointer) error {
517
- u, err := p.valDec(o)
518
- if err != nil {
519
- return err
520
- }
521
- v := structPointer_BoolSlice(base, p.field)
522
- *v = append(*v, u != 0)
523
- return nil
524
-}
525
-
526
-// Decode a slice of bools ([]bool) in packed format.
527
-func (o *Buffer) dec_slice_packed_bool(p *Properties, base structPointer) error {
528
- v := structPointer_BoolSlice(base, p.field)
529
-
530
- nn, err := o.DecodeVarint()
531
- if err != nil {
532
- return err
533
- }
534
- nb := int(nn) // number of bytes of encoded bools
535
-
536
- y := *v
537
- for i := 0; i < nb; i++ {
538
- u, err := p.valDec(o)
539
- if err != nil {
540
- return err
541
- }
542
- y = append(y, u != 0)
543
- }
544
-
545
- *v = y
546
- return nil
547
-}
548
-
549
-// Decode a slice of int32s ([]int32).
550
-func (o *Buffer) dec_slice_int32(p *Properties, base structPointer) error {
551
- u, err := p.valDec(o)
552
- if err != nil {
553
- return err
554
- }
555
- structPointer_Word32Slice(base, p.field).Append(uint32(u))
556
- return nil
557
-}
558
-
559
-// Decode a slice of int32s ([]int32) in packed format.
560
-func (o *Buffer) dec_slice_packed_int32(p *Properties, base structPointer) error {
561
- v := structPointer_Word32Slice(base, p.field)
562
-
563
- nn, err := o.DecodeVarint()
564
- if err != nil {
565
- return err
566
- }
567
- nb := int(nn) // number of bytes of encoded int32s
568
-
569
- fin := o.index + nb
570
- if fin < o.index {
571
- return errOverflow
572
- }
573
- for o.index < fin {
574
- u, err := p.valDec(o)
575
- if err != nil {
576
- return err
577
- }
578
- v.Append(uint32(u))
579
- }
580
- return nil
581
-}
582
-
583
-// Decode a slice of int64s ([]int64).
584
-func (o *Buffer) dec_slice_int64(p *Properties, base structPointer) error {
585
- u, err := p.valDec(o)
586
- if err != nil {
587
- return err
588
- }
589
-
590
- structPointer_Word64Slice(base, p.field).Append(u)
591
- return nil
592
-}
593
-
594
-// Decode a slice of int64s ([]int64) in packed format.
595
-func (o *Buffer) dec_slice_packed_int64(p *Properties, base structPointer) error {
596
- v := structPointer_Word64Slice(base, p.field)
597
-
598
- nn, err := o.DecodeVarint()
599
- if err != nil {
600
- return err
601
- }
602
- nb := int(nn) // number of bytes of encoded int64s
603
-
604
- fin := o.index + nb
605
- if fin < o.index {
606
- return errOverflow
607
- }
608
- for o.index < fin {
609
- u, err := p.valDec(o)
610
- if err != nil {
611
- return err
612
- }
613
- v.Append(u)
614
- }
615
- return nil
616
-}
617
-
618
-// Decode a slice of strings ([]string).
619
-func (o *Buffer) dec_slice_string(p *Properties, base structPointer) error {
620
- s, err := o.DecodeStringBytes()
621
- if err != nil {
622
- return err
623
- }
624
- v := structPointer_StringSlice(base, p.field)
625
- *v = append(*v, s)
626
- return nil
627
-}
628
-
629
-// Decode a slice of slice of bytes ([][]byte).
630
-func (o *Buffer) dec_slice_slice_byte(p *Properties, base structPointer) error {
631
- b, err := o.DecodeRawBytes(true)
632
- if err != nil {
633
- return err
634
- }
635
- v := structPointer_BytesSlice(base, p.field)
636
- *v = append(*v, b)
637
- return nil
638
-}
639
-
640
-// Decode a group.
641
-func (o *Buffer) dec_struct_group(p *Properties, base structPointer) error {
642
- bas := structPointer_GetStructPointer(base, p.field)
643
- if structPointer_IsNil(bas) {
644
- // allocate new nested message
645
- bas = toStructPointer(reflect.New(p.stype))
646
- structPointer_SetStructPointer(base, p.field, bas)
647
- }
648
- return o.unmarshalType(p.stype, p.sprop, true, bas)
649
-}
650
-
651
-// Decode an embedded message.
652
-func (o *Buffer) dec_struct_message(p *Properties, base structPointer) (err error) {
653
- raw, e := o.DecodeRawBytes(false)
654
- if e != nil {
655
- return e
656
- }
657
-
658
- bas := structPointer_GetStructPointer(base, p.field)
659
- if structPointer_IsNil(bas) {
660
- // allocate new nested message
661
- bas = toStructPointer(reflect.New(p.stype))
662
- structPointer_SetStructPointer(base, p.field, bas)
663
- }
664
-
665
- // If the object can unmarshal itself, let it.
666
- if p.isUnmarshaler {
667
- iv := structPointer_Interface(bas, p.stype)
668
- return iv.(Unmarshaler).Unmarshal(raw)
669
- }
670
-
671
- obuf := o.buf
672
- oi := o.index
673
- o.buf = raw
674
- o.index = 0
675
-
676
- err = o.unmarshalType(p.stype, p.sprop, false, bas)
677
- o.buf = obuf
678
- o.index = oi
679
-
680
- return err
681
-}
682
-
683
-// Decode a slice of embedded messages.
684
-func (o *Buffer) dec_slice_struct_message(p *Properties, base structPointer) error {
685
- return o.dec_slice_struct(p, false, base)
686
-}
687
-
688
-// Decode a slice of embedded groups.
689
-func (o *Buffer) dec_slice_struct_group(p *Properties, base structPointer) error {
690
- return o.dec_slice_struct(p, true, base)
691
-}
692
-
693
-// Decode a slice of structs ([]*struct).
694
-func (o *Buffer) dec_slice_struct(p *Properties, is_group bool, base structPointer) error {
695
- v := reflect.New(p.stype)
696
- bas := toStructPointer(v)
697
- structPointer_StructPointerSlice(base, p.field).Append(bas)
698
-
699
- if is_group {
700
- err := o.unmarshalType(p.stype, p.sprop, is_group, bas)
701
- return err
702
- }
703
-
704
- raw, err := o.DecodeRawBytes(false)
705
- if err != nil {
706
- return err
707
- }
708
-
709
- // If the object can unmarshal itself, let it.
710
- if p.isUnmarshaler {
711
- iv := v.Interface()
712
- return iv.(Unmarshaler).Unmarshal(raw)
713
- }
714
-
715
- obuf := o.buf
716
- oi := o.index
717
- o.buf = raw
718
- o.index = 0
719
-
720
- err = o.unmarshalType(p.stype, p.sprop, is_group, bas)
721
-
722
- o.buf = obuf
723
- o.index = oi
724
-
725
- return err
726
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/decode_gogo.go
deleted
-220
@@ -1,220 +0,0 @@
1
-// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
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
6
-// met:
7
-//
8
-// * Redistributions of source code must retain the above copyright
9
-// notice, this list of conditions and the following disclaimer.
10
-// * Redistributions in binary form must reproduce the above
11
-// copyright notice, this list of conditions and the following disclaimer
12
-// in the documentation and/or other materials provided with the
13
-// distribution.
14
-//
15
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
-
27
-package proto
28
-
29
-import (
30
- "reflect"
31
-)
32
-
33
-// Decode a reference to a bool pointer.
34
-func (o *Buffer) dec_ref_bool(p *Properties, base structPointer) error {
35
- u, err := p.valDec(o)
36
- if err != nil {
37
- return err
38
- }
39
- if len(o.bools) == 0 {
40
- o.bools = make([]bool, boolPoolSize)
41
- }
42
- o.bools[0] = u != 0
43
- *structPointer_RefBool(base, p.field) = o.bools[0]
44
- o.bools = o.bools[1:]
45
- return nil
46
-}
47
-
48
-// Decode a reference to an int32 pointer.
49
-func (o *Buffer) dec_ref_int32(p *Properties, base structPointer) error {
50
- u, err := p.valDec(o)
51
- if err != nil {
52
- return err
53
- }
54
- refWord32_Set(structPointer_RefWord32(base, p.field), o, uint32(u))
55
- return nil
56
-}
57
-
58
-// Decode a reference to an int64 pointer.
59
-func (o *Buffer) dec_ref_int64(p *Properties, base structPointer) error {
60
- u, err := p.valDec(o)
61
- if err != nil {
62
- return err
63
- }
64
- refWord64_Set(structPointer_RefWord64(base, p.field), o, u)
65
- return nil
66
-}
67
-
68
-// Decode a reference to a string pointer.
69
-func (o *Buffer) dec_ref_string(p *Properties, base structPointer) error {
70
- s, err := o.DecodeStringBytes()
71
- if err != nil {
72
- return err
73
- }
74
- *structPointer_RefString(base, p.field) = s
75
- return nil
76
-}
77
-
78
-// Decode a reference to a struct pointer.
79
-func (o *Buffer) dec_ref_struct_message(p *Properties, base structPointer) (err error) {
80
- raw, e := o.DecodeRawBytes(false)
81
- if e != nil {
82
- return e
83
- }
84
-
85
- // If the object can unmarshal itself, let it.
86
- if p.isUnmarshaler {
87
- panic("not supported, since this is a pointer receiver")
88
- }
89
-
90
- obuf := o.buf
91
- oi := o.index
92
- o.buf = raw
93
- o.index = 0
94
-
95
- bas := structPointer_FieldPointer(base, p.field)
96
-
97
- err = o.unmarshalType(p.stype, p.sprop, false, bas)
98
- o.buf = obuf
99
- o.index = oi
100
-
101
- return err
102
-}
103
-
104
-// Decode a slice of references to struct pointers ([]struct).
105
-func (o *Buffer) dec_slice_ref_struct(p *Properties, is_group bool, base structPointer) error {
106
- newBas := appendStructPointer(base, p.field, p.sstype)
107
-
108
- if is_group {
109
- panic("not supported, maybe in future, if requested.")
110
- }
111
-
112
- raw, err := o.DecodeRawBytes(false)
113
- if err != nil {
114
- return err
115
- }
116
-
117
- // If the object can unmarshal itself, let it.
118
- if p.isUnmarshaler {
119
- panic("not supported, since this is not a pointer receiver.")
120
- }
121
-
122
- obuf := o.buf
123
- oi := o.index
124
- o.buf = raw
125
- o.index = 0
126
-
127
- err = o.unmarshalType(p.stype, p.sprop, is_group, newBas)
128
-
129
- o.buf = obuf
130
- o.index = oi
131
-
132
- return err
133
-}
134
-
135
-// Decode a slice of references to struct pointers.
136
-func (o *Buffer) dec_slice_ref_struct_message(p *Properties, base structPointer) error {
137
- return o.dec_slice_ref_struct(p, false, base)
138
-}
139
-
140
-func setPtrCustomType(base structPointer, f field, v interface{}) {
141
- if v == nil {
142
- return
143
- }
144
- structPointer_SetStructPointer(base, f, structPointer(reflect.ValueOf(v).Pointer()))
145
-}
146
-
147
-func setCustomType(base structPointer, f field, value interface{}) {
148
- if value == nil {
149
- return
150
- }
151
- v := reflect.ValueOf(value).Elem()
152
- t := reflect.TypeOf(value).Elem()
153
- kind := t.Kind()
154
- switch kind {
155
- case reflect.Slice:
156
- slice := reflect.MakeSlice(t, v.Len(), v.Cap())
157
- reflect.Copy(slice, v)
158
- oldHeader := structPointer_GetSliceHeader(base, f)
159
- oldHeader.Data = slice.Pointer()
160
- oldHeader.Len = v.Len()
161
- oldHeader.Cap = v.Cap()
162
- default:
163
- l := 1
164
- size := reflect.TypeOf(value).Elem().Size()
165
- if kind == reflect.Array {
166
- l = reflect.TypeOf(value).Elem().Len()
167
- size = reflect.TypeOf(value).Size()
168
- }
169
- total := int(size) * l
170
- structPointer_Copy(toStructPointer(reflect.ValueOf(value)), structPointer_Add(base, f), total)
171
- }
172
-}
173
-
174
-func (o *Buffer) dec_custom_bytes(p *Properties, base structPointer) error {
175
- b, err := o.DecodeRawBytes(true)
176
- if err != nil {
177
- return err
178
- }
179
- i := reflect.New(p.ctype.Elem()).Interface()
180
- custom := (i).(Unmarshaler)
181
- if err := custom.Unmarshal(b); err != nil {
182
- return err
183
- }
184
- setPtrCustomType(base, p.field, custom)
185
- return nil
186
-}
187
-
188
-func (o *Buffer) dec_custom_ref_bytes(p *Properties, base structPointer) error {
189
- b, err := o.DecodeRawBytes(true)
190
- if err != nil {
191
- return err
192
- }
193
- i := reflect.New(p.ctype).Interface()
194
- custom := (i).(Unmarshaler)
195
- if err := custom.Unmarshal(b); err != nil {
196
- return err
197
- }
198
- if custom != nil {
199
- setCustomType(base, p.field, custom)
200
- }
201
- return nil
202
-}
203
-
204
-// Decode a slice of bytes ([]byte) into a slice of custom types.
205
-func (o *Buffer) dec_custom_slice_bytes(p *Properties, base structPointer) error {
206
- b, err := o.DecodeRawBytes(true)
207
- if err != nil {
208
- return err
209
- }
210
- i := reflect.New(p.ctype.Elem()).Interface()
211
- custom := (i).(Unmarshaler)
212
- if err := custom.Unmarshal(b); err != nil {
213
- return err
214
- }
215
- newBas := appendStructPointer(base, p.field, p.ctype)
216
-
217
- setCustomType(newBas, 0, custom)
218
-
219
- return nil
220
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/encode.go
deleted
-1054
@@ -1,1054 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
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
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(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(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 := int32(word32_Get(v)) // permit sign extension to use full 64-bit range
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 := int32(word32_Get(v)) // permit sign extension to use full 64-bit range
327
- n += len(p.tagcode)
328
- n += p.valSize(uint64(x))
329
- return
330
-}
331
-
332
-// Encode a uint32.
333
-// Exactly the same as int32, except for no sign extension.
334
-func (o *Buffer) enc_uint32(p *Properties, base structPointer) error {
335
- v := structPointer_Word32(base, p.field)
336
- if word32_IsNil(v) {
337
- return ErrNil
338
- }
339
- x := word32_Get(v)
340
- o.buf = append(o.buf, p.tagcode...)
341
- p.valEnc(o, uint64(x))
342
- return nil
343
-}
344
-
345
-func size_uint32(p *Properties, base structPointer) (n int) {
346
- v := structPointer_Word32(base, p.field)
347
- if word32_IsNil(v) {
348
- return 0
349
- }
350
- x := word32_Get(v)
351
- n += len(p.tagcode)
352
- n += p.valSize(uint64(x))
353
- return
354
-}
355
-
356
-// Encode an int64.
357
-func (o *Buffer) enc_int64(p *Properties, base structPointer) error {
358
- v := structPointer_Word64(base, p.field)
359
- if word64_IsNil(v) {
360
- return ErrNil
361
- }
362
- x := word64_Get(v)
363
- o.buf = append(o.buf, p.tagcode...)
364
- p.valEnc(o, x)
365
- return nil
366
-}
367
-
368
-func size_int64(p *Properties, base structPointer) (n int) {
369
- v := structPointer_Word64(base, p.field)
370
- if word64_IsNil(v) {
371
- return 0
372
- }
373
- x := word64_Get(v)
374
- n += len(p.tagcode)
375
- n += p.valSize(x)
376
- return
377
-}
378
-
379
-// Encode a string.
380
-func (o *Buffer) enc_string(p *Properties, base structPointer) error {
381
- v := *structPointer_String(base, p.field)
382
- if v == nil {
383
- return ErrNil
384
- }
385
- x := *v
386
- o.buf = append(o.buf, p.tagcode...)
387
- o.EncodeStringBytes(x)
388
- return nil
389
-}
390
-
391
-func size_string(p *Properties, base structPointer) (n int) {
392
- v := *structPointer_String(base, p.field)
393
- if v == nil {
394
- return 0
395
- }
396
- x := *v
397
- n += len(p.tagcode)
398
- n += sizeStringBytes(x)
399
- return
400
-}
401
-
402
-// All protocol buffer fields are nillable, but be careful.
403
-func isNil(v reflect.Value) bool {
404
- switch v.Kind() {
405
- case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
406
- return v.IsNil()
407
- }
408
- return false
409
-}
410
-
411
-// Encode a message struct.
412
-func (o *Buffer) enc_struct_message(p *Properties, base structPointer) error {
413
- var state errorState
414
- structp := structPointer_GetStructPointer(base, p.field)
415
- if structPointer_IsNil(structp) {
416
- return ErrNil
417
- }
418
-
419
- // Can the object marshal itself?
420
- if p.isMarshaler {
421
- m := structPointer_Interface(structp, p.stype).(Marshaler)
422
- data, err := m.Marshal()
423
- if err != nil && !state.shouldContinue(err, nil) {
424
- return err
425
- }
426
- o.buf = append(o.buf, p.tagcode...)
427
- o.EncodeRawBytes(data)
428
- return nil
429
- }
430
-
431
- o.buf = append(o.buf, p.tagcode...)
432
- return o.enc_len_struct(p.sprop, structp, &state)
433
-}
434
-
435
-func size_struct_message(p *Properties, base structPointer) int {
436
- structp := structPointer_GetStructPointer(base, p.field)
437
- if structPointer_IsNil(structp) {
438
- return 0
439
- }
440
-
441
- // Can the object marshal itself?
442
- if p.isMarshaler {
443
- m := structPointer_Interface(structp, p.stype).(Marshaler)
444
- data, _ := m.Marshal()
445
- n0 := len(p.tagcode)
446
- n1 := sizeRawBytes(data)
447
- return n0 + n1
448
- }
449
-
450
- n0 := len(p.tagcode)
451
- n1 := size_struct(p.sprop, structp)
452
- n2 := sizeVarint(uint64(n1)) // size of encoded length
453
- return n0 + n1 + n2
454
-}
455
-
456
-// Encode a group struct.
457
-func (o *Buffer) enc_struct_group(p *Properties, base structPointer) error {
458
- var state errorState
459
- b := structPointer_GetStructPointer(base, p.field)
460
- if structPointer_IsNil(b) {
461
- return ErrNil
462
- }
463
-
464
- o.EncodeVarint(uint64((p.Tag << 3) | WireStartGroup))
465
- err := o.enc_struct(p.sprop, b)
466
- if err != nil && !state.shouldContinue(err, nil) {
467
- return err
468
- }
469
- o.EncodeVarint(uint64((p.Tag << 3) | WireEndGroup))
470
- return state.err
471
-}
472
-
473
-func size_struct_group(p *Properties, base structPointer) (n int) {
474
- b := structPointer_GetStructPointer(base, p.field)
475
- if structPointer_IsNil(b) {
476
- return 0
477
- }
478
-
479
- n += sizeVarint(uint64((p.Tag << 3) | WireStartGroup))
480
- n += size_struct(p.sprop, b)
481
- n += sizeVarint(uint64((p.Tag << 3) | WireEndGroup))
482
- return
483
-}
484
-
485
-// Encode a slice of bools ([]bool).
486
-func (o *Buffer) enc_slice_bool(p *Properties, base structPointer) error {
487
- s := *structPointer_BoolSlice(base, p.field)
488
- l := len(s)
489
- if l == 0 {
490
- return ErrNil
491
- }
492
- for _, x := range s {
493
- o.buf = append(o.buf, p.tagcode...)
494
- v := uint64(0)
495
- if x {
496
- v = 1
497
- }
498
- p.valEnc(o, v)
499
- }
500
- return nil
501
-}
502
-
503
-func size_slice_bool(p *Properties, base structPointer) int {
504
- s := *structPointer_BoolSlice(base, p.field)
505
- l := len(s)
506
- if l == 0 {
507
- return 0
508
- }
509
- return l * (len(p.tagcode) + 1) // each bool takes exactly one byte
510
-}
511
-
512
-// Encode a slice of bools ([]bool) in packed format.
513
-func (o *Buffer) enc_slice_packed_bool(p *Properties, base structPointer) error {
514
- s := *structPointer_BoolSlice(base, p.field)
515
- l := len(s)
516
- if l == 0 {
517
- return ErrNil
518
- }
519
- o.buf = append(o.buf, p.tagcode...)
520
- o.EncodeVarint(uint64(l)) // each bool takes exactly one byte
521
- for _, x := range s {
522
- v := uint64(0)
523
- if x {
524
- v = 1
525
- }
526
- p.valEnc(o, v)
527
- }
528
- return nil
529
-}
530
-
531
-func size_slice_packed_bool(p *Properties, base structPointer) (n int) {
532
- s := *structPointer_BoolSlice(base, p.field)
533
- l := len(s)
534
- if l == 0 {
535
- return 0
536
- }
537
- n += len(p.tagcode)
538
- n += sizeVarint(uint64(l))
539
- n += l // each bool takes exactly one byte
540
- return
541
-}
542
-
543
-// Encode a slice of bytes ([]byte).
544
-func (o *Buffer) enc_slice_byte(p *Properties, base structPointer) error {
545
- s := *structPointer_Bytes(base, p.field)
546
- if s == nil {
547
- return ErrNil
548
- }
549
- o.buf = append(o.buf, p.tagcode...)
550
- o.EncodeRawBytes(s)
551
- return nil
552
-}
553
-
554
-func size_slice_byte(p *Properties, base structPointer) (n int) {
555
- s := *structPointer_Bytes(base, p.field)
556
- if s == nil {
557
- return 0
558
- }
559
- n += len(p.tagcode)
560
- n += sizeRawBytes(s)
561
- return
562
-}
563
-
564
-// Encode a slice of int32s ([]int32).
565
-func (o *Buffer) enc_slice_int32(p *Properties, base structPointer) error {
566
- s := structPointer_Word32Slice(base, p.field)
567
- l := s.Len()
568
- if l == 0 {
569
- return ErrNil
570
- }
571
- for i := 0; i < l; i++ {
572
- o.buf = append(o.buf, p.tagcode...)
573
- x := int32(s.Index(i)) // permit sign extension to use full 64-bit range
574
- p.valEnc(o, uint64(x))
575
- }
576
- return nil
577
-}
578
-
579
-func size_slice_int32(p *Properties, base structPointer) (n int) {
580
- s := structPointer_Word32Slice(base, p.field)
581
- l := s.Len()
582
- if l == 0 {
583
- return 0
584
- }
585
- for i := 0; i < l; i++ {
586
- n += len(p.tagcode)
587
- x := int32(s.Index(i)) // permit sign extension to use full 64-bit range
588
- n += p.valSize(uint64(x))
589
- }
590
- return
591
-}
592
-
593
-// Encode a slice of int32s ([]int32) in packed format.
594
-func (o *Buffer) enc_slice_packed_int32(p *Properties, base structPointer) error {
595
- s := structPointer_Word32Slice(base, p.field)
596
- l := s.Len()
597
- if l == 0 {
598
- return ErrNil
599
- }
600
- // TODO: Reuse a Buffer.
601
- buf := NewBuffer(nil)
602
- for i := 0; i < l; i++ {
603
- x := int32(s.Index(i)) // permit sign extension to use full 64-bit range
604
- p.valEnc(buf, uint64(x))
605
- }
606
-
607
- o.buf = append(o.buf, p.tagcode...)
608
- o.EncodeVarint(uint64(len(buf.buf)))
609
- o.buf = append(o.buf, buf.buf...)
610
- return nil
611
-}
612
-
613
-func size_slice_packed_int32(p *Properties, base structPointer) (n int) {
614
- s := structPointer_Word32Slice(base, p.field)
615
- l := s.Len()
616
- if l == 0 {
617
- return 0
618
- }
619
- var bufSize int
620
- for i := 0; i < l; i++ {
621
- x := int32(s.Index(i)) // permit sign extension to use full 64-bit range
622
- bufSize += p.valSize(uint64(x))
623
- }
624
-
625
- n += len(p.tagcode)
626
- n += sizeVarint(uint64(bufSize))
627
- n += bufSize
628
- return
629
-}
630
-
631
-// Encode a slice of uint32s ([]uint32).
632
-// Exactly the same as int32, except for no sign extension.
633
-func (o *Buffer) enc_slice_uint32(p *Properties, base structPointer) error {
634
- s := structPointer_Word32Slice(base, p.field)
635
- l := s.Len()
636
- if l == 0 {
637
- return ErrNil
638
- }
639
- for i := 0; i < l; i++ {
640
- o.buf = append(o.buf, p.tagcode...)
641
- x := s.Index(i)
642
- p.valEnc(o, uint64(x))
643
- }
644
- return nil
645
-}
646
-
647
-func size_slice_uint32(p *Properties, base structPointer) (n int) {
648
- s := structPointer_Word32Slice(base, p.field)
649
- l := s.Len()
650
- if l == 0 {
651
- return 0
652
- }
653
- for i := 0; i < l; i++ {
654
- n += len(p.tagcode)
655
- x := s.Index(i)
656
- n += p.valSize(uint64(x))
657
- }
658
- return
659
-}
660
-
661
-// Encode a slice of uint32s ([]uint32) in packed format.
662
-// Exactly the same as int32, except for no sign extension.
663
-func (o *Buffer) enc_slice_packed_uint32(p *Properties, base structPointer) error {
664
- s := structPointer_Word32Slice(base, p.field)
665
- l := s.Len()
666
- if l == 0 {
667
- return ErrNil
668
- }
669
- // TODO: Reuse a Buffer.
670
- buf := NewBuffer(nil)
671
- for i := 0; i < l; i++ {
672
- p.valEnc(buf, uint64(s.Index(i)))
673
- }
674
-
675
- o.buf = append(o.buf, p.tagcode...)
676
- o.EncodeVarint(uint64(len(buf.buf)))
677
- o.buf = append(o.buf, buf.buf...)
678
- return nil
679
-}
680
-
681
-func size_slice_packed_uint32(p *Properties, base structPointer) (n int) {
682
- s := structPointer_Word32Slice(base, p.field)
683
- l := s.Len()
684
- if l == 0 {
685
- return 0
686
- }
687
- var bufSize int
688
- for i := 0; i < l; i++ {
689
- bufSize += p.valSize(uint64(s.Index(i)))
690
- }
691
-
692
- n += len(p.tagcode)
693
- n += sizeVarint(uint64(bufSize))
694
- n += bufSize
695
- return
696
-}
697
-
698
-// Encode a slice of int64s ([]int64).
699
-func (o *Buffer) enc_slice_int64(p *Properties, base structPointer) error {
700
- s := structPointer_Word64Slice(base, p.field)
701
- l := s.Len()
702
- if l == 0 {
703
- return ErrNil
704
- }
705
- for i := 0; i < l; i++ {
706
- o.buf = append(o.buf, p.tagcode...)
707
- p.valEnc(o, s.Index(i))
708
- }
709
- return nil
710
-}
711
-
712
-func size_slice_int64(p *Properties, base structPointer) (n int) {
713
- s := structPointer_Word64Slice(base, p.field)
714
- l := s.Len()
715
- if l == 0 {
716
- return 0
717
- }
718
- for i := 0; i < l; i++ {
719
- n += len(p.tagcode)
720
- n += p.valSize(s.Index(i))
721
- }
722
- return
723
-}
724
-
725
-// Encode a slice of int64s ([]int64) in packed format.
726
-func (o *Buffer) enc_slice_packed_int64(p *Properties, base structPointer) error {
727
- s := structPointer_Word64Slice(base, p.field)
728
- l := s.Len()
729
- if l == 0 {
730
- return ErrNil
731
- }
732
- // TODO: Reuse a Buffer.
733
- buf := NewBuffer(nil)
734
- for i := 0; i < l; i++ {
735
- p.valEnc(buf, s.Index(i))
736
- }
737
-
738
- o.buf = append(o.buf, p.tagcode...)
739
- o.EncodeVarint(uint64(len(buf.buf)))
740
- o.buf = append(o.buf, buf.buf...)
741
- return nil
742
-}
743
-
744
-func size_slice_packed_int64(p *Properties, base structPointer) (n int) {
745
- s := structPointer_Word64Slice(base, p.field)
746
- l := s.Len()
747
- if l == 0 {
748
- return 0
749
- }
750
- var bufSize int
751
- for i := 0; i < l; i++ {
752
- bufSize += p.valSize(s.Index(i))
753
- }
754
-
755
- n += len(p.tagcode)
756
- n += sizeVarint(uint64(bufSize))
757
- n += bufSize
758
- return
759
-}
760
-
761
-// Encode a slice of slice of bytes ([][]byte).
762
-func (o *Buffer) enc_slice_slice_byte(p *Properties, base structPointer) error {
763
- ss := *structPointer_BytesSlice(base, p.field)
764
- l := len(ss)
765
- if l == 0 {
766
- return ErrNil
767
- }
768
- for i := 0; i < l; i++ {
769
- o.buf = append(o.buf, p.tagcode...)
770
- o.EncodeRawBytes(ss[i])
771
- }
772
- return nil
773
-}
774
-
775
-func size_slice_slice_byte(p *Properties, base structPointer) (n int) {
776
- ss := *structPointer_BytesSlice(base, p.field)
777
- l := len(ss)
778
- if l == 0 {
779
- return 0
780
- }
781
- n += l * len(p.tagcode)
782
- for i := 0; i < l; i++ {
783
- n += sizeRawBytes(ss[i])
784
- }
785
- return
786
-}
787
-
788
-// Encode a slice of strings ([]string).
789
-func (o *Buffer) enc_slice_string(p *Properties, base structPointer) error {
790
- ss := *structPointer_StringSlice(base, p.field)
791
- l := len(ss)
792
- for i := 0; i < l; i++ {
793
- o.buf = append(o.buf, p.tagcode...)
794
- o.EncodeStringBytes(ss[i])
795
- }
796
- return nil
797
-}
798
-
799
-func size_slice_string(p *Properties, base structPointer) (n int) {
800
- ss := *structPointer_StringSlice(base, p.field)
801
- l := len(ss)
802
- n += l * len(p.tagcode)
803
- for i := 0; i < l; i++ {
804
- n += sizeStringBytes(ss[i])
805
- }
806
- return
807
-}
808
-
809
-// Encode a slice of message structs ([]*struct).
810
-func (o *Buffer) enc_slice_struct_message(p *Properties, base structPointer) error {
811
- var state errorState
812
- s := structPointer_StructPointerSlice(base, p.field)
813
- l := s.Len()
814
-
815
- for i := 0; i < l; i++ {
816
- structp := s.Index(i)
817
- if structPointer_IsNil(structp) {
818
- return ErrRepeatedHasNil
819
- }
820
-
821
- // Can the object marshal itself?
822
- if p.isMarshaler {
823
- m := structPointer_Interface(structp, p.stype).(Marshaler)
824
- data, err := m.Marshal()
825
- if err != nil && !state.shouldContinue(err, nil) {
826
- return err
827
- }
828
- o.buf = append(o.buf, p.tagcode...)
829
- o.EncodeRawBytes(data)
830
- continue
831
- }
832
-
833
- o.buf = append(o.buf, p.tagcode...)
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
838
- }
839
- return err
840
- }
841
- }
842
- return state.err
843
-}
844
-
845
-func size_slice_struct_message(p *Properties, base structPointer) (n int) {
846
- s := structPointer_StructPointerSlice(base, p.field)
847
- l := s.Len()
848
- n += l * len(p.tagcode)
849
- for i := 0; i < l; i++ {
850
- structp := s.Index(i)
851
- if structPointer_IsNil(structp) {
852
- return // return the size up to this point
853
- }
854
-
855
- // Can the object marshal itself?
856
- if p.isMarshaler {
857
- m := structPointer_Interface(structp, p.stype).(Marshaler)
858
- data, _ := m.Marshal()
859
- n += len(p.tagcode)
860
- n += sizeRawBytes(data)
861
- continue
862
- }
863
-
864
- n0 := size_struct(p.sprop, structp)
865
- n1 := sizeVarint(uint64(n0)) // size of encoded length
866
- n += n0 + n1
867
- }
868
- return
869
-}
870
-
871
-// Encode a slice of group structs ([]*struct).
872
-func (o *Buffer) enc_slice_struct_group(p *Properties, base structPointer) error {
873
- var state errorState
874
- s := structPointer_StructPointerSlice(base, p.field)
875
- l := s.Len()
876
-
877
- for i := 0; i < l; i++ {
878
- b := s.Index(i)
879
- if structPointer_IsNil(b) {
880
- return ErrRepeatedHasNil
881
- }
882
-
883
- o.EncodeVarint(uint64((p.Tag << 3) | WireStartGroup))
884
-
885
- err := o.enc_struct(p.sprop, b)
886
-
887
- if err != nil && !state.shouldContinue(err, nil) {
888
- if err == ErrNil {
889
- return ErrRepeatedHasNil
890
- }
891
- return err
892
- }
893
-
894
- o.EncodeVarint(uint64((p.Tag << 3) | WireEndGroup))
895
- }
896
- return state.err
897
-}
898
-
899
-func size_slice_struct_group(p *Properties, base structPointer) (n int) {
900
- s := structPointer_StructPointerSlice(base, p.field)
901
- l := s.Len()
902
-
903
- n += l * sizeVarint(uint64((p.Tag<<3)|WireStartGroup))
904
- n += l * sizeVarint(uint64((p.Tag<<3)|WireEndGroup))
905
- for i := 0; i < l; i++ {
906
- b := s.Index(i)
907
- if structPointer_IsNil(b) {
908
- return // return size up to this point
909
- }
910
-
911
- n += size_struct(p.sprop, b)
912
- }
913
- return
914
-}
915
-
916
-// Encode an extension map.
917
-func (o *Buffer) enc_map(p *Properties, base structPointer) error {
918
- v := *structPointer_ExtMap(base, p.field)
919
- if err := encodeExtensionMap(v); err != nil {
920
- return err
921
- }
922
- // Fast-path for common cases: zero or one extensions.
923
- if len(v) <= 1 {
924
- for _, e := range v {
925
- o.buf = append(o.buf, e.enc...)
926
- }
927
- return nil
928
- }
929
-
930
- // Sort keys to provide a deterministic encoding.
931
- keys := make([]int, 0, len(v))
932
- for k := range v {
933
- keys = append(keys, int(k))
934
- }
935
- sort.Ints(keys)
936
-
937
- for _, k := range keys {
938
- o.buf = append(o.buf, v[int32(k)].enc...)
939
- }
940
- return nil
941
-}
942
-
943
-func size_map(p *Properties, base structPointer) int {
944
- v := *structPointer_ExtMap(base, p.field)
945
- return sizeExtensionMap(v)
946
-}
947
-
948
-// Encode a struct.
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
- // 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 {
957
- err := p.enc(o, p, base)
958
- if err != nil {
959
- if err == ErrNil {
960
- if p.Required && state.err == nil {
961
- state.err = &RequiredNotSetError{p.Name}
962
- }
963
- } else if !state.shouldContinue(err, p) {
964
- return err
965
- }
966
- }
967
- }
968
- }
969
-
970
- // Add unrecognized fields at the end.
971
- if prop.unrecField.IsValid() {
972
- v := *structPointer_Bytes(base, prop.unrecField)
973
- if len(v) > 0 {
974
- o.buf = append(o.buf, v...)
975
- }
976
- }
977
-
978
- return state.err
979
-}
980
-
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 {
985
- n += p.size(p, base)
986
- }
987
- }
988
-
989
- // Add unrecognized fields at the end.
990
- if prop.unrecField.IsValid() {
991
- v := *structPointer_Bytes(base, prop.unrecField)
992
- n += len(v)
993
- }
994
-
995
- return
996
-}
997
-
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(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(prop, base)
1006
- if err != nil && !state.shouldContinue(err, nil) {
1007
- return err
1008
- }
1009
- lMsg := len(o.buf) - iMsg
1010
- lLen := sizeVarint(uint64(lMsg))
1011
- switch x := lLen - (iMsg - iLen); {
1012
- case x > 0: // actual length is x bytes larger than the space we reserved
1013
- // Move msg x bytes right.
1014
- o.buf = append(o.buf, zeroes[:x]...)
1015
- copy(o.buf[iMsg+x:], o.buf[iMsg:iMsg+lMsg])
1016
- case x < 0: // actual length is x bytes smaller than the space we reserved
1017
- // Move msg x bytes left.
1018
- copy(o.buf[iMsg+x:], o.buf[iMsg:iMsg+lMsg])
1019
- o.buf = o.buf[:len(o.buf)+x] // x is negative
1020
- }
1021
- // Encode the length in the reserved space.
1022
- o.buf = o.buf[:iLen]
1023
- o.EncodeVarint(uint64(lMsg))
1024
- o.buf = o.buf[:len(o.buf)+lMsg]
1025
- return state.err
1026
-}
1027
-
1028
-// errorState maintains the first error that occurs and updates that error
1029
-// with additional context.
1030
-type errorState struct {
1031
- err error
1032
-}
1033
-
1034
-// shouldContinue reports whether encoding should continue upon encountering the
1035
-// given error. If the error is RequiredNotSetError, shouldContinue returns true
1036
-// and, if this is the first appearance of that error, remembers it for future
1037
-// reporting.
1038
-//
1039
-// If prop is not nil, it may update any error with additional context about the
1040
-// field with the error.
1041
-func (s *errorState) shouldContinue(err error, prop *Properties) bool {
1042
- // Ignore unset required fields.
1043
- reqNotSet, ok := err.(*RequiredNotSetError)
1044
- if !ok {
1045
- return false
1046
- }
1047
- if s.err == nil {
1048
- if prop != nil {
1049
- err = &RequiredNotSetError{prop.Name + "." + reqNotSet.field}
1050
- }
1051
- s.err = err
1052
- }
1053
- return true
1054
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/encode_gogo.go
deleted
-383
@@ -1,383 +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://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://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
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
-import (
40
- "reflect"
41
-)
42
-
43
-type Sizer interface {
44
- Size() int
45
-}
46
-
47
-func (o *Buffer) enc_ext_slice_byte(p *Properties, base structPointer) error {
48
- s := *structPointer_Bytes(base, p.field)
49
- if s == nil {
50
- return ErrNil
51
- }
52
- o.buf = append(o.buf, s...)
53
- return nil
54
-}
55
-
56
-func size_ext_slice_byte(p *Properties, base structPointer) (n int) {
57
- s := *structPointer_Bytes(base, p.field)
58
- if s == nil {
59
- return 0
60
- }
61
- n += len(s)
62
- return
63
-}
64
-
65
-// Encode a reference to bool pointer.
66
-func (o *Buffer) enc_ref_bool(p *Properties, base structPointer) error {
67
- v := structPointer_RefBool(base, p.field)
68
- if v == nil {
69
- return ErrNil
70
- }
71
- x := 0
72
- if *v {
73
- x = 1
74
- }
75
- o.buf = append(o.buf, p.tagcode...)
76
- p.valEnc(o, uint64(x))
77
- return nil
78
-}
79
-
80
-func size_ref_bool(p *Properties, base structPointer) int {
81
- v := structPointer_RefBool(base, p.field)
82
- if v == nil {
83
- return 0
84
- }
85
- return len(p.tagcode) + 1 // each bool takes exactly one byte
86
-}
87
-
88
-// Encode a reference to int32 pointer.
89
-func (o *Buffer) enc_ref_int32(p *Properties, base structPointer) error {
90
- v := structPointer_RefWord32(base, p.field)
91
- if refWord32_IsNil(v) {
92
- return ErrNil
93
- }
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
126
- }
127
- x := refWord32_Get(v)
128
- n += len(p.tagcode)
129
- n += p.valSize(uint64(x))
130
- return
131
-}
132
-
133
-// Encode a reference to an int64 pointer.
134
-func (o *Buffer) enc_ref_int64(p *Properties, base structPointer) error {
135
- v := structPointer_RefWord64(base, p.field)
136
- if refWord64_IsNil(v) {
137
- return ErrNil
138
- }
139
- x := refWord64_Get(v)
140
- o.buf = append(o.buf, p.tagcode...)
141
- p.valEnc(o, x)
142
- return nil
143
-}
144
-
145
-func size_ref_int64(p *Properties, base structPointer) (n int) {
146
- v := structPointer_RefWord64(base, p.field)
147
- if refWord64_IsNil(v) {
148
- return 0
149
- }
150
- x := refWord64_Get(v)
151
- n += len(p.tagcode)
152
- n += p.valSize(x)
153
- return
154
-}
155
-
156
-// Encode a reference to a string pointer.
157
-func (o *Buffer) enc_ref_string(p *Properties, base structPointer) error {
158
- v := structPointer_RefString(base, p.field)
159
- if v == nil {
160
- return ErrNil
161
- }
162
- x := *v
163
- o.buf = append(o.buf, p.tagcode...)
164
- o.EncodeStringBytes(x)
165
- return nil
166
-}
167
-
168
-func size_ref_string(p *Properties, base structPointer) (n int) {
169
- v := structPointer_RefString(base, p.field)
170
- if v == nil {
171
- return 0
172
- }
173
- x := *v
174
- n += len(p.tagcode)
175
- n += sizeStringBytes(x)
176
- return
177
-}
178
-
179
-// Encode a reference to a message struct.
180
-func (o *Buffer) enc_ref_struct_message(p *Properties, base structPointer) error {
181
- var state errorState
182
- structp := structPointer_GetRefStructPointer(base, p.field)
183
- if structPointer_IsNil(structp) {
184
- return ErrNil
185
- }
186
-
187
- // Can the object marshal itself?
188
- if p.isMarshaler {
189
- m := structPointer_Interface(structp, p.stype).(Marshaler)
190
- data, err := m.Marshal()
191
- if err != nil && !state.shouldContinue(err, nil) {
192
- return err
193
- }
194
- o.buf = append(o.buf, p.tagcode...)
195
- o.EncodeRawBytes(data)
196
- return nil
197
- }
198
-
199
- o.buf = append(o.buf, p.tagcode...)
200
- return o.enc_len_struct(p.sprop, structp, &state)
201
-}
202
-
203
-//TODO this is only copied, please fix this
204
-func size_ref_struct_message(p *Properties, base structPointer) int {
205
- structp := structPointer_GetRefStructPointer(base, p.field)
206
- if structPointer_IsNil(structp) {
207
- return 0
208
- }
209
-
210
- // Can the object marshal itself?
211
- if p.isMarshaler {
212
- m := structPointer_Interface(structp, p.stype).(Marshaler)
213
- data, _ := m.Marshal()
214
- n0 := len(p.tagcode)
215
- n1 := sizeRawBytes(data)
216
- return n0 + n1
217
- }
218
-
219
- n0 := len(p.tagcode)
220
- n1 := size_struct(p.sprop, structp)
221
- n2 := sizeVarint(uint64(n1)) // size of encoded length
222
- return n0 + n1 + n2
223
-}
224
-
225
-// Encode a slice of references to message struct pointers ([]struct).
226
-func (o *Buffer) enc_slice_ref_struct_message(p *Properties, base structPointer) error {
227
- var state errorState
228
- ss := structPointer_GetStructPointer(base, p.field)
229
- ss1 := structPointer_GetRefStructPointer(ss, field(0))
230
- size := p.stype.Size()
231
- l := structPointer_Len(base, p.field)
232
- for i := 0; i < l; i++ {
233
- structp := structPointer_Add(ss1, field(uintptr(i)*size))
234
- if structPointer_IsNil(structp) {
235
- return ErrRepeatedHasNil
236
- }
237
-
238
- // Can the object marshal itself?
239
- if p.isMarshaler {
240
- m := structPointer_Interface(structp, p.stype).(Marshaler)
241
- data, err := m.Marshal()
242
- if err != nil && !state.shouldContinue(err, nil) {
243
- return err
244
- }
245
- o.buf = append(o.buf, p.tagcode...)
246
- o.EncodeRawBytes(data)
247
- continue
248
- }
249
-
250
- o.buf = append(o.buf, p.tagcode...)
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
255
- }
256
- return err
257
- }
258
-
259
- }
260
- return state.err
261
-}
262
-
263
-//TODO this is only copied, please fix this
264
-func size_slice_ref_struct_message(p *Properties, base structPointer) (n int) {
265
- ss := structPointer_GetStructPointer(base, p.field)
266
- ss1 := structPointer_GetRefStructPointer(ss, field(0))
267
- size := p.stype.Size()
268
- l := structPointer_Len(base, p.field)
269
- n += l * len(p.tagcode)
270
- for i := 0; i < l; i++ {
271
- structp := structPointer_Add(ss1, field(uintptr(i)*size))
272
- if structPointer_IsNil(structp) {
273
- return // return the size up to this point
274
- }
275
-
276
- // Can the object marshal itself?
277
- if p.isMarshaler {
278
- m := structPointer_Interface(structp, p.stype).(Marshaler)
279
- data, _ := m.Marshal()
280
- n += len(p.tagcode)
281
- n += sizeRawBytes(data)
282
- continue
283
- }
284
-
285
- n0 := size_struct(p.sprop, structp)
286
- n1 := sizeVarint(uint64(n0)) // size of encoded length
287
- n += n0 + n1
288
- }
289
- return
290
-}
291
-
292
-func (o *Buffer) enc_custom_bytes(p *Properties, base structPointer) error {
293
- i := structPointer_InterfaceRef(base, p.field, p.ctype)
294
- if i == nil {
295
- return ErrNil
296
- }
297
- custom := i.(Marshaler)
298
- data, err := custom.Marshal()
299
- if err != nil {
300
- return err
301
- }
302
- if data == nil {
303
- return ErrNil
304
- }
305
- o.buf = append(o.buf, p.tagcode...)
306
- o.EncodeRawBytes(data)
307
- return nil
308
-}
309
-
310
-func size_custom_bytes(p *Properties, base structPointer) (n int) {
311
- n += len(p.tagcode)
312
- i := structPointer_InterfaceRef(base, p.field, p.ctype)
313
- if i == nil {
314
- return 0
315
- }
316
- custom := i.(Marshaler)
317
- data, _ := custom.Marshal()
318
- n += sizeRawBytes(data)
319
- return
320
-}
321
-
322
-func (o *Buffer) enc_custom_ref_bytes(p *Properties, base structPointer) error {
323
- custom := structPointer_InterfaceAt(base, p.field, p.ctype).(Marshaler)
324
- data, err := custom.Marshal()
325
- if err != nil {
326
- return err
327
- }
328
- if data == nil {
329
- return ErrNil
330
- }
331
- o.buf = append(o.buf, p.tagcode...)
332
- o.EncodeRawBytes(data)
333
- return nil
334
-}
335
-
336
-func size_custom_ref_bytes(p *Properties, base structPointer) (n int) {
337
- n += len(p.tagcode)
338
- i := structPointer_InterfaceAt(base, p.field, p.ctype)
339
- if i == nil {
340
- return 0
341
- }
342
- custom := i.(Marshaler)
343
- data, _ := custom.Marshal()
344
- n += sizeRawBytes(data)
345
- return
346
-}
347
-
348
-func (o *Buffer) enc_custom_slice_bytes(p *Properties, base structPointer) error {
349
- inter := structPointer_InterfaceRef(base, p.field, p.ctype)
350
- if inter == nil {
351
- return ErrNil
352
- }
353
- slice := reflect.ValueOf(inter)
354
- l := slice.Len()
355
- for i := 0; i < l; i++ {
356
- v := slice.Index(i)
357
- custom := v.Interface().(Marshaler)
358
- data, err := custom.Marshal()
359
- if err != nil {
360
- return err
361
- }
362
- o.buf = append(o.buf, p.tagcode...)
363
- o.EncodeRawBytes(data)
364
- }
365
- return nil
366
-}
367
-
368
-func size_custom_slice_bytes(p *Properties, base structPointer) (n int) {
369
- inter := structPointer_InterfaceRef(base, p.field, p.ctype)
370
- if inter == nil {
371
- return 0
372
- }
373
- slice := reflect.ValueOf(inter)
374
- l := slice.Len()
375
- n += l * len(p.tagcode)
376
- for i := 0; i < l; i++ {
377
- v := slice.Index(i)
378
- custom := v.Interface().(Marshaler)
379
- data, _ := custom.Marshal()
380
- n += sizeRawBytes(data)
381
- }
382
- return
383
-}
Godeps/_workspace/src/github.com/gogo/protobuf/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
-// 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
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.
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/github.com/gogo/protobuf/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
-// 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
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/github.com/gogo/protobuf/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/github.com/gogo/protobuf/proto/extensions.go
deleted
-472
@@ -1,472 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
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
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
-}
59
-
60
-type extensionsMap interface {
61
- extendableProto
62
- ExtensionMap() map[int32]Extension
63
-}
64
-
65
-type extensionsBytes interface {
66
- extendableProto
67
- GetExtensions() *[]byte
68
-}
69
-
70
-var extendableProtoType = reflect.TypeOf((*extendableProto)(nil)).Elem()
71
-
72
-// ExtensionDesc represents an extension specification.
73
-// Used in generated code from the protocol compiler.
74
-type ExtensionDesc struct {
75
- ExtendedType Message // nil pointer to the type that is being extended
76
- ExtensionType interface{} // nil pointer to the extension type
77
- Field int32 // field number
78
- Name string // fully-qualified name of extension, for text formatting
79
- Tag string // protobuf tag style
80
-}
81
-
82
-func (ed *ExtensionDesc) repeated() bool {
83
- t := reflect.TypeOf(ed.ExtensionType)
84
- return t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8
85
-}
86
-
87
-// Extension represents an extension in a message.
88
-type Extension struct {
89
- // When an extension is stored in a message using SetExtension
90
- // only desc and value are set. When the message is marshaled
91
- // enc will be set to the encoded form of the message.
92
- //
93
- // When a message is unmarshaled and contains extensions, each
94
- // extension will have only enc set. When such an extension is
95
- // accessed using GetExtension (or GetExtensions) desc and value
96
- // will be set.
97
- desc *ExtensionDesc
98
- value interface{}
99
- enc []byte
100
-}
101
-
102
-// SetRawExtension is for testing only.
103
-func SetRawExtension(base extendableProto, id int32, b []byte) {
104
- if ebase, ok := base.(extensionsMap); ok {
105
- ebase.ExtensionMap()[id] = Extension{enc: b}
106
- } else if ebase, ok := base.(extensionsBytes); ok {
107
- clearExtension(base, id)
108
- ext := ebase.GetExtensions()
109
- *ext = append(*ext, b...)
110
- } else {
111
- panic("unreachable")
112
- }
113
-}
114
-
115
-// isExtensionField returns true iff the given field number is in an extension range.
116
-func isExtensionField(pb extendableProto, field int32) bool {
117
- for _, er := range pb.ExtensionRangeArray() {
118
- if er.Start <= field && field <= er.End {
119
- return true
120
- }
121
- }
122
- return false
123
-}
124
-
125
-// checkExtensionTypes checks that the given extension is valid for pb.
126
-func checkExtensionTypes(pb extendableProto, extension *ExtensionDesc) error {
127
- // Check the extended type.
128
- if a, b := reflect.TypeOf(pb), reflect.TypeOf(extension.ExtendedType); a != b {
129
- return errors.New("proto: bad extended type; " + b.String() + " does not extend " + a.String())
130
- }
131
- // Check the range.
132
- if !isExtensionField(pb, extension.Field) {
133
- return errors.New("proto: bad extension number; not in declared ranges")
134
- }
135
- return nil
136
-}
137
-
138
-// extPropKey is sufficient to uniquely identify an extension.
139
-type extPropKey struct {
140
- base reflect.Type
141
- field int32
142
-}
143
-
144
-var extProp = struct {
145
- sync.RWMutex
146
- m map[extPropKey]*Properties
147
-}{
148
- m: make(map[extPropKey]*Properties),
149
-}
150
-
151
-func extensionProperties(ed *ExtensionDesc) *Properties {
152
- key := extPropKey{base: reflect.TypeOf(ed.ExtendedType), field: ed.Field}
153
-
154
- extProp.RLock()
155
- if prop, ok := extProp.m[key]; ok {
156
- extProp.RUnlock()
157
- return prop
158
- }
159
- extProp.RUnlock()
160
-
161
- extProp.Lock()
162
- defer extProp.Unlock()
163
- // Check again.
164
- if prop, ok := extProp.m[key]; ok {
165
- return prop
166
- }
167
-
168
- prop := new(Properties)
169
- prop.Init(reflect.TypeOf(ed.ExtensionType), "unknown_name", ed.Tag, nil)
170
- extProp.m[key] = prop
171
- return prop
172
-}
173
-
174
-// encodeExtensionMap encodes any unmarshaled (unencoded) extensions in m.
175
-func encodeExtensionMap(m map[int32]Extension) error {
176
- for k, e := range m {
177
- err := encodeExtension(&e)
178
- if err != nil {
179
- return err
180
- }
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 {
213
- // Extension is only in its encoded form.
214
- n += len(e.enc)
215
- continue
216
- }
217
-
218
- // We don't skip extensions that have an encoded form set,
219
- // because the extension value may have been mutated after
220
- // the last time this function was called.
221
-
222
- et := reflect.TypeOf(e.desc.ExtensionType)
223
- props := extensionProperties(e.desc)
224
-
225
- // If e.value has type T, the encoder expects a *struct{ X T }.
226
- // Pass a *T with a zero field and hope it all works out.
227
- x := reflect.New(et)
228
- x.Elem().Set(reflect.ValueOf(e.value))
229
- n += props.size(props, toStructPointer(x))
230
- }
231
- return
232
-}
233
-
234
-// HasExtension returns whether the given extension is present in pb.
235
-func HasExtension(pb extendableProto, extension *ExtensionDesc) bool {
236
- // TODO: Check types, field numbers, etc.?
237
- if epb, doki := pb.(extensionsMap); doki {
238
- _, ok := epb.ExtensionMap()[extension.Field]
239
- return ok
240
- } else if epb, doki := pb.(extensionsBytes); doki {
241
- ext := epb.GetExtensions()
242
- buf := *ext
243
- o := 0
244
- for o < len(buf) {
245
- tag, n := DecodeVarint(buf[o:])
246
- fieldNum := int32(tag >> 3)
247
- if int32(fieldNum) == extension.Field {
248
- return true
249
- }
250
- wireType := int(tag & 0x7)
251
- o += n
252
- l, err := size(buf[o:], wireType)
253
- if err != nil {
254
- return false
255
- }
256
- o += l
257
- }
258
- return false
259
- }
260
- panic("unreachable")
261
-}
262
-
263
-func deleteExtension(pb extensionsBytes, theFieldNum int32, offset int) int {
264
- ext := pb.GetExtensions()
265
- for offset < len(*ext) {
266
- tag, n1 := DecodeVarint((*ext)[offset:])
267
- fieldNum := int32(tag >> 3)
268
- wireType := int(tag & 0x7)
269
- n2, err := size((*ext)[offset+n1:], wireType)
270
- if err != nil {
271
- panic(err)
272
- }
273
- newOffset := offset + n1 + n2
274
- if fieldNum == theFieldNum {
275
- *ext = append((*ext)[:offset], (*ext)[newOffset:]...)
276
- return offset
277
- }
278
- offset = newOffset
279
- }
280
- return -1
281
-}
282
-
283
-func clearExtension(pb extendableProto, fieldNum int32) {
284
- if epb, doki := pb.(extensionsMap); doki {
285
- delete(epb.ExtensionMap(), fieldNum)
286
- } else if epb, doki := pb.(extensionsBytes); doki {
287
- offset := 0
288
- for offset != -1 {
289
- offset = deleteExtension(epb, fieldNum, offset)
290
- }
291
- } else {
292
- panic("unreachable")
293
- }
294
-}
295
-
296
-// ClearExtension removes the given extension from pb.
297
-func ClearExtension(pb extendableProto, extension *ExtensionDesc) {
298
- // TODO: Check types, field numbers, etc.?
299
- clearExtension(pb, extension.Field)
300
-}
301
-
302
-// GetExtension parses and returns the given extension of pb.
303
-// If the extension is not present it returns ErrMissingExtension.
304
-func GetExtension(pb extendableProto, extension *ExtensionDesc) (interface{}, error) {
305
- if err := checkExtensionTypes(pb, extension); err != nil {
306
- return nil, err
307
- }
308
-
309
- if epb, doki := pb.(extensionsMap); doki {
310
- emap := epb.ExtensionMap()
311
- e, ok := emap[extension.Field]
312
- if !ok {
313
- return nil, ErrMissingExtension
314
- }
315
- if e.value != nil {
316
- // Already decoded. Check the descriptor, though.
317
- if e.desc != extension {
318
- // This shouldn't happen. If it does, it means that
319
- // GetExtension was called twice with two different
320
- // descriptors with the same field number.
321
- return nil, errors.New("proto: descriptor conflict")
322
- }
323
- return e.value, nil
324
- }
325
-
326
- v, err := decodeExtension(e.enc, extension)
327
- if err != nil {
328
- return nil, err
329
- }
330
-
331
- // Remember the decoded version and drop the encoded version.
332
- // That way it is safe to mutate what we return.
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()
340
- o := 0
341
- for o < len(*ext) {
342
- tag, n := DecodeVarint((*ext)[o:])
343
- fieldNum := int32(tag >> 3)
344
- wireType := int(tag & 0x7)
345
- l, err := size((*ext)[o+n:], wireType)
346
- if err != nil {
347
- return nil, err
348
- }
349
- if int32(fieldNum) == extension.Field {
350
- v, err := decodeExtension((*ext)[o:o+n+l], extension)
351
- if err != nil {
352
- return nil, err
353
- }
354
- return v, nil
355
- }
356
- o += n + l
357
- }
358
- }
359
- panic("unreachable")
360
-}
361
-
362
-// decodeExtension decodes an extension encoded in b.
363
-func decodeExtension(b []byte, extension *ExtensionDesc) (interface{}, error) {
364
- o := NewBuffer(b)
365
-
366
- t := reflect.TypeOf(extension.ExtensionType)
367
- rep := extension.repeated()
368
-
369
- props := extensionProperties(extension)
370
-
371
- // t is a pointer to a struct, pointer to basic type or a slice.
372
- // Allocate a "field" to store the pointer/slice itself; the
373
- // pointer/slice will be stored here. We pass
374
- // the address of this field to props.dec.
375
- // This passes a zero field and a *t and lets props.dec
376
- // interpret it as a *struct{ x t }.
377
- value := reflect.New(t).Elem()
378
-
379
- for {
380
- // Discard wire type and field number varint. It isn't needed.
381
- if _, err := o.DecodeVarint(); err != nil {
382
- return nil, err
383
- }
384
-
385
- if err := props.dec(o, props, toStructPointer(value.Addr())); err != nil {
386
- return nil, err
387
- }
388
-
389
- if !rep || o.index >= len(o.buf) {
390
- break
391
- }
392
- }
393
- return value.Interface(), nil
394
-}
395
-
396
-// GetExtensions returns a slice of the extensions present in pb that are also listed in es.
397
-// The returned slice has the same length as es; missing extensions will appear as nil elements.
398
-func GetExtensions(pb Message, es []*ExtensionDesc) (extensions []interface{}, err error) {
399
- epb, ok := pb.(extendableProto)
400
- if !ok {
401
- err = errors.New("proto: not an extendable proto")
402
- return
403
- }
404
- extensions = make([]interface{}, len(es))
405
- for i, e := range es {
406
- extensions[i], err = GetExtension(epb, e)
407
- if err == ErrMissingExtension {
408
- err = nil
409
- }
410
- if err != nil {
411
- return
412
- }
413
- }
414
- return
415
-}
416
-
417
-// SetExtension sets the specified extension of pb to the specified value.
418
-func SetExtension(pb extendableProto, extension *ExtensionDesc, value interface{}) error {
419
- if err := checkExtensionTypes(pb, extension); err != nil {
420
- return err
421
- }
422
- typ := reflect.TypeOf(extension.ExtensionType)
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 {
433
- ClearExtension(pb, extension)
434
- ext := epb.GetExtensions()
435
- et := reflect.TypeOf(extension.ExtensionType)
436
- props := extensionProperties(extension)
437
- p := NewBuffer(nil)
438
- x := reflect.New(et)
439
- x.Elem().Set(reflect.ValueOf(value))
440
- if err := props.enc(p, props, toStructPointer(x)); err != nil {
441
- return err
442
- }
443
- *ext = append(*ext, p.buf...)
444
- }
445
- return nil
446
-}
447
-
448
-// A global registry of extensions.
449
-// The generated code will register the generated descriptors by calling RegisterExtension.
450
-
451
-var extensionMaps = make(map[reflect.Type]map[int32]*ExtensionDesc)
452
-
453
-// RegisterExtension is called from the generated code.
454
-func RegisterExtension(desc *ExtensionDesc) {
455
- st := reflect.TypeOf(desc.ExtendedType).Elem()
456
- m := extensionMaps[st]
457
- if m == nil {
458
- m = make(map[int32]*ExtensionDesc)
459
- extensionMaps[st] = m
460
- }
461
- if _, ok := m[desc.Field]; ok {
462
- panic("proto: duplicate extension registered: " + st.String() + " " + strconv.Itoa(int(desc.Field)))
463
- }
464
- m[desc.Field] = desc
465
-}
466
-
467
-// RegisteredExtensions returns a map of the registered extensions of a
468
-// protocol buffer struct, indexed by the extension number.
469
-// The argument pb should be a nil pointer to the struct type.
470
-func RegisteredExtensions(pb Message) map[int32]*ExtensionDesc {
471
- return extensionMaps[reflect.TypeOf(pb).Elem()]
472
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/extensions_gogo.go
deleted
-221
@@ -1,221 +0,0 @@
1
-// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
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
6
-// met:
7
-//
8
-// * Redistributions of source code must retain the above copyright
9
-// notice, this list of conditions and the following disclaimer.
10
-// * Redistributions in binary form must reproduce the above
11
-// copyright notice, this list of conditions and the following disclaimer
12
-// in the documentation and/or other materials provided with the
13
-// distribution.
14
-//
15
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
-
27
-package proto
28
-
29
-import (
30
- "bytes"
31
- "errors"
32
- "fmt"
33
- "reflect"
34
- "sort"
35
- "strings"
36
-)
37
-
38
-func GetBoolExtension(pb extendableProto, extension *ExtensionDesc, ifnotset bool) bool {
39
- if reflect.ValueOf(pb).IsNil() {
40
- return ifnotset
41
- }
42
- value, err := GetExtension(pb, extension)
43
- if err != nil {
44
- return ifnotset
45
- }
46
- if value == nil {
47
- return ifnotset
48
- }
49
- if value.(*bool) == nil {
50
- return ifnotset
51
- }
52
- return *(value.(*bool))
53
-}
54
-
55
-func (this *Extension) Equal(that *Extension) bool {
56
- return bytes.Equal(this.enc, that.enc)
57
-}
58
-
59
-func SizeOfExtensionMap(m map[int32]Extension) (n int) {
60
- return sizeExtensionMap(m)
61
-}
62
-
63
-type sortableMapElem struct {
64
- field int32
65
- ext Extension
66
-}
67
-
68
-func newSortableExtensionsFromMap(m map[int32]Extension) sortableExtensions {
69
- s := make(sortableExtensions, 0, len(m))
70
- for k, v := range m {
71
- s = append(s, &sortableMapElem{field: k, ext: v})
72
- }
73
- return s
74
-}
75
-
76
-type sortableExtensions []*sortableMapElem
77
-
78
-func (this sortableExtensions) Len() int { return len(this) }
79
-
80
-func (this sortableExtensions) Swap(i, j int) { this[i], this[j] = this[j], this[i] }
81
-
82
-func (this sortableExtensions) Less(i, j int) bool { return this[i].field < this[j].field }
83
-
84
-func (this sortableExtensions) String() string {
85
- sort.Sort(this)
86
- ss := make([]string, len(this))
87
- for i := range this {
88
- ss[i] = fmt.Sprintf("%d: %v", this[i].field, this[i].ext)
89
- }
90
- return "map[" + strings.Join(ss, ",") + "]"
91
-}
92
-
93
-func StringFromExtensionsMap(m map[int32]Extension) string {
94
- return newSortableExtensionsFromMap(m).String()
95
-}
96
-
97
-func StringFromExtensionsBytes(ext []byte) string {
98
- m, err := BytesToExtensionsMap(ext)
99
- if err != nil {
100
- panic(err)
101
- }
102
- return StringFromExtensionsMap(m)
103
-}
104
-
105
-func EncodeExtensionMap(m map[int32]Extension, data []byte) (n int, err error) {
106
- if err := encodeExtensionMap(m); err != nil {
107
- return 0, err
108
- }
109
- keys := make([]int, 0, len(m))
110
- for k := range m {
111
- keys = append(keys, int(k))
112
- }
113
- sort.Ints(keys)
114
- for _, k := range keys {
115
- n += copy(data[n:], m[int32(k)].enc)
116
- }
117
- return n, nil
118
-}
119
-
120
-func GetRawExtension(m map[int32]Extension, id int32) ([]byte, error) {
121
- if m[id].value == nil || m[id].desc == nil {
122
- return m[id].enc, nil
123
- }
124
- if err := encodeExtensionMap(m); err != nil {
125
- return nil, err
126
- }
127
- return m[id].enc, nil
128
-}
129
-
130
-func size(buf []byte, wire int) (int, error) {
131
- switch wire {
132
- case WireVarint:
133
- _, n := DecodeVarint(buf)
134
- return n, nil
135
- case WireFixed64:
136
- return 8, nil
137
- case WireBytes:
138
- v, n := DecodeVarint(buf)
139
- return int(v) + n, nil
140
- case WireFixed32:
141
- return 4, nil
142
- case WireStartGroup:
143
- offset := 0
144
- for {
145
- u, n := DecodeVarint(buf[offset:])
146
- fwire := int(u & 0x7)
147
- offset += n
148
- if fwire == WireEndGroup {
149
- return offset, nil
150
- }
151
- s, err := size(buf[offset:], wire)
152
- if err != nil {
153
- return 0, err
154
- }
155
- offset += s
156
- }
157
- }
158
- return 0, fmt.Errorf("proto: can't get size for unknown wire type %d", wire)
159
-}
160
-
161
-func BytesToExtensionsMap(buf []byte) (map[int32]Extension, error) {
162
- m := make(map[int32]Extension)
163
- i := 0
164
- for i < len(buf) {
165
- tag, n := DecodeVarint(buf[i:])
166
- if n <= 0 {
167
- return nil, fmt.Errorf("unable to decode varint")
168
- }
169
- fieldNum := int32(tag >> 3)
170
- wireType := int(tag & 0x7)
171
- l, err := size(buf[i+n:], wireType)
172
- if err != nil {
173
- return nil, err
174
- }
175
- end := i + int(l) + n
176
- m[int32(fieldNum)] = Extension{enc: buf[i:end]}
177
- i = end
178
- }
179
- return m, nil
180
-}
181
-
182
-func NewExtension(e []byte) Extension {
183
- ee := Extension{enc: make([]byte, len(e))}
184
- copy(ee.enc, e)
185
- return ee
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
deleted
-94
@@ -1,94 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2014 The Go Authors. All rights reserved.
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
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/github.com/gogo/protobuf/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
-}
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
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
-// 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
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 "github.com/gogo/protobuf/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
- "github.com/gogo/protobuf/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.HasDefault {
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/github.com/gogo/protobuf/proto/lib_gogo.go
deleted
-40
@@ -1,40 +0,0 @@
1
-// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
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
6
-// met:
7
-//
8
-// * Redistributions of source code must retain the above copyright
9
-// notice, this list of conditions and the following disclaimer.
10
-// * Redistributions in binary form must reproduce the above
11
-// copyright notice, this list of conditions and the following disclaimer
12
-// in the documentation and/or other materials provided with the
13
-// distribution.
14
-//
15
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
-
27
-package proto
28
-
29
-import (
30
- "encoding/json"
31
- "strconv"
32
-)
33
-
34
-func MarshalJSONEnum(m map[int32]string, value int32) ([]byte, error) {
35
- s, ok := m[value]
36
- if !ok {
37
- s = strconv.Itoa(int(value))
38
- }
39
- return json.Marshal(s)
40
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/message_set.go
deleted
-287
@@ -1,287 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
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
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
- "bytes"
40
- "encoding/json"
41
- "errors"
42
- "fmt"
43
- "reflect"
44
- "sort"
45
-)
46
-
47
-// ErrNoMessageTypeId occurs when a protocol buffer does not have a message type ID.
48
-// A message type ID is required for storing a protocol buffer in a message set.
49
-var ErrNoMessageTypeId = errors.New("proto does not have a message type ID")
50
-
51
-// The first two types (_MessageSet_Item and MessageSet)
52
-// model what the protocol compiler produces for the following protocol message:
53
-// message MessageSet {
54
-// repeated group Item = 1 {
55
-// required int32 type_id = 2;
56
-// required string message = 3;
57
-// };
58
-// }
59
-// That is the MessageSet wire format. We can't use a proto to generate these
60
-// because that would introduce a circular dependency between it and this package.
61
-//
62
-// When a proto1 proto has a field that looks like:
63
-// optional message<MessageSet> info = 3;
64
-// the protocol compiler produces a field in the generated struct that looks like:
65
-// Info *_proto_.MessageSet `protobuf:"bytes,3,opt,name=info"`
66
-// The package is automatically inserted so there is no need for that proto file to
67
-// import this package.
68
-
69
-type _MessageSet_Item struct {
70
- TypeId *int32 `protobuf:"varint,2,req,name=type_id"`
71
- Message []byte `protobuf:"bytes,3,req,name=message"`
72
-}
73
-
74
-type MessageSet struct {
75
- Item []*_MessageSet_Item `protobuf:"group,1,rep"`
76
- XXX_unrecognized []byte
77
- // TODO: caching?
78
-}
79
-
80
-// Make sure MessageSet is a Message.
81
-var _ Message = (*MessageSet)(nil)
82
-
83
-// messageTypeIder is an interface satisfied by a protocol buffer type
84
-// that may be stored in a MessageSet.
85
-type messageTypeIder interface {
86
- MessageTypeId() int32
87
-}
88
-
89
-func (ms *MessageSet) find(pb Message) *_MessageSet_Item {
90
- mti, ok := pb.(messageTypeIder)
91
- if !ok {
92
- return nil
93
- }
94
- id := mti.MessageTypeId()
95
- for _, item := range ms.Item {
96
- if *item.TypeId == id {
97
- return item
98
- }
99
- }
100
- return nil
101
-}
102
-
103
-func (ms *MessageSet) Has(pb Message) bool {
104
- if ms.find(pb) != nil {
105
- return true
106
- }
107
- return false
108
-}
109
-
110
-func (ms *MessageSet) Unmarshal(pb Message) error {
111
- if item := ms.find(pb); item != nil {
112
- return Unmarshal(item.Message, pb)
113
- }
114
- if _, ok := pb.(messageTypeIder); !ok {
115
- return ErrNoMessageTypeId
116
- }
117
- return nil // TODO: return error instead?
118
-}
119
-
120
-func (ms *MessageSet) Marshal(pb Message) error {
121
- msg, err := Marshal(pb)
122
- if err != nil {
123
- return err
124
- }
125
- if item := ms.find(pb); item != nil {
126
- // reuse existing item
127
- item.Message = msg
128
- return nil
129
- }
130
-
131
- mti, ok := pb.(messageTypeIder)
132
- if !ok {
133
- return ErrNoMessageTypeId
134
- }
135
-
136
- mtid := mti.MessageTypeId()
137
- ms.Item = append(ms.Item, &_MessageSet_Item{
138
- TypeId: &mtid,
139
- Message: msg,
140
- })
141
- return nil
142
-}
143
-
144
-func (ms *MessageSet) Reset() { *ms = MessageSet{} }
145
-func (ms *MessageSet) String() string { return CompactTextString(ms) }
146
-func (*MessageSet) ProtoMessage() {}
147
-
148
-// Support for the message_set_wire_format message option.
149
-
150
-func skipVarint(buf []byte) []byte {
151
- i := 0
152
- for ; buf[i]&0x80 != 0; i++ {
153
- }
154
- return buf[i+1:]
155
-}
156
-
157
-// MarshalMessageSet encodes the extension map represented by m in the message set wire format.
158
-// It is called by generated Marshal methods on protocol buffer messages with the message_set_wire_format option.
159
-func MarshalMessageSet(m map[int32]Extension) ([]byte, error) {
160
- if err := encodeExtensionMap(m); err != nil {
161
- return nil, err
162
- }
163
-
164
- // Sort extension IDs to provide a deterministic encoding.
165
- // See also enc_map in encode.go.
166
- ids := make([]int, 0, len(m))
167
- for id := range m {
168
- ids = append(ids, int(id))
169
- }
170
- sort.Ints(ids)
171
-
172
- ms := &MessageSet{Item: make([]*_MessageSet_Item, 0, len(m))}
173
- for _, id := range ids {
174
- e := m[int32(id)]
175
- // Remove the wire type and field number varint, as well as the length varint.
176
- msg := skipVarint(skipVarint(e.enc))
177
-
178
- ms.Item = append(ms.Item, &_MessageSet_Item{
179
- TypeId: Int32(int32(id)),
180
- Message: msg,
181
- })
182
- }
183
- return Marshal(ms)
184
-}
185
-
186
-// UnmarshalMessageSet decodes the extension map encoded in buf in the message set wire format.
187
-// It is called by generated Unmarshal methods on protocol buffer messages with the message_set_wire_format option.
188
-func UnmarshalMessageSet(buf []byte, m map[int32]Extension) error {
189
- ms := new(MessageSet)
190
- if err := Unmarshal(buf, ms); err != nil {
191
- return err
192
- }
193
- for _, item := range ms.Item {
194
- id := *item.TypeId
195
- msg := item.Message
196
-
197
- // Restore wire type and field number varint, plus length varint.
198
- // Be careful to preserve duplicate items.
199
- b := EncodeVarint(uint64(id)<<3 | WireBytes)
200
- if ext, ok := m[id]; ok {
201
- // Existing data; rip off the tag and length varint
202
- // so we join the new data correctly.
203
- // We can assume that ext.enc is set because we are unmarshaling.
204
- o := ext.enc[len(b):] // skip wire type and field number
205
- _, n := DecodeVarint(o) // calculate length of length varint
206
- o = o[n:] // skip length varint
207
- msg = append(o, msg...) // join old data and new data
208
- }
209
- b = append(b, EncodeVarint(uint64(len(msg)))...)
210
- b = append(b, msg...)
211
-
212
- m[id] = Extension{enc: b}
213
- }
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)
275
-
276
-type messageSetDesc struct {
277
- t reflect.Type // pointer to struct
278
- name string
279
-}
280
-
281
-// RegisterMessageSetType is called from the generated code.
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
deleted
-66
@@ -1,66 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2014 The Go Authors. All rights reserved.
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
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
- "bytes"
36
- "testing"
37
-)
38
-
39
-func TestUnmarshalMessageSetWithDuplicate(t *testing.T) {
40
- // Check that a repeated message set entry will be concatenated.
41
- in := &MessageSet{
42
- Item: []*_MessageSet_Item{
43
- {TypeId: Int32(12345), Message: []byte("hoo")},
44
- {TypeId: Int32(12345), Message: []byte("hah")},
45
- },
46
- }
47
- b, err := Marshal(in)
48
- if err != nil {
49
- t.Fatalf("Marshal: %v", err)
50
- }
51
- t.Logf("Marshaled bytes: %q", b)
52
-
53
- m := make(map[int32]Extension)
54
- if err := UnmarshalMessageSet(b, m); err != nil {
55
- t.Fatalf("UnmarshalMessageSet: %v", err)
56
- }
57
- ext, ok := m[12345]
58
- if !ok {
59
- t.Fatalf("Didn't retrieve extension 12345; map is %v", m)
60
- }
61
- // Skip wire type/field number and length varints.
62
- got := skipVarint(skipVarint(ext.enc))
63
- if want := []byte("hoohah"); !bytes.Equal(got, want) {
64
- t.Errorf("Combined extension is %q, want %q", got, want)
65
- }
66
-}
Godeps/_workspace/src/github.com/gogo/protobuf/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
-// 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
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/github.com/gogo/protobuf/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
-// 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
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/github.com/gogo/protobuf/proto/pointer_unsafe_gogo.go
deleted
-166
@@ -1,166 +0,0 @@
1
-// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
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
6
-// met:
7
-//
8
-// * Redistributions of source code must retain the above copyright
9
-// notice, this list of conditions and the following disclaimer.
10
-// * Redistributions in binary form must reproduce the above
11
-// copyright notice, this list of conditions and the following disclaimer
12
-// in the documentation and/or other materials provided with the
13
-// distribution.
14
-//
15
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
-
27
-// +build !appengine
28
-
29
-// This file contains the implementation of the proto field accesses using package unsafe.
30
-
31
-package proto
32
-
33
-import (
34
- "reflect"
35
- "unsafe"
36
-)
37
-
38
-func structPointer_InterfaceAt(p structPointer, f field, t reflect.Type) interface{} {
39
- point := unsafe.Pointer(uintptr(p) + uintptr(f))
40
- r := reflect.NewAt(t, point)
41
- return r.Interface()
42
-}
43
-
44
-func structPointer_InterfaceRef(p structPointer, f field, t reflect.Type) interface{} {
45
- point := unsafe.Pointer(uintptr(p) + uintptr(f))
46
- r := reflect.NewAt(t, point)
47
- if r.Elem().IsNil() {
48
- return nil
49
- }
50
- return r.Elem().Interface()
51
-}
52
-
53
-func copyUintPtr(oldptr, newptr uintptr, size int) {
54
- oldbytes := make([]byte, 0)
55
- oldslice := (*reflect.SliceHeader)(unsafe.Pointer(&oldbytes))
56
- oldslice.Data = oldptr
57
- oldslice.Len = size
58
- oldslice.Cap = size
59
- newbytes := make([]byte, 0)
60
- newslice := (*reflect.SliceHeader)(unsafe.Pointer(&newbytes))
61
- newslice.Data = newptr
62
- newslice.Len = size
63
- newslice.Cap = size
64
- copy(newbytes, oldbytes)
65
-}
66
-
67
-func structPointer_Copy(oldptr structPointer, newptr structPointer, size int) {
68
- copyUintPtr(uintptr(oldptr), uintptr(newptr), size)
69
-}
70
-
71
-func appendStructPointer(base structPointer, f field, typ reflect.Type) structPointer {
72
- size := typ.Elem().Size()
73
- oldHeader := structPointer_GetSliceHeader(base, f)
74
- newLen := oldHeader.Len + 1
75
- slice := reflect.MakeSlice(typ, newLen, newLen)
76
- bas := toStructPointer(slice)
77
- for i := 0; i < oldHeader.Len; i++ {
78
- newElemptr := uintptr(bas) + uintptr(i)*size
79
- oldElemptr := oldHeader.Data + uintptr(i)*size
80
- copyUintPtr(oldElemptr, newElemptr, int(size))
81
- }
82
-
83
- oldHeader.Data = uintptr(bas)
84
- oldHeader.Len = newLen
85
- oldHeader.Cap = newLen
86
-
87
- return structPointer(unsafe.Pointer(uintptr(unsafe.Pointer(bas)) + uintptr(uintptr(newLen-1)*size)))
88
-}
89
-
90
-// RefBool returns a *bool field in the struct.
91
-func structPointer_RefBool(p structPointer, f field) *bool {
92
- return (*bool)(unsafe.Pointer(uintptr(p) + uintptr(f)))
93
-}
94
-
95
-// RefString returns the address of a string field in the struct.
96
-func structPointer_RefString(p structPointer, f field) *string {
97
- return (*string)(unsafe.Pointer(uintptr(p) + uintptr(f)))
98
-}
99
-
100
-func structPointer_FieldPointer(p structPointer, f field) structPointer {
101
- return structPointer(unsafe.Pointer(uintptr(p) + uintptr(f)))
102
-}
103
-
104
-func structPointer_GetRefStructPointer(p structPointer, f field) structPointer {
105
- return structPointer((*structPointer)(unsafe.Pointer(uintptr(p) + uintptr(f))))
106
-}
107
-
108
-func structPointer_GetSliceHeader(p structPointer, f field) *reflect.SliceHeader {
109
- return (*reflect.SliceHeader)(unsafe.Pointer(uintptr(p) + uintptr(f)))
110
-}
111
-
112
-func structPointer_Add(p structPointer, size field) structPointer {
113
- return structPointer(unsafe.Pointer(uintptr(p) + uintptr(size)))
114
-}
115
-
116
-func structPointer_Len(p structPointer, f field) int {
117
- return len(*(*[]interface{})(unsafe.Pointer(structPointer_GetRefStructPointer(p, f))))
118
-}
119
-
120
-// refWord32 is the address of a 32-bit value field.
121
-type refWord32 *uint32
122
-
123
-func refWord32_IsNil(p refWord32) bool {
124
- return p == nil
125
-}
126
-
127
-func refWord32_Set(p refWord32, o *Buffer, x uint32) {
128
- if len(o.uint32s) == 0 {
129
- o.uint32s = make([]uint32, uint32PoolSize)
130
- }
131
- o.uint32s[0] = x
132
- *p = o.uint32s[0]
133
- o.uint32s = o.uint32s[1:]
134
-}
135
-
136
-func refWord32_Get(p refWord32) uint32 {
137
- return *p
138
-}
139
-
140
-func structPointer_RefWord32(p structPointer, f field) refWord32 {
141
- return refWord32((*uint32)(unsafe.Pointer(uintptr(p) + uintptr(f))))
142
-}
143
-
144
-// refWord64 is like refWord32 but for 32-bit values.
145
-type refWord64 *uint64
146
-
147
-func refWord64_Set(p refWord64, o *Buffer, x uint64) {
148
- if len(o.uint64s) == 0 {
149
- o.uint64s = make([]uint64, uint64PoolSize)
150
- }
151
- o.uint64s[0] = x
152
- *p = o.uint64s[0]
153
- o.uint64s = o.uint64s[1:]
154
-}
155
-
156
-func refWord64_IsNil(p refWord64) bool {
157
- return p == nil
158
-}
159
-
160
-func refWord64_Get(p refWord64) uint64 {
161
- return *p
162
-}
163
-
164
-func structPointer_RefWord64(p structPointer, f field) refWord64 {
165
- return refWord64((*uint64)(unsafe.Pointer(uintptr(p) + uintptr(f))))
166
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/properties.go
deleted
-683
@@ -1,683 +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://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
-// 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
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
-
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
170
- valEnc valueEncoder // set for bool and numeric types only
171
- field field
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
180
-
181
- size sizer
182
- valSize valueSizer // set for bool and numeric types only
183
-
184
- dec decoder
185
- valDec valueDecoder // set for bool and numeric types only
186
-
187
- // If this is a packable field, this will be the decoder for the packed version of the field.
188
- packedDec decoder
189
-}
190
-
191
-// String formats the properties in the protobuf struct field tag style.
192
-func (p *Properties) String() string {
193
- s := p.Wire
194
- s = ","
195
- s += strconv.Itoa(p.Tag)
196
- if p.Required {
197
- s += ",req"
198
- }
199
- if p.Optional {
200
- s += ",opt"
201
- }
202
- if p.Repeated {
203
- s += ",rep"
204
- }
205
- if p.Packed {
206
- s += ",packed"
207
- }
208
- if p.OrigName != p.Name {
209
- s += ",name=" + p.OrigName
210
- }
211
- if len(p.Enum) > 0 {
212
- s += ",enum=" + p.Enum
213
- }
214
- if p.HasDefault {
215
- s += ",def=" + p.Default
216
- }
217
- return s
218
-}
219
-
220
-// Parse populates p by parsing a string in the protobuf struct field tag style.
221
-func (p *Properties) Parse(s string) {
222
- // "bytes,49,opt,name=foo,def=hello!"
223
- fields := strings.Split(s, ",") // breaks def=, but handled below.
224
- if len(fields) < 2 {
225
- fmt.Fprintf(os.Stderr, "proto: tag has too few fields: %q\n", s)
226
- return
227
- }
228
-
229
- p.Wire = fields[0]
230
- switch p.Wire {
231
- case "varint":
232
- p.WireType = WireVarint
233
- p.valEnc = (*Buffer).EncodeVarint
234
- p.valDec = (*Buffer).DecodeVarint
235
- p.valSize = sizeVarint
236
- case "fixed32":
237
- p.WireType = WireFixed32
238
- p.valEnc = (*Buffer).EncodeFixed32
239
- p.valDec = (*Buffer).DecodeFixed32
240
- p.valSize = sizeFixed32
241
- case "fixed64":
242
- p.WireType = WireFixed64
243
- p.valEnc = (*Buffer).EncodeFixed64
244
- p.valDec = (*Buffer).DecodeFixed64
245
- p.valSize = sizeFixed64
246
- case "zigzag32":
247
- p.WireType = WireVarint
248
- p.valEnc = (*Buffer).EncodeZigzag32
249
- p.valDec = (*Buffer).DecodeZigzag32
250
- p.valSize = sizeZigzag32
251
- case "zigzag64":
252
- p.WireType = WireVarint
253
- p.valEnc = (*Buffer).EncodeZigzag64
254
- p.valDec = (*Buffer).DecodeZigzag64
255
- p.valSize = sizeZigzag64
256
- case "bytes", "group":
257
- p.WireType = WireBytes
258
- // no numeric converter for non-numeric types
259
- default:
260
- fmt.Fprintf(os.Stderr, "proto: tag has unknown wire type: %q\n", s)
261
- return
262
- }
263
-
264
- var err error
265
- p.Tag, err = strconv.Atoi(fields[1])
266
- if err != nil {
267
- return
268
- }
269
-
270
- for i := 2; i < len(fields); i++ {
271
- f := fields[i]
272
- switch {
273
- case f == "req":
274
- p.Required = true
275
- case f == "opt":
276
- p.Optional = true
277
- case f == "rep":
278
- p.Repeated = true
279
- case f == "packed":
280
- p.Packed = true
281
- case strings.HasPrefix(f, "name="):
282
- p.OrigName = f[5:]
283
- case strings.HasPrefix(f, "enum="):
284
- p.Enum = f[5:]
285
- case strings.HasPrefix(f, "def="):
286
- p.HasDefault = true
287
- p.Default = f[4:] // rest of string
288
- if i+1 < len(fields) {
289
- // Commas aren't escaped, and def is always last.
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
-}
300
-
301
-func logNoSliceEnc(t1, t2 reflect.Type) {
302
- fmt.Fprintf(os.Stderr, "proto: no slice oenc for %T = []%T\n", t1, t2)
303
-}
304
-
305
-var protoMessageType = reflect.TypeOf((*Message)(nil)).Elem()
306
-
307
-// Initialize the fields for encoding and decoding.
308
-func (p *Properties) setEncAndDec(typ reflect.Type, lockGetProp bool) {
309
- p.enc = nil
310
- p.dec = nil
311
- p.size = nil
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:
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:
325
- fmt.Fprintf(os.Stderr, "proto: no encoder function for %T -> %T\n", t1, t2)
326
- break
327
- case reflect.Bool:
328
- p.enc = (*Buffer).enc_bool
329
- p.dec = (*Buffer).dec_bool
330
- p.size = size_bool
331
- case reflect.Int32:
332
- p.enc = (*Buffer).enc_int32
333
- p.dec = (*Buffer).dec_int32
334
- p.size = size_int32
335
- case reflect.Uint32:
336
- p.enc = (*Buffer).enc_uint32
337
- p.dec = (*Buffer).dec_int32 // can reuse
338
- p.size = size_uint32
339
- case reflect.Int64, reflect.Uint64:
340
- p.enc = (*Buffer).enc_int64
341
- p.dec = (*Buffer).dec_int64
342
- p.size = size_int64
343
- case reflect.Float32:
344
- p.enc = (*Buffer).enc_uint32 // can just treat them as bits
345
- p.dec = (*Buffer).dec_int32
346
- p.size = size_uint32
347
- case reflect.Float64:
348
- p.enc = (*Buffer).enc_int64 // can just treat them as bits
349
- p.dec = (*Buffer).dec_int64
350
- p.size = size_int64
351
- case reflect.String:
352
- p.enc = (*Buffer).enc_string
353
- p.dec = (*Buffer).dec_string
354
- p.size = size_string
355
- case reflect.Struct:
356
- p.stype = t1.Elem()
357
- p.isMarshaler = isMarshaler(t1)
358
- p.isUnmarshaler = isUnmarshaler(t1)
359
- if p.Wire == "bytes" {
360
- p.enc = (*Buffer).enc_struct_message
361
- p.dec = (*Buffer).dec_struct_message
362
- p.size = size_struct_message
363
- } else {
364
- p.enc = (*Buffer).enc_struct_group
365
- p.dec = (*Buffer).dec_struct_group
366
- p.size = size_struct_group
367
- }
368
- }
369
-
370
- case reflect.Slice:
371
- switch t2 := t1.Elem(); t2.Kind() {
372
- default:
373
- logNoSliceEnc(t1, t2)
374
- break
375
- case reflect.Bool:
376
- if p.Packed {
377
- p.enc = (*Buffer).enc_slice_packed_bool
378
- p.size = size_slice_packed_bool
379
- } else {
380
- p.enc = (*Buffer).enc_slice_bool
381
- p.size = size_slice_bool
382
- }
383
- p.dec = (*Buffer).dec_slice_bool
384
- p.packedDec = (*Buffer).dec_slice_packed_bool
385
- case reflect.Int32:
386
- if p.Packed {
387
- p.enc = (*Buffer).enc_slice_packed_int32
388
- p.size = size_slice_packed_int32
389
- } else {
390
- p.enc = (*Buffer).enc_slice_int32
391
- p.size = size_slice_int32
392
- }
393
- p.dec = (*Buffer).dec_slice_int32
394
- p.packedDec = (*Buffer).dec_slice_packed_int32
395
- case reflect.Uint32:
396
- if p.Packed {
397
- p.enc = (*Buffer).enc_slice_packed_uint32
398
- p.size = size_slice_packed_uint32
399
- } else {
400
- p.enc = (*Buffer).enc_slice_uint32
401
- p.size = size_slice_uint32
402
- }
403
- p.dec = (*Buffer).dec_slice_int32
404
- p.packedDec = (*Buffer).dec_slice_packed_int32
405
- case reflect.Int64, reflect.Uint64:
406
- if p.Packed {
407
- p.enc = (*Buffer).enc_slice_packed_int64
408
- p.size = size_slice_packed_int64
409
- } else {
410
- p.enc = (*Buffer).enc_slice_int64
411
- p.size = size_slice_int64
412
- }
413
- p.dec = (*Buffer).dec_slice_int64
414
- p.packedDec = (*Buffer).dec_slice_packed_int64
415
- case reflect.Uint8:
416
- p.enc = (*Buffer).enc_slice_byte
417
- p.dec = (*Buffer).dec_slice_byte
418
- p.size = size_slice_byte
419
- case reflect.Float32, reflect.Float64:
420
- switch t2.Bits() {
421
- case 32:
422
- // can just treat them as bits
423
- if p.Packed {
424
- p.enc = (*Buffer).enc_slice_packed_uint32
425
- p.size = size_slice_packed_uint32
426
- } else {
427
- p.enc = (*Buffer).enc_slice_uint32
428
- p.size = size_slice_uint32
429
- }
430
- p.dec = (*Buffer).dec_slice_int32
431
- p.packedDec = (*Buffer).dec_slice_packed_int32
432
- case 64:
433
- // can just treat them as bits
434
- if p.Packed {
435
- p.enc = (*Buffer).enc_slice_packed_int64
436
- p.size = size_slice_packed_int64
437
- } else {
438
- p.enc = (*Buffer).enc_slice_int64
439
- p.size = size_slice_int64
440
- }
441
- p.dec = (*Buffer).dec_slice_int64
442
- p.packedDec = (*Buffer).dec_slice_packed_int64
443
- default:
444
- logNoSliceEnc(t1, t2)
445
- break
446
- }
447
- case reflect.String:
448
- p.enc = (*Buffer).enc_slice_string
449
- p.dec = (*Buffer).dec_slice_string
450
- p.size = size_slice_string
451
- case reflect.Ptr:
452
- switch t3 := t2.Elem(); t3.Kind() {
453
- default:
454
- fmt.Fprintf(os.Stderr, "proto: no ptr oenc for %T -> %T -> %T\n", t1, t2, t3)
455
- break
456
- case reflect.Struct:
457
- p.stype = t2.Elem()
458
- p.isMarshaler = isMarshaler(t2)
459
- p.isUnmarshaler = isUnmarshaler(t2)
460
- if p.Wire == "bytes" {
461
- p.enc = (*Buffer).enc_slice_struct_message
462
- p.dec = (*Buffer).dec_slice_struct_message
463
- p.size = size_slice_struct_message
464
- } else {
465
- p.enc = (*Buffer).enc_slice_struct_group
466
- p.dec = (*Buffer).dec_slice_struct_group
467
- p.size = size_slice_struct_group
468
- }
469
- }
470
- case reflect.Slice:
471
- switch t2.Elem().Kind() {
472
- default:
473
- fmt.Fprintf(os.Stderr, "proto: no slice elem oenc for %T -> %T -> %T\n", t1, t2, t2.Elem())
474
- break
475
- case reflect.Uint8:
476
- p.enc = (*Buffer).enc_slice_slice_byte
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 {
491
- wire = WireBytes
492
- }
493
- x := uint32(p.Tag)<<3 | uint32(wire)
494
- i := 0
495
- for i = 0; x > 127; i++ {
496
- p.tagbuf[i] = 0x80 | uint8(x&0x7F)
497
- x >>= 7
498
- }
499
- p.tagbuf[i] = uint8(x)
500
- p.tagcode = p.tagbuf[0 : i+1]
501
-
502
- if p.stype != nil {
503
- if lockGetProp {
504
- p.sprop = GetProperties(p.stype)
505
- } else {
506
- p.sprop = getPropertiesLocked(p.stype)
507
- }
508
- }
509
-}
510
-
511
-var (
512
- marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
513
- unmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem()
514
-)
515
-
516
-// isMarshaler reports whether type t implements Marshaler.
517
-func isMarshaler(t reflect.Type) bool {
518
- return t.Implements(marshalerType)
519
-}
520
-
521
-// isUnmarshaler reports whether type t implements Unmarshaler.
522
-func isUnmarshaler(t reflect.Type) bool {
523
- return t.Implements(unmarshalerType)
524
-}
525
-
526
-// Init populates the properties from a protocol buffer struct tag.
527
-func (p *Properties) Init(typ reflect.Type, name, tag string, f *reflect.StructField) {
528
- p.init(typ, name, tag, f, true)
529
-}
530
-
531
-func (p *Properties) init(typ reflect.Type, name, tag string, f *reflect.StructField, lockGetProp bool) {
532
- // "bytes,49,opt,def=hello!"
533
- p.Name = name
534
- p.OrigName = name
535
- if f != nil {
536
- p.field = toField(f)
537
- }
538
- if tag == "" {
539
- return
540
- }
541
- p.Parse(tag)
542
- p.setEncAndDec(typ, lockGetProp)
543
-}
544
-
545
-var (
546
- mutex sync.Mutex
547
- propertiesMap = make(map[reflect.Type]*StructProperties)
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()
559
- return sprop
560
-}
561
-
562
-// getPropertiesLocked requires that mutex is held.
563
-func getPropertiesLocked(t reflect.Type) *StructProperties {
564
- if prop, ok := propertiesMap[t]; ok {
565
- if collectStats {
566
- stats.Chit++
567
- }
568
- return prop
569
- }
570
- if collectStats {
571
- stats.Cmiss++
572
- }
573
-
574
- prop := new(StructProperties)
575
- // in case of recursive protos, fill this in now.
576
- propertiesMap[t] = prop
577
-
578
- // build properties
579
- prop.extendable = reflect.PtrTo(t).Implements(extendableProtoType)
580
- prop.unrecField = invalidField
581
- prop.Prop = make([]*Properties, t.NumField())
582
- prop.order = make([]int, t.NumField())
583
-
584
- for i := 0; i < t.NumField(); i++ {
585
- f := t.Field(i)
586
- p := new(Properties)
587
- name := f.Name
588
- p.init(f.Type, name, f.Tag.Get("protobuf"), &f, false)
589
-
590
- if f.Name == "XXX_extensions" { // special case
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)
603
- }
604
- prop.Prop[i] = p
605
- prop.order[i] = i
606
- if debug {
607
- print(i, " ", f.Name, " ", t.String(), " ")
608
- if p.Tag > 0 {
609
- print(p.String())
610
- }
611
- print("\n")
612
- }
613
- if p.enc == nil && !strings.HasPrefix(f.Name, "XXX_") {
614
- fmt.Fprintln(os.Stderr, "proto: no encoder for", f.Name, f.Type.String(), "[GetProperties]")
615
- }
616
- }
617
-
618
- // Re-order prop.order.
619
- sort.Sort(prop)
620
-
621
- // build required counts
622
- // build tags
623
- reqCount := 0
624
- prop.decoderOrigNames = make(map[string]int)
625
- for i, p := range prop.Prop {
626
- if strings.HasPrefix(p.Name, "XXX_") {
627
- // Internal fields should not appear in tags/origNames maps.
628
- // They are handled specially when encoding and decoding.
629
- continue
630
- }
631
- if p.Required {
632
- reqCount++
633
- }
634
- prop.decoderTags.put(p.Tag, i)
635
- prop.decoderOrigNames[p.OrigName] = i
636
- }
637
- prop.reqCount = reqCount
638
-
639
- return prop
640
-}
641
-
642
-// Return the Properties object for the x[0]'th field of the structure.
643
-func propByIndex(t reflect.Type, x []int) *Properties {
644
- if len(x) != 1 {
645
- fmt.Fprintf(os.Stderr, "proto: field index dimension %d (not 1) for type %s\n", len(x), t)
646
- return nil
647
- }
648
- prop := GetProperties(t)
649
- return prop.Prop[x[0]]
650
-}
651
-
652
-// Get the address and type of a pointer to a struct from an interface.
653
-func getbase(pb Message) (t reflect.Type, b structPointer, err error) {
654
- if pb == nil {
655
- err = ErrNil
656
- return
657
- }
658
- // get the reflect type of the pointer to the struct.
659
- t = reflect.TypeOf(pb)
660
- // get the address of the struct.
661
- value := reflect.ValueOf(pb)
662
- b = toStructPointer(value)
663
- return
664
-}
665
-
666
-// A global registry of enum types.
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.
674
-func RegisterEnum(typeName string, unusedNameMap map[int32]string, valueMap map[string]int32) {
675
- if _, ok := enumValueMaps[typeName]; ok {
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
deleted
-111
@@ -1,111 +0,0 @@
1
-// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
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
6
-// met:
7
-//
8
-// * Redistributions of source code must retain the above copyright
9
-// notice, this list of conditions and the following disclaimer.
10
-// * Redistributions in binary form must reproduce the above
11
-// copyright notice, this list of conditions and the following disclaimer
12
-// in the documentation and/or other materials provided with the
13
-// distribution.
14
-//
15
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
-
27
-package proto
28
-
29
-import (
30
- "fmt"
31
- "os"
32
- "reflect"
33
-)
34
-
35
-func (p *Properties) setCustomEncAndDec(typ reflect.Type) {
36
- p.ctype = typ
37
- if p.Repeated {
38
- p.enc = (*Buffer).enc_custom_slice_bytes
39
- p.dec = (*Buffer).dec_custom_slice_bytes
40
- p.size = size_custom_slice_bytes
41
- } else if typ.Kind() == reflect.Ptr {
42
- p.enc = (*Buffer).enc_custom_bytes
43
- p.dec = (*Buffer).dec_custom_bytes
44
- p.size = size_custom_bytes
45
- } else {
46
- p.enc = (*Buffer).enc_custom_ref_bytes
47
- p.dec = (*Buffer).dec_custom_ref_bytes
48
- p.size = size_custom_ref_bytes
49
- }
50
-}
51
-
52
-func (p *Properties) setNonNullableEncAndDec(typ reflect.Type) bool {
53
- switch typ.Kind() {
54
- case reflect.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:
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:
71
- p.enc = (*Buffer).enc_ref_uint32 // can just treat them as bits
72
- p.dec = (*Buffer).dec_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
77
- p.size = size_ref_int64
78
- case reflect.String:
79
- p.dec = (*Buffer).dec_ref_string
80
- p.enc = (*Buffer).enc_ref_string
81
- p.size = size_ref_string
82
- case reflect.Struct:
83
- p.stype = typ
84
- p.isMarshaler = isMarshaler(typ)
85
- p.isUnmarshaler = isUnmarshaler(typ)
86
- if p.Wire == "bytes" {
87
- p.enc = (*Buffer).enc_ref_struct_message
88
- p.dec = (*Buffer).dec_ref_struct_message
89
- p.size = size_ref_struct_message
90
- } else {
91
- fmt.Fprintf(os.Stderr, "proto: no coders for struct %T\n", typ)
92
- }
93
- default:
94
- return false
95
- }
96
- return true
97
-}
98
-
99
-func (p *Properties) setSliceOfNonPointerStructs(typ reflect.Type) {
100
- t2 := typ.Elem()
101
- p.sstype = typ
102
- p.stype = t2
103
- p.isMarshaler = isMarshaler(t2)
104
- p.isUnmarshaler = isUnmarshaler(t2)
105
- p.enc = (*Buffer).enc_slice_ref_struct_message
106
- p.dec = (*Buffer).dec_slice_ref_struct_message
107
- p.size = size_slice_ref_struct_message
108
- if p.Wire != "bytes" {
109
- fmt.Fprintf(os.Stderr, "proto: no ptr oenc for %T -> %T \n", typ, t2)
110
- }
111
-}
Godeps/_workspace/src/github.com/gogo/protobuf/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
-// 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
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/github.com/gogo/protobuf/proto/size_test.go
deleted
-120
@@ -1,120 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2012 The Go Authors. All rights reserved.
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
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/github.com/gogo/protobuf/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
- {"negative int32", &pb.Defaults{F_Int32: Int32(-1)}},
69
- {"small int64", &pb.Defaults{F_Int64: Int64(1)}},
70
- {"big int64", &pb.Defaults{F_Int64: Int64(1 << 20)}},
71
- {"negative int64", &pb.Defaults{F_Int64: Int64(-1)}},
72
- {"fixed32", &pb.Defaults{F_Fixed32: Uint32(71)}},
73
- {"fixed64", &pb.Defaults{F_Fixed64: Uint64(72)}},
74
- {"uint32", &pb.Defaults{F_Uint32: Uint32(123)}},
75
- {"uint64", &pb.Defaults{F_Uint64: Uint64(124)}},
76
- {"float", &pb.Defaults{F_Float: Float32(12.6)}},
77
- {"double", &pb.Defaults{F_Double: Float64(13.9)}},
78
- {"string", &pb.Defaults{F_String: String("niles")}},
79
- {"bytes", &pb.Defaults{F_Bytes: []byte("wowsa")}},
80
- {"bytes, empty", &pb.Defaults{F_Bytes: []byte{}}},
81
- {"sint32", &pb.Defaults{F_Sint32: Int32(65)}},
82
- {"sint64", &pb.Defaults{F_Sint64: Int64(67)}},
83
- {"enum", &pb.Defaults{F_Enum: pb.Defaults_BLUE.Enum()}},
84
- // Repeated.
85
- {"empty repeated bool", &pb.MoreRepeated{Bools: []bool{}}},
86
- {"repeated bool", &pb.MoreRepeated{Bools: []bool{false, true, true, false}}},
87
- {"packed repeated bool", &pb.MoreRepeated{BoolsPacked: []bool{false, true, true, false, true, true, true}}},
88
- {"repeated int32", &pb.MoreRepeated{Ints: []int32{1, 12203, 1729, -1}}},
89
- {"repeated int32 packed", &pb.MoreRepeated{IntsPacked: []int32{1, 12203, 1729}}},
90
- {"repeated int64 packed", &pb.MoreRepeated{Int64SPacked: []int64{
91
- // Need enough large numbers to verify that the header is counting the number of bytes
92
- // for the field, not the number of elements.
93
- 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62,
94
- 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62, 1 << 62,
95
- }}},
96
- {"repeated string", &pb.MoreRepeated{Strings: []string{"r", "ken", "gri"}}},
97
- {"repeated fixed", &pb.MoreRepeated{Fixeds: []uint32{1, 2, 3, 4}}},
98
- // Nested.
99
- {"nested", &pb.OldMessage{Nested: &pb.OldMessage_Nested{Name: String("whatever")}}},
100
- {"group", &pb.GroupOld{G: &pb.GroupOld_G{X: Int32(12345)}}},
101
- // Other things.
102
- {"unrecognized", &pb.MoreRepeated{XXX_unrecognized: []byte{13<<3 | 0, 4}}},
103
- {"extension (unencoded)", messageWithExtension1},
104
- {"extension (encoded)", messageWithExtension3},
105
-}
106
-
107
-func TestSize(t *testing.T) {
108
- for _, tc := range SizeTests {
109
- size := Size(tc.pb)
110
- b, err := Marshal(tc.pb)
111
- if err != nil {
112
- t.Errorf("%v: Marshal failed: %v", tc.desc, err)
113
- continue
114
- }
115
- if size != len(b) {
116
- t.Errorf("%v: Size(%v) = %d, want %d", tc.desc, tc.pb, size, len(b))
117
- t.Logf("%v: bytes: %#v", tc.desc, b)
118
- }
119
- }
120
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/skip_gogo.go
deleted
-117
@@ -1,117 +0,0 @@
1
-// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
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
6
-// met:
7
-//
8
-// * Redistributions of source code must retain the above copyright
9
-// notice, this list of conditions and the following disclaimer.
10
-// * Redistributions in binary form must reproduce the above
11
-// copyright notice, this list of conditions and the following disclaimer
12
-// in the documentation and/or other materials provided with the
13
-// distribution.
14
-//
15
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
-
27
-package proto
28
-
29
-import (
30
- "fmt"
31
- "io"
32
-)
33
-
34
-func Skip(data []byte) (n int, err error) {
35
- l := len(data)
36
- index := 0
37
- for index < l {
38
- var wire uint64
39
- for shift := uint(0); ; shift += 7 {
40
- if index >= l {
41
- return 0, io.ErrUnexpectedEOF
42
- }
43
- b := data[index]
44
- index++
45
- wire |= (uint64(b) & 0x7F) << shift
46
- if b < 0x80 {
47
- break
48
- }
49
- }
50
- wireType := int(wire & 0x7)
51
- switch wireType {
52
- case 0:
53
- for {
54
- if index >= l {
55
- return 0, io.ErrUnexpectedEOF
56
- }
57
- index++
58
- if data[index-1] < 0x80 {
59
- break
60
- }
61
- }
62
- return index, nil
63
- case 1:
64
- index += 8
65
- return index, nil
66
- case 2:
67
- var length int
68
- for shift := uint(0); ; shift += 7 {
69
- if index >= l {
70
- return 0, io.ErrUnexpectedEOF
71
- }
72
- b := data[index]
73
- index++
74
- length |= (int(b) & 0x7F) << shift
75
- if b < 0x80 {
76
- break
77
- }
78
- }
79
- index += length
80
- return index, nil
81
- case 3:
82
- for {
83
- var wire uint64
84
- var start int = index
85
- for shift := uint(0); ; shift += 7 {
86
- if index >= l {
87
- return 0, io.ErrUnexpectedEOF
88
- }
89
- b := data[index]
90
- index++
91
- wire |= (uint64(b) & 0x7F) << shift
92
- if b < 0x80 {
93
- break
94
- }
95
- }
96
- wireType := int(wire & 0x7)
97
- if wireType == 4 {
98
- break
99
- }
100
- next, err := Skip(data[start:])
101
- if err != nil {
102
- return 0, err
103
- }
104
- index = start + next
105
- }
106
- return index, nil
107
- case 4:
108
- return index, nil
109
- case 5:
110
- index += 4
111
- return index, nil
112
- default:
113
- return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
114
- }
115
- }
116
- panic("unreachable")
117
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/testdata/Makefile
deleted
-47
@@ -1,47 +0,0 @@
1
-# Go support for Protocol Buffers - Google's data interchange format
2
-#
3
-# Copyright 2010 The Go Authors. All rights reserved.
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
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
-all: regenerate
33
-
34
-regenerate:
35
- rm -f test.pb.go
36
- protoc --gogo_out=. test.proto
37
-
38
-# The following rules are just aids to development. Not needed for typical testing.
39
-
40
-diff: regenerate
41
- hg diff test.pb.go
42
-
43
-restore:
44
- cp test.pb.go.golden test.pb.go
45
-
46
-preserve:
47
- cp test.pb.go test.pb.go.golden
Godeps/_workspace/src/github.com/gogo/protobuf/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
-// 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
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", "--gogo_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/github.com/gogo/protobuf/proto/testdata/test.pb.go
deleted
-2356
@@ -1,2356 +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/github.com/gogo/protobuf/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
- Num *int32 `protobuf:"varint,2,opt,name=num" json:"num,omitempty"`
1074
- XXX_unrecognized []byte `json:"-"`
1075
-}
1076
-
1077
-func (m *OldMessage) Reset() { *m = OldMessage{} }
1078
-func (m *OldMessage) String() string { return proto.CompactTextString(m) }
1079
-func (*OldMessage) ProtoMessage() {}
1080
-
1081
-func (m *OldMessage) GetNested() *OldMessage_Nested {
1082
- if m != nil {
1083
- return m.Nested
1084
- }
1085
- return nil
1086
-}
1087
-
1088
-func (m *OldMessage) GetNum() int32 {
1089
- if m != nil && m.Num != nil {
1090
- return *m.Num
1091
- }
1092
- return 0
1093
-}
1094
-
1095
-type OldMessage_Nested struct {
1096
- Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
1097
- XXX_unrecognized []byte `json:"-"`
1098
-}
1099
-
1100
-func (m *OldMessage_Nested) Reset() { *m = OldMessage_Nested{} }
1101
-func (m *OldMessage_Nested) String() string { return proto.CompactTextString(m) }
1102
-func (*OldMessage_Nested) ProtoMessage() {}
1103
-
1104
-func (m *OldMessage_Nested) GetName() string {
1105
- if m != nil && m.Name != nil {
1106
- return *m.Name
1107
- }
1108
- return ""
1109
-}
1110
-
1111
-// NewMessage is wire compatible with OldMessage;
1112
-// imagine it as a future version.
1113
-type NewMessage struct {
1114
- Nested *NewMessage_Nested `protobuf:"bytes,1,opt,name=nested" json:"nested,omitempty"`
1115
- // This is an int32 in OldMessage.
1116
- Num *int64 `protobuf:"varint,2,opt,name=num" json:"num,omitempty"`
1117
- XXX_unrecognized []byte `json:"-"`
1118
-}
1119
-
1120
-func (m *NewMessage) Reset() { *m = NewMessage{} }
1121
-func (m *NewMessage) String() string { return proto.CompactTextString(m) }
1122
-func (*NewMessage) ProtoMessage() {}
1123
-
1124
-func (m *NewMessage) GetNested() *NewMessage_Nested {
1125
- if m != nil {
1126
- return m.Nested
1127
- }
1128
- return nil
1129
-}
1130
-
1131
-func (m *NewMessage) GetNum() int64 {
1132
- if m != nil && m.Num != nil {
1133
- return *m.Num
1134
- }
1135
- return 0
1136
-}
1137
-
1138
-type NewMessage_Nested struct {
1139
- Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
1140
- FoodGroup *string `protobuf:"bytes,2,opt,name=food_group" json:"food_group,omitempty"`
1141
- XXX_unrecognized []byte `json:"-"`
1142
-}
1143
-
1144
-func (m *NewMessage_Nested) Reset() { *m = NewMessage_Nested{} }
1145
-func (m *NewMessage_Nested) String() string { return proto.CompactTextString(m) }
1146
-func (*NewMessage_Nested) ProtoMessage() {}
1147
-
1148
-func (m *NewMessage_Nested) GetName() string {
1149
- if m != nil && m.Name != nil {
1150
- return *m.Name
1151
- }
1152
- return ""
1153
-}
1154
-
1155
-func (m *NewMessage_Nested) GetFoodGroup() string {
1156
- if m != nil && m.FoodGroup != nil {
1157
- return *m.FoodGroup
1158
- }
1159
- return ""
1160
-}
1161
-
1162
-type InnerMessage struct {
1163
- Host *string `protobuf:"bytes,1,req,name=host" json:"host,omitempty"`
1164
- Port *int32 `protobuf:"varint,2,opt,name=port,def=4000" json:"port,omitempty"`
1165
- Connected *bool `protobuf:"varint,3,opt,name=connected" json:"connected,omitempty"`
1166
- XXX_unrecognized []byte `json:"-"`
1167
-}
1168
-
1169
-func (m *InnerMessage) Reset() { *m = InnerMessage{} }
1170
-func (m *InnerMessage) String() string { return proto.CompactTextString(m) }
1171
-func (*InnerMessage) ProtoMessage() {}
1172
-
1173
-const Default_InnerMessage_Port int32 = 4000
1174
-
1175
-func (m *InnerMessage) GetHost() string {
1176
- if m != nil && m.Host != nil {
1177
- return *m.Host
1178
- }
1179
- return ""
1180
-}
1181
-
1182
-func (m *InnerMessage) GetPort() int32 {
1183
- if m != nil && m.Port != nil {
1184
- return *m.Port
1185
- }
1186
- return Default_InnerMessage_Port
1187
-}
1188
-
1189
-func (m *InnerMessage) GetConnected() bool {
1190
- if m != nil && m.Connected != nil {
1191
- return *m.Connected
1192
- }
1193
- return false
1194
-}
1195
-
1196
-type OtherMessage struct {
1197
- Key *int64 `protobuf:"varint,1,opt,name=key" json:"key,omitempty"`
1198
- Value []byte `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
1199
- Weight *float32 `protobuf:"fixed32,3,opt,name=weight" json:"weight,omitempty"`
1200
- Inner *InnerMessage `protobuf:"bytes,4,opt,name=inner" json:"inner,omitempty"`
1201
- XXX_unrecognized []byte `json:"-"`
1202
-}
1203
-
1204
-func (m *OtherMessage) Reset() { *m = OtherMessage{} }
1205
-func (m *OtherMessage) String() string { return proto.CompactTextString(m) }
1206
-func (*OtherMessage) ProtoMessage() {}
1207
-
1208
-func (m *OtherMessage) GetKey() int64 {
1209
- if m != nil && m.Key != nil {
1210
- return *m.Key
1211
- }
1212
- return 0
1213
-}
1214
-
1215
-func (m *OtherMessage) GetValue() []byte {
1216
- if m != nil {
1217
- return m.Value
1218
- }
1219
- return nil
1220
-}
1221
-
1222
-func (m *OtherMessage) GetWeight() float32 {
1223
- if m != nil && m.Weight != nil {
1224
- return *m.Weight
1225
- }
1226
- return 0
1227
-}
1228
-
1229
-func (m *OtherMessage) GetInner() *InnerMessage {
1230
- if m != nil {
1231
- return m.Inner
1232
- }
1233
- return nil
1234
-}
1235
-
1236
-type MyMessage struct {
1237
- Count *int32 `protobuf:"varint,1,req,name=count" json:"count,omitempty"`
1238
- Name *string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
1239
- Quote *string `protobuf:"bytes,3,opt,name=quote" json:"quote,omitempty"`
1240
- Pet []string `protobuf:"bytes,4,rep,name=pet" json:"pet,omitempty"`
1241
- Inner *InnerMessage `protobuf:"bytes,5,opt,name=inner" json:"inner,omitempty"`
1242
- Others []*OtherMessage `protobuf:"bytes,6,rep,name=others" json:"others,omitempty"`
1243
- RepInner []*InnerMessage `protobuf:"bytes,12,rep,name=rep_inner" json:"rep_inner,omitempty"`
1244
- Bikeshed *MyMessage_Color `protobuf:"varint,7,opt,name=bikeshed,enum=testdata.MyMessage_Color" json:"bikeshed,omitempty"`
1245
- Somegroup *MyMessage_SomeGroup `protobuf:"group,8,opt,name=SomeGroup" json:"somegroup,omitempty"`
1246
- // This field becomes [][]byte in the generated code.
1247
- RepBytes [][]byte `protobuf:"bytes,10,rep,name=rep_bytes" json:"rep_bytes,omitempty"`
1248
- Bigfloat *float64 `protobuf:"fixed64,11,opt,name=bigfloat" json:"bigfloat,omitempty"`
1249
- XXX_extensions map[int32]proto.Extension `json:"-"`
1250
- XXX_unrecognized []byte `json:"-"`
1251
-}
1252
-
1253
-func (m *MyMessage) Reset() { *m = MyMessage{} }
1254
-func (m *MyMessage) String() string { return proto.CompactTextString(m) }
1255
-func (*MyMessage) ProtoMessage() {}
1256
-
1257
-var extRange_MyMessage = []proto.ExtensionRange{
1258
- {100, 536870911},
1259
-}
1260
-
1261
-func (*MyMessage) ExtensionRangeArray() []proto.ExtensionRange {
1262
- return extRange_MyMessage
1263
-}
1264
-func (m *MyMessage) ExtensionMap() map[int32]proto.Extension {
1265
- if m.XXX_extensions == nil {
1266
- m.XXX_extensions = make(map[int32]proto.Extension)
1267
- }
1268
- return m.XXX_extensions
1269
-}
1270
-
1271
-func (m *MyMessage) GetCount() int32 {
1272
- if m != nil && m.Count != nil {
1273
- return *m.Count
1274
- }
1275
- return 0
1276
-}
1277
-
1278
-func (m *MyMessage) GetName() string {
1279
- if m != nil && m.Name != nil {
1280
- return *m.Name
1281
- }
1282
- return ""
1283
-}
1284
-
1285
-func (m *MyMessage) GetQuote() string {
1286
- if m != nil && m.Quote != nil {
1287
- return *m.Quote
1288
- }
1289
- return ""
1290
-}
1291
-
1292
-func (m *MyMessage) GetPet() []string {
1293
- if m != nil {
1294
- return m.Pet
1295
- }
1296
- return nil
1297
-}
1298
-
1299
-func (m *MyMessage) GetInner() *InnerMessage {
1300
- if m != nil {
1301
- return m.Inner
1302
- }
1303
- return nil
1304
-}
1305
-
1306
-func (m *MyMessage) GetOthers() []*OtherMessage {
1307
- if m != nil {
1308
- return m.Others
1309
- }
1310
- return nil
1311
-}
1312
-
1313
-func (m *MyMessage) GetRepInner() []*InnerMessage {
1314
- if m != nil {
1315
- return m.RepInner
1316
- }
1317
- return nil
1318
-}
1319
-
1320
-func (m *MyMessage) GetBikeshed() MyMessage_Color {
1321
- if m != nil && m.Bikeshed != nil {
1322
- return *m.Bikeshed
1323
- }
1324
- return MyMessage_RED
1325
-}
1326
-
1327
-func (m *MyMessage) GetSomegroup() *MyMessage_SomeGroup {
1328
- if m != nil {
1329
- return m.Somegroup
1330
- }
1331
- return nil
1332
-}
1333
-
1334
-func (m *MyMessage) GetRepBytes() [][]byte {
1335
- if m != nil {
1336
- return m.RepBytes
1337
- }
1338
- return nil
1339
-}
1340
-
1341
-func (m *MyMessage) GetBigfloat() float64 {
1342
- if m != nil && m.Bigfloat != nil {
1343
- return *m.Bigfloat
1344
- }
1345
- return 0
1346
-}
1347
-
1348
-type MyMessage_SomeGroup struct {
1349
- GroupField *int32 `protobuf:"varint,9,opt,name=group_field" json:"group_field,omitempty"`
1350
- XXX_unrecognized []byte `json:"-"`
1351
-}
1352
-
1353
-func (m *MyMessage_SomeGroup) Reset() { *m = MyMessage_SomeGroup{} }
1354
-func (m *MyMessage_SomeGroup) String() string { return proto.CompactTextString(m) }
1355
-func (*MyMessage_SomeGroup) ProtoMessage() {}
1356
-
1357
-func (m *MyMessage_SomeGroup) GetGroupField() int32 {
1358
- if m != nil && m.GroupField != nil {
1359
- return *m.GroupField
1360
- }
1361
- return 0
1362
-}
1363
-
1364
-type Ext struct {
1365
- Data *string `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
1366
- XXX_unrecognized []byte `json:"-"`
1367
-}
1368
-
1369
-func (m *Ext) Reset() { *m = Ext{} }
1370
-func (m *Ext) String() string { return proto.CompactTextString(m) }
1371
-func (*Ext) ProtoMessage() {}
1372
-
1373
-func (m *Ext) GetData() string {
1374
- if m != nil && m.Data != nil {
1375
- return *m.Data
1376
- }
1377
- return ""
1378
-}
1379
-
1380
-var E_Ext_More = &proto.ExtensionDesc{
1381
- ExtendedType: (*MyMessage)(nil),
1382
- ExtensionType: (*Ext)(nil),
1383
- Field: 103,
1384
- Name: "testdata.Ext.more",
1385
- Tag: "bytes,103,opt,name=more",
1386
-}
1387
-
1388
-var E_Ext_Text = &proto.ExtensionDesc{
1389
- ExtendedType: (*MyMessage)(nil),
1390
- ExtensionType: (*string)(nil),
1391
- Field: 104,
1392
- Name: "testdata.Ext.text",
1393
- Tag: "bytes,104,opt,name=text",
1394
-}
1395
-
1396
-var E_Ext_Number = &proto.ExtensionDesc{
1397
- ExtendedType: (*MyMessage)(nil),
1398
- ExtensionType: (*int32)(nil),
1399
- Field: 105,
1400
- Name: "testdata.Ext.number",
1401
- Tag: "varint,105,opt,name=number",
1402
-}
1403
-
1404
-type MyMessageSet struct {
1405
- XXX_extensions map[int32]proto.Extension `json:"-"`
1406
- XXX_unrecognized []byte `json:"-"`
1407
-}
1408
-
1409
-func (m *MyMessageSet) Reset() { *m = MyMessageSet{} }
1410
-func (m *MyMessageSet) String() string { return proto.CompactTextString(m) }
1411
-func (*MyMessageSet) ProtoMessage() {}
1412
-
1413
-func (m *MyMessageSet) Marshal() ([]byte, error) {
1414
- return proto.MarshalMessageSet(m.ExtensionMap())
1415
-}
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)
1428
-var _ proto.Unmarshaler = (*MyMessageSet)(nil)
1429
-
1430
-var extRange_MyMessageSet = []proto.ExtensionRange{
1431
- {100, 2147483646},
1432
-}
1433
-
1434
-func (*MyMessageSet) ExtensionRangeArray() []proto.ExtensionRange {
1435
- return extRange_MyMessageSet
1436
-}
1437
-func (m *MyMessageSet) ExtensionMap() map[int32]proto.Extension {
1438
- if m.XXX_extensions == nil {
1439
- m.XXX_extensions = make(map[int32]proto.Extension)
1440
- }
1441
- return m.XXX_extensions
1442
-}
1443
-
1444
-type Empty struct {
1445
- XXX_unrecognized []byte `json:"-"`
1446
-}
1447
-
1448
-func (m *Empty) Reset() { *m = Empty{} }
1449
-func (m *Empty) String() string { return proto.CompactTextString(m) }
1450
-func (*Empty) ProtoMessage() {}
1451
-
1452
-type MessageList struct {
1453
- Message []*MessageList_Message `protobuf:"group,1,rep" json:"message,omitempty"`
1454
- XXX_unrecognized []byte `json:"-"`
1455
-}
1456
-
1457
-func (m *MessageList) Reset() { *m = MessageList{} }
1458
-func (m *MessageList) String() string { return proto.CompactTextString(m) }
1459
-func (*MessageList) ProtoMessage() {}
1460
-
1461
-func (m *MessageList) GetMessage() []*MessageList_Message {
1462
- if m != nil {
1463
- return m.Message
1464
- }
1465
- return nil
1466
-}
1467
-
1468
-type MessageList_Message struct {
1469
- Name *string `protobuf:"bytes,2,req,name=name" json:"name,omitempty"`
1470
- Count *int32 `protobuf:"varint,3,req,name=count" json:"count,omitempty"`
1471
- XXX_unrecognized []byte `json:"-"`
1472
-}
1473
-
1474
-func (m *MessageList_Message) Reset() { *m = MessageList_Message{} }
1475
-func (m *MessageList_Message) String() string { return proto.CompactTextString(m) }
1476
-func (*MessageList_Message) ProtoMessage() {}
1477
-
1478
-func (m *MessageList_Message) GetName() string {
1479
- if m != nil && m.Name != nil {
1480
- return *m.Name
1481
- }
1482
- return ""
1483
-}
1484
-
1485
-func (m *MessageList_Message) GetCount() int32 {
1486
- if m != nil && m.Count != nil {
1487
- return *m.Count
1488
- }
1489
- return 0
1490
-}
1491
-
1492
-type Strings struct {
1493
- StringField *string `protobuf:"bytes,1,opt,name=string_field" json:"string_field,omitempty"`
1494
- BytesField []byte `protobuf:"bytes,2,opt,name=bytes_field" json:"bytes_field,omitempty"`
1495
- XXX_unrecognized []byte `json:"-"`
1496
-}
1497
-
1498
-func (m *Strings) Reset() { *m = Strings{} }
1499
-func (m *Strings) String() string { return proto.CompactTextString(m) }
1500
-func (*Strings) ProtoMessage() {}
1501
-
1502
-func (m *Strings) GetStringField() string {
1503
- if m != nil && m.StringField != nil {
1504
- return *m.StringField
1505
- }
1506
- return ""
1507
-}
1508
-
1509
-func (m *Strings) GetBytesField() []byte {
1510
- if m != nil {
1511
- return m.BytesField
1512
- }
1513
- return nil
1514
-}
1515
-
1516
-type Defaults struct {
1517
- // Default-valued fields of all basic types.
1518
- // Same as GoTest, but copied here to make testing easier.
1519
- F_Bool *bool `protobuf:"varint,1,opt,def=1" json:"F_Bool,omitempty"`
1520
- F_Int32 *int32 `protobuf:"varint,2,opt,def=32" json:"F_Int32,omitempty"`
1521
- F_Int64 *int64 `protobuf:"varint,3,opt,def=64" json:"F_Int64,omitempty"`
1522
- F_Fixed32 *uint32 `protobuf:"fixed32,4,opt,def=320" json:"F_Fixed32,omitempty"`
1523
- F_Fixed64 *uint64 `protobuf:"fixed64,5,opt,def=640" json:"F_Fixed64,omitempty"`
1524
- F_Uint32 *uint32 `protobuf:"varint,6,opt,def=3200" json:"F_Uint32,omitempty"`
1525
- F_Uint64 *uint64 `protobuf:"varint,7,opt,def=6400" json:"F_Uint64,omitempty"`
1526
- F_Float *float32 `protobuf:"fixed32,8,opt,def=314159" json:"F_Float,omitempty"`
1527
- F_Double *float64 `protobuf:"fixed64,9,opt,def=271828" json:"F_Double,omitempty"`
1528
- F_String *string `protobuf:"bytes,10,opt,def=hello, \"world!\"\n" json:"F_String,omitempty"`
1529
- F_Bytes []byte `protobuf:"bytes,11,opt,def=Bignose" json:"F_Bytes,omitempty"`
1530
- F_Sint32 *int32 `protobuf:"zigzag32,12,opt,def=-32" json:"F_Sint32,omitempty"`
1531
- F_Sint64 *int64 `protobuf:"zigzag64,13,opt,def=-64" json:"F_Sint64,omitempty"`
1532
- F_Enum *Defaults_Color `protobuf:"varint,14,opt,enum=testdata.Defaults_Color,def=1" json:"F_Enum,omitempty"`
1533
- // More fields with crazy defaults.
1534
- F_Pinf *float32 `protobuf:"fixed32,15,opt,def=inf" json:"F_Pinf,omitempty"`
1535
- F_Ninf *float32 `protobuf:"fixed32,16,opt,def=-inf" json:"F_Ninf,omitempty"`
1536
- F_Nan *float32 `protobuf:"fixed32,17,opt,def=nan" json:"F_Nan,omitempty"`
1537
- // Sub-message.
1538
- Sub *SubDefaults `protobuf:"bytes,18,opt,name=sub" json:"sub,omitempty"`
1539
- // Redundant but explicit defaults.
1540
- StrZero *string `protobuf:"bytes,19,opt,name=str_zero,def=" json:"str_zero,omitempty"`
1541
- XXX_unrecognized []byte `json:"-"`
1542
-}
1543
-
1544
-func (m *Defaults) Reset() { *m = Defaults{} }
1545
-func (m *Defaults) String() string { return proto.CompactTextString(m) }
1546
-func (*Defaults) ProtoMessage() {}
1547
-
1548
-const Default_Defaults_F_Bool bool = true
1549
-const Default_Defaults_F_Int32 int32 = 32
1550
-const Default_Defaults_F_Int64 int64 = 64
1551
-const Default_Defaults_F_Fixed32 uint32 = 320
1552
-const Default_Defaults_F_Fixed64 uint64 = 640
1553
-const Default_Defaults_F_Uint32 uint32 = 3200
1554
-const Default_Defaults_F_Uint64 uint64 = 6400
1555
-const Default_Defaults_F_Float float32 = 314159
1556
-const Default_Defaults_F_Double float64 = 271828
1557
-const Default_Defaults_F_String string = "hello, \"world!\"\n"
1558
-
1559
-var Default_Defaults_F_Bytes []byte = []byte("Bignose")
1560
-
1561
-const Default_Defaults_F_Sint32 int32 = -32
1562
-const Default_Defaults_F_Sint64 int64 = -64
1563
-const Default_Defaults_F_Enum Defaults_Color = Defaults_GREEN
1564
-
1565
-var Default_Defaults_F_Pinf float32 = float32(math.Inf(1))
1566
-var Default_Defaults_F_Ninf float32 = float32(math.Inf(-1))
1567
-var Default_Defaults_F_Nan float32 = float32(math.NaN())
1568
-
1569
-func (m *Defaults) GetF_Bool() bool {
1570
- if m != nil && m.F_Bool != nil {
1571
- return *m.F_Bool
1572
- }
1573
- return Default_Defaults_F_Bool
1574
-}
1575
-
1576
-func (m *Defaults) GetF_Int32() int32 {
1577
- if m != nil && m.F_Int32 != nil {
1578
- return *m.F_Int32
1579
- }
1580
- return Default_Defaults_F_Int32
1581
-}
1582
-
1583
-func (m *Defaults) GetF_Int64() int64 {
1584
- if m != nil && m.F_Int64 != nil {
1585
- return *m.F_Int64
1586
- }
1587
- return Default_Defaults_F_Int64
1588
-}
1589
-
1590
-func (m *Defaults) GetF_Fixed32() uint32 {
1591
- if m != nil && m.F_Fixed32 != nil {
1592
- return *m.F_Fixed32
1593
- }
1594
- return Default_Defaults_F_Fixed32
1595
-}
1596
-
1597
-func (m *Defaults) GetF_Fixed64() uint64 {
1598
- if m != nil && m.F_Fixed64 != nil {
1599
- return *m.F_Fixed64
1600
- }
1601
- return Default_Defaults_F_Fixed64
1602
-}
1603
-
1604
-func (m *Defaults) GetF_Uint32() uint32 {
1605
- if m != nil && m.F_Uint32 != nil {
1606
- return *m.F_Uint32
1607
- }
1608
- return Default_Defaults_F_Uint32
1609
-}
1610
-
1611
-func (m *Defaults) GetF_Uint64() uint64 {
1612
- if m != nil && m.F_Uint64 != nil {
1613
- return *m.F_Uint64
1614
- }
1615
- return Default_Defaults_F_Uint64
1616
-}
1617
-
1618
-func (m *Defaults) GetF_Float() float32 {
1619
- if m != nil && m.F_Float != nil {
1620
- return *m.F_Float
1621
- }
1622
- return Default_Defaults_F_Float
1623
-}
1624
-
1625
-func (m *Defaults) GetF_Double() float64 {
1626
- if m != nil && m.F_Double != nil {
1627
- return *m.F_Double
1628
- }
1629
- return Default_Defaults_F_Double
1630
-}
1631
-
1632
-func (m *Defaults) GetF_String() string {
1633
- if m != nil && m.F_String != nil {
1634
- return *m.F_String
1635
- }
1636
- return Default_Defaults_F_String
1637
-}
1638
-
1639
-func (m *Defaults) GetF_Bytes() []byte {
1640
- if m != nil && m.F_Bytes != nil {
1641
- return m.F_Bytes
1642
- }
1643
- return append([]byte(nil), Default_Defaults_F_Bytes...)
1644
-}
1645
-
1646
-func (m *Defaults) GetF_Sint32() int32 {
1647
- if m != nil && m.F_Sint32 != nil {
1648
- return *m.F_Sint32
1649
- }
1650
- return Default_Defaults_F_Sint32
1651
-}
1652
-
1653
-func (m *Defaults) GetF_Sint64() int64 {
1654
- if m != nil && m.F_Sint64 != nil {
1655
- return *m.F_Sint64
1656
- }
1657
- return Default_Defaults_F_Sint64
1658
-}
1659
-
1660
-func (m *Defaults) GetF_Enum() Defaults_Color {
1661
- if m != nil && m.F_Enum != nil {
1662
- return *m.F_Enum
1663
- }
1664
- return Default_Defaults_F_Enum
1665
-}
1666
-
1667
-func (m *Defaults) GetF_Pinf() float32 {
1668
- if m != nil && m.F_Pinf != nil {
1669
- return *m.F_Pinf
1670
- }
1671
- return Default_Defaults_F_Pinf
1672
-}
1673
-
1674
-func (m *Defaults) GetF_Ninf() float32 {
1675
- if m != nil && m.F_Ninf != nil {
1676
- return *m.F_Ninf
1677
- }
1678
- return Default_Defaults_F_Ninf
1679
-}
1680
-
1681
-func (m *Defaults) GetF_Nan() float32 {
1682
- if m != nil && m.F_Nan != nil {
1683
- return *m.F_Nan
1684
- }
1685
- return Default_Defaults_F_Nan
1686
-}
1687
-
1688
-func (m *Defaults) GetSub() *SubDefaults {
1689
- if m != nil {
1690
- return m.Sub
1691
- }
1692
- return nil
1693
-}
1694
-
1695
-func (m *Defaults) GetStrZero() string {
1696
- if m != nil && m.StrZero != nil {
1697
- return *m.StrZero
1698
- }
1699
- return ""
1700
-}
1701
-
1702
-type SubDefaults struct {
1703
- N *int64 `protobuf:"varint,1,opt,name=n,def=7" json:"n,omitempty"`
1704
- XXX_unrecognized []byte `json:"-"`
1705
-}
1706
-
1707
-func (m *SubDefaults) Reset() { *m = SubDefaults{} }
1708
-func (m *SubDefaults) String() string { return proto.CompactTextString(m) }
1709
-func (*SubDefaults) ProtoMessage() {}
1710
-
1711
-const Default_SubDefaults_N int64 = 7
1712
-
1713
-func (m *SubDefaults) GetN() int64 {
1714
- if m != nil && m.N != nil {
1715
- return *m.N
1716
- }
1717
- return Default_SubDefaults_N
1718
-}
1719
-
1720
-type RepeatedEnum struct {
1721
- Color []RepeatedEnum_Color `protobuf:"varint,1,rep,name=color,enum=testdata.RepeatedEnum_Color" json:"color,omitempty"`
1722
- XXX_unrecognized []byte `json:"-"`
1723
-}
1724
-
1725
-func (m *RepeatedEnum) Reset() { *m = RepeatedEnum{} }
1726
-func (m *RepeatedEnum) String() string { return proto.CompactTextString(m) }
1727
-func (*RepeatedEnum) ProtoMessage() {}
1728
-
1729
-func (m *RepeatedEnum) GetColor() []RepeatedEnum_Color {
1730
- if m != nil {
1731
- return m.Color
1732
- }
1733
- return nil
1734
-}
1735
-
1736
-type MoreRepeated struct {
1737
- Bools []bool `protobuf:"varint,1,rep,name=bools" json:"bools,omitempty"`
1738
- BoolsPacked []bool `protobuf:"varint,2,rep,packed,name=bools_packed" json:"bools_packed,omitempty"`
1739
- Ints []int32 `protobuf:"varint,3,rep,name=ints" json:"ints,omitempty"`
1740
- IntsPacked []int32 `protobuf:"varint,4,rep,packed,name=ints_packed" json:"ints_packed,omitempty"`
1741
- Int64SPacked []int64 `protobuf:"varint,7,rep,packed,name=int64s_packed" json:"int64s_packed,omitempty"`
1742
- Strings []string `protobuf:"bytes,5,rep,name=strings" json:"strings,omitempty"`
1743
- Fixeds []uint32 `protobuf:"fixed32,6,rep,name=fixeds" json:"fixeds,omitempty"`
1744
- XXX_unrecognized []byte `json:"-"`
1745
-}
1746
-
1747
-func (m *MoreRepeated) Reset() { *m = MoreRepeated{} }
1748
-func (m *MoreRepeated) String() string { return proto.CompactTextString(m) }
1749
-func (*MoreRepeated) ProtoMessage() {}
1750
-
1751
-func (m *MoreRepeated) GetBools() []bool {
1752
- if m != nil {
1753
- return m.Bools
1754
- }
1755
- return nil
1756
-}
1757
-
1758
-func (m *MoreRepeated) GetBoolsPacked() []bool {
1759
- if m != nil {
1760
- return m.BoolsPacked
1761
- }
1762
- return nil
1763
-}
1764
-
1765
-func (m *MoreRepeated) GetInts() []int32 {
1766
- if m != nil {
1767
- return m.Ints
1768
- }
1769
- return nil
1770
-}
1771
-
1772
-func (m *MoreRepeated) GetIntsPacked() []int32 {
1773
- if m != nil {
1774
- return m.IntsPacked
1775
- }
1776
- return nil
1777
-}
1778
-
1779
-func (m *MoreRepeated) GetInt64SPacked() []int64 {
1780
- if m != nil {
1781
- return m.Int64SPacked
1782
- }
1783
- return nil
1784
-}
1785
-
1786
-func (m *MoreRepeated) GetStrings() []string {
1787
- if m != nil {
1788
- return m.Strings
1789
- }
1790
- return nil
1791
-}
1792
-
1793
-func (m *MoreRepeated) GetFixeds() []uint32 {
1794
- if m != nil {
1795
- return m.Fixeds
1796
- }
1797
- return nil
1798
-}
1799
-
1800
-type GroupOld struct {
1801
- G *GroupOld_G `protobuf:"group,101,opt" json:"g,omitempty"`
1802
- XXX_unrecognized []byte `json:"-"`
1803
-}
1804
-
1805
-func (m *GroupOld) Reset() { *m = GroupOld{} }
1806
-func (m *GroupOld) String() string { return proto.CompactTextString(m) }
1807
-func (*GroupOld) ProtoMessage() {}
1808
-
1809
-func (m *GroupOld) GetG() *GroupOld_G {
1810
- if m != nil {
1811
- return m.G
1812
- }
1813
- return nil
1814
-}
1815
-
1816
-type GroupOld_G struct {
1817
- X *int32 `protobuf:"varint,2,opt,name=x" json:"x,omitempty"`
1818
- XXX_unrecognized []byte `json:"-"`
1819
-}
1820
-
1821
-func (m *GroupOld_G) Reset() { *m = GroupOld_G{} }
1822
-func (m *GroupOld_G) String() string { return proto.CompactTextString(m) }
1823
-func (*GroupOld_G) ProtoMessage() {}
1824
-
1825
-func (m *GroupOld_G) GetX() int32 {
1826
- if m != nil && m.X != nil {
1827
- return *m.X
1828
- }
1829
- return 0
1830
-}
1831
-
1832
-type GroupNew struct {
1833
- G *GroupNew_G `protobuf:"group,101,opt" json:"g,omitempty"`
1834
- XXX_unrecognized []byte `json:"-"`
1835
-}
1836
-
1837
-func (m *GroupNew) Reset() { *m = GroupNew{} }
1838
-func (m *GroupNew) String() string { return proto.CompactTextString(m) }
1839
-func (*GroupNew) ProtoMessage() {}
1840
-
1841
-func (m *GroupNew) GetG() *GroupNew_G {
1842
- if m != nil {
1843
- return m.G
1844
- }
1845
- return nil
1846
-}
1847
-
1848
-type GroupNew_G struct {
1849
- X *int32 `protobuf:"varint,2,opt,name=x" json:"x,omitempty"`
1850
- Y *int32 `protobuf:"varint,3,opt,name=y" json:"y,omitempty"`
1851
- XXX_unrecognized []byte `json:"-"`
1852
-}
1853
-
1854
-func (m *GroupNew_G) Reset() { *m = GroupNew_G{} }
1855
-func (m *GroupNew_G) String() string { return proto.CompactTextString(m) }
1856
-func (*GroupNew_G) ProtoMessage() {}
1857
-
1858
-func (m *GroupNew_G) GetX() int32 {
1859
- if m != nil && m.X != nil {
1860
- return *m.X
1861
- }
1862
- return 0
1863
-}
1864
-
1865
-func (m *GroupNew_G) GetY() int32 {
1866
- if m != nil && m.Y != nil {
1867
- return *m.Y
1868
- }
1869
- return 0
1870
-}
1871
-
1872
-type FloatingPoint struct {
1873
- F *float64 `protobuf:"fixed64,1,req,name=f" json:"f,omitempty"`
1874
- XXX_unrecognized []byte `json:"-"`
1875
-}
1876
-
1877
-func (m *FloatingPoint) Reset() { *m = FloatingPoint{} }
1878
-func (m *FloatingPoint) String() string { return proto.CompactTextString(m) }
1879
-func (*FloatingPoint) ProtoMessage() {}
1880
-
1881
-func (m *FloatingPoint) GetF() float64 {
1882
- if m != nil && m.F != nil {
1883
- return *m.F
1884
- }
1885
- return 0
1886
-}
1887
-
1888
-var E_Greeting = &proto.ExtensionDesc{
1889
- ExtendedType: (*MyMessage)(nil),
1890
- ExtensionType: ([]string)(nil),
1891
- Field: 106,
1892
- Name: "testdata.greeting",
1893
- Tag: "bytes,106,rep,name=greeting",
1894
-}
1895
-
1896
-var E_X201 = &proto.ExtensionDesc{
1897
- ExtendedType: (*MyMessageSet)(nil),
1898
- ExtensionType: (*Empty)(nil),
1899
- Field: 201,
1900
- Name: "testdata.x201",
1901
- Tag: "bytes,201,opt,name=x201",
1902
-}
1903
-
1904
-var E_X202 = &proto.ExtensionDesc{
1905
- ExtendedType: (*MyMessageSet)(nil),
1906
- ExtensionType: (*Empty)(nil),
1907
- Field: 202,
1908
- Name: "testdata.x202",
1909
- Tag: "bytes,202,opt,name=x202",
1910
-}
1911
-
1912
-var E_X203 = &proto.ExtensionDesc{
1913
- ExtendedType: (*MyMessageSet)(nil),
1914
- ExtensionType: (*Empty)(nil),
1915
- Field: 203,
1916
- Name: "testdata.x203",
1917
- Tag: "bytes,203,opt,name=x203",
1918
-}
1919
-
1920
-var E_X204 = &proto.ExtensionDesc{
1921
- ExtendedType: (*MyMessageSet)(nil),
1922
- ExtensionType: (*Empty)(nil),
1923
- Field: 204,
1924
- Name: "testdata.x204",
1925
- Tag: "bytes,204,opt,name=x204",
1926
-}
1927
-
1928
-var E_X205 = &proto.ExtensionDesc{
1929
- ExtendedType: (*MyMessageSet)(nil),
1930
- ExtensionType: (*Empty)(nil),
1931
- Field: 205,
1932
- Name: "testdata.x205",
1933
- Tag: "bytes,205,opt,name=x205",
1934
-}
1935
-
1936
-var E_X206 = &proto.ExtensionDesc{
1937
- ExtendedType: (*MyMessageSet)(nil),
1938
- ExtensionType: (*Empty)(nil),
1939
- Field: 206,
1940
- Name: "testdata.x206",
1941
- Tag: "bytes,206,opt,name=x206",
1942
-}
1943
-
1944
-var E_X207 = &proto.ExtensionDesc{
1945
- ExtendedType: (*MyMessageSet)(nil),
1946
- ExtensionType: (*Empty)(nil),
1947
- Field: 207,
1948
- Name: "testdata.x207",
1949
- Tag: "bytes,207,opt,name=x207",
1950
-}
1951
-
1952
-var E_X208 = &proto.ExtensionDesc{
1953
- ExtendedType: (*MyMessageSet)(nil),
1954
- ExtensionType: (*Empty)(nil),
1955
- Field: 208,
1956
- Name: "testdata.x208",
1957
- Tag: "bytes,208,opt,name=x208",
1958
-}
1959
-
1960
-var E_X209 = &proto.ExtensionDesc{
1961
- ExtendedType: (*MyMessageSet)(nil),
1962
- ExtensionType: (*Empty)(nil),
1963
- Field: 209,
1964
- Name: "testdata.x209",
1965
- Tag: "bytes,209,opt,name=x209",
1966
-}
1967
-
1968
-var E_X210 = &proto.ExtensionDesc{
1969
- ExtendedType: (*MyMessageSet)(nil),
1970
- ExtensionType: (*Empty)(nil),
1971
- Field: 210,
1972
- Name: "testdata.x210",
1973
- Tag: "bytes,210,opt,name=x210",
1974
-}
1975
-
1976
-var E_X211 = &proto.ExtensionDesc{
1977
- ExtendedType: (*MyMessageSet)(nil),
1978
- ExtensionType: (*Empty)(nil),
1979
- Field: 211,
1980
- Name: "testdata.x211",
1981
- Tag: "bytes,211,opt,name=x211",
1982
-}
1983
-
1984
-var E_X212 = &proto.ExtensionDesc{
1985
- ExtendedType: (*MyMessageSet)(nil),
1986
- ExtensionType: (*Empty)(nil),
1987
- Field: 212,
1988
- Name: "testdata.x212",
1989
- Tag: "bytes,212,opt,name=x212",
1990
-}
1991
-
1992
-var E_X213 = &proto.ExtensionDesc{
1993
- ExtendedType: (*MyMessageSet)(nil),
1994
- ExtensionType: (*Empty)(nil),
1995
- Field: 213,
1996
- Name: "testdata.x213",
1997
- Tag: "bytes,213,opt,name=x213",
1998
-}
1999
-
2000
-var E_X214 = &proto.ExtensionDesc{
2001
- ExtendedType: (*MyMessageSet)(nil),
2002
- ExtensionType: (*Empty)(nil),
2003
- Field: 214,
2004
- Name: "testdata.x214",
2005
- Tag: "bytes,214,opt,name=x214",
2006
-}
2007
-
2008
-var E_X215 = &proto.ExtensionDesc{
2009
- ExtendedType: (*MyMessageSet)(nil),
2010
- ExtensionType: (*Empty)(nil),
2011
- Field: 215,
2012
- Name: "testdata.x215",
2013
- Tag: "bytes,215,opt,name=x215",
2014
-}
2015
-
2016
-var E_X216 = &proto.ExtensionDesc{
2017
- ExtendedType: (*MyMessageSet)(nil),
2018
- ExtensionType: (*Empty)(nil),
2019
- Field: 216,
2020
- Name: "testdata.x216",
2021
- Tag: "bytes,216,opt,name=x216",
2022
-}
2023
-
2024
-var E_X217 = &proto.ExtensionDesc{
2025
- ExtendedType: (*MyMessageSet)(nil),
2026
- ExtensionType: (*Empty)(nil),
2027
- Field: 217,
2028
- Name: "testdata.x217",
2029
- Tag: "bytes,217,opt,name=x217",
2030
-}
2031
-
2032
-var E_X218 = &proto.ExtensionDesc{
2033
- ExtendedType: (*MyMessageSet)(nil),
2034
- ExtensionType: (*Empty)(nil),
2035
- Field: 218,
2036
- Name: "testdata.x218",
2037
- Tag: "bytes,218,opt,name=x218",
2038
-}
2039
-
2040
-var E_X219 = &proto.ExtensionDesc{
2041
- ExtendedType: (*MyMessageSet)(nil),
2042
- ExtensionType: (*Empty)(nil),
2043
- Field: 219,
2044
- Name: "testdata.x219",
2045
- Tag: "bytes,219,opt,name=x219",
2046
-}
2047
-
2048
-var E_X220 = &proto.ExtensionDesc{
2049
- ExtendedType: (*MyMessageSet)(nil),
2050
- ExtensionType: (*Empty)(nil),
2051
- Field: 220,
2052
- Name: "testdata.x220",
2053
- Tag: "bytes,220,opt,name=x220",
2054
-}
2055
-
2056
-var E_X221 = &proto.ExtensionDesc{
2057
- ExtendedType: (*MyMessageSet)(nil),
2058
- ExtensionType: (*Empty)(nil),
2059
- Field: 221,
2060
- Name: "testdata.x221",
2061
- Tag: "bytes,221,opt,name=x221",
2062
-}
2063
-
2064
-var E_X222 = &proto.ExtensionDesc{
2065
- ExtendedType: (*MyMessageSet)(nil),
2066
- ExtensionType: (*Empty)(nil),
2067
- Field: 222,
2068
- Name: "testdata.x222",
2069
- Tag: "bytes,222,opt,name=x222",
2070
-}
2071
-
2072
-var E_X223 = &proto.ExtensionDesc{
2073
- ExtendedType: (*MyMessageSet)(nil),
2074
- ExtensionType: (*Empty)(nil),
2075
- Field: 223,
2076
- Name: "testdata.x223",
2077
- Tag: "bytes,223,opt,name=x223",
2078
-}
2079
-
2080
-var E_X224 = &proto.ExtensionDesc{
2081
- ExtendedType: (*MyMessageSet)(nil),
2082
- ExtensionType: (*Empty)(nil),
2083
- Field: 224,
2084
- Name: "testdata.x224",
2085
- Tag: "bytes,224,opt,name=x224",
2086
-}
2087
-
2088
-var E_X225 = &proto.ExtensionDesc{
2089
- ExtendedType: (*MyMessageSet)(nil),
2090
- ExtensionType: (*Empty)(nil),
2091
- Field: 225,
2092
- Name: "testdata.x225",
2093
- Tag: "bytes,225,opt,name=x225",
2094
-}
2095
-
2096
-var E_X226 = &proto.ExtensionDesc{
2097
- ExtendedType: (*MyMessageSet)(nil),
2098
- ExtensionType: (*Empty)(nil),
2099
- Field: 226,
2100
- Name: "testdata.x226",
2101
- Tag: "bytes,226,opt,name=x226",
2102
-}
2103
-
2104
-var E_X227 = &proto.ExtensionDesc{
2105
- ExtendedType: (*MyMessageSet)(nil),
2106
- ExtensionType: (*Empty)(nil),
2107
- Field: 227,
2108
- Name: "testdata.x227",
2109
- Tag: "bytes,227,opt,name=x227",
2110
-}
2111
-
2112
-var E_X228 = &proto.ExtensionDesc{
2113
- ExtendedType: (*MyMessageSet)(nil),
2114
- ExtensionType: (*Empty)(nil),
2115
- Field: 228,
2116
- Name: "testdata.x228",
2117
- Tag: "bytes,228,opt,name=x228",
2118
-}
2119
-
2120
-var E_X229 = &proto.ExtensionDesc{
2121
- ExtendedType: (*MyMessageSet)(nil),
2122
- ExtensionType: (*Empty)(nil),
2123
- Field: 229,
2124
- Name: "testdata.x229",
2125
- Tag: "bytes,229,opt,name=x229",
2126
-}
2127
-
2128
-var E_X230 = &proto.ExtensionDesc{
2129
- ExtendedType: (*MyMessageSet)(nil),
2130
- ExtensionType: (*Empty)(nil),
2131
- Field: 230,
2132
- Name: "testdata.x230",
2133
- Tag: "bytes,230,opt,name=x230",
2134
-}
2135
-
2136
-var E_X231 = &proto.ExtensionDesc{
2137
- ExtendedType: (*MyMessageSet)(nil),
2138
- ExtensionType: (*Empty)(nil),
2139
- Field: 231,
2140
- Name: "testdata.x231",
2141
- Tag: "bytes,231,opt,name=x231",
2142
-}
2143
-
2144
-var E_X232 = &proto.ExtensionDesc{
2145
- ExtendedType: (*MyMessageSet)(nil),
2146
- ExtensionType: (*Empty)(nil),
2147
- Field: 232,
2148
- Name: "testdata.x232",
2149
- Tag: "bytes,232,opt,name=x232",
2150
-}
2151
-
2152
-var E_X233 = &proto.ExtensionDesc{
2153
- ExtendedType: (*MyMessageSet)(nil),
2154
- ExtensionType: (*Empty)(nil),
2155
- Field: 233,
2156
- Name: "testdata.x233",
2157
- Tag: "bytes,233,opt,name=x233",
2158
-}
2159
-
2160
-var E_X234 = &proto.ExtensionDesc{
2161
- ExtendedType: (*MyMessageSet)(nil),
2162
- ExtensionType: (*Empty)(nil),
2163
- Field: 234,
2164
- Name: "testdata.x234",
2165
- Tag: "bytes,234,opt,name=x234",
2166
-}
2167
-
2168
-var E_X235 = &proto.ExtensionDesc{
2169
- ExtendedType: (*MyMessageSet)(nil),
2170
- ExtensionType: (*Empty)(nil),
2171
- Field: 235,
2172
- Name: "testdata.x235",
2173
- Tag: "bytes,235,opt,name=x235",
2174
-}
2175
-
2176
-var E_X236 = &proto.ExtensionDesc{
2177
- ExtendedType: (*MyMessageSet)(nil),
2178
- ExtensionType: (*Empty)(nil),
2179
- Field: 236,
2180
- Name: "testdata.x236",
2181
- Tag: "bytes,236,opt,name=x236",
2182
-}
2183
-
2184
-var E_X237 = &proto.ExtensionDesc{
2185
- ExtendedType: (*MyMessageSet)(nil),
2186
- ExtensionType: (*Empty)(nil),
2187
- Field: 237,
2188
- Name: "testdata.x237",
2189
- Tag: "bytes,237,opt,name=x237",
2190
-}
2191
-
2192
-var E_X238 = &proto.ExtensionDesc{
2193
- ExtendedType: (*MyMessageSet)(nil),
2194
- ExtensionType: (*Empty)(nil),
2195
- Field: 238,
2196
- Name: "testdata.x238",
2197
- Tag: "bytes,238,opt,name=x238",
2198
-}
2199
-
2200
-var E_X239 = &proto.ExtensionDesc{
2201
- ExtendedType: (*MyMessageSet)(nil),
2202
- ExtensionType: (*Empty)(nil),
2203
- Field: 239,
2204
- Name: "testdata.x239",
2205
- Tag: "bytes,239,opt,name=x239",
2206
-}
2207
-
2208
-var E_X240 = &proto.ExtensionDesc{
2209
- ExtendedType: (*MyMessageSet)(nil),
2210
- ExtensionType: (*Empty)(nil),
2211
- Field: 240,
2212
- Name: "testdata.x240",
2213
- Tag: "bytes,240,opt,name=x240",
2214
-}
2215
-
2216
-var E_X241 = &proto.ExtensionDesc{
2217
- ExtendedType: (*MyMessageSet)(nil),
2218
- ExtensionType: (*Empty)(nil),
2219
- Field: 241,
2220
- Name: "testdata.x241",
2221
- Tag: "bytes,241,opt,name=x241",
2222
-}
2223
-
2224
-var E_X242 = &proto.ExtensionDesc{
2225
- ExtendedType: (*MyMessageSet)(nil),
2226
- ExtensionType: (*Empty)(nil),
2227
- Field: 242,
2228
- Name: "testdata.x242",
2229
- Tag: "bytes,242,opt,name=x242",
2230
-}
2231
-
2232
-var E_X243 = &proto.ExtensionDesc{
2233
- ExtendedType: (*MyMessageSet)(nil),
2234
- ExtensionType: (*Empty)(nil),
2235
- Field: 243,
2236
- Name: "testdata.x243",
2237
- Tag: "bytes,243,opt,name=x243",
2238
-}
2239
-
2240
-var E_X244 = &proto.ExtensionDesc{
2241
- ExtendedType: (*MyMessageSet)(nil),
2242
- ExtensionType: (*Empty)(nil),
2243
- Field: 244,
2244
- Name: "testdata.x244",
2245
- Tag: "bytes,244,opt,name=x244",
2246
-}
2247
-
2248
-var E_X245 = &proto.ExtensionDesc{
2249
- ExtendedType: (*MyMessageSet)(nil),
2250
- ExtensionType: (*Empty)(nil),
2251
- Field: 245,
2252
- Name: "testdata.x245",
2253
- Tag: "bytes,245,opt,name=x245",
2254
-}
2255
-
2256
-var E_X246 = &proto.ExtensionDesc{
2257
- ExtendedType: (*MyMessageSet)(nil),
2258
- ExtensionType: (*Empty)(nil),
2259
- Field: 246,
2260
- Name: "testdata.x246",
2261
- Tag: "bytes,246,opt,name=x246",
2262
-}
2263
-
2264
-var E_X247 = &proto.ExtensionDesc{
2265
- ExtendedType: (*MyMessageSet)(nil),
2266
- ExtensionType: (*Empty)(nil),
2267
- Field: 247,
2268
- Name: "testdata.x247",
2269
- Tag: "bytes,247,opt,name=x247",
2270
-}
2271
-
2272
-var E_X248 = &proto.ExtensionDesc{
2273
- ExtendedType: (*MyMessageSet)(nil),
2274
- ExtensionType: (*Empty)(nil),
2275
- Field: 248,
2276
- Name: "testdata.x248",
2277
- Tag: "bytes,248,opt,name=x248",
2278
-}
2279
-
2280
-var E_X249 = &proto.ExtensionDesc{
2281
- ExtendedType: (*MyMessageSet)(nil),
2282
- ExtensionType: (*Empty)(nil),
2283
- Field: 249,
2284
- Name: "testdata.x249",
2285
- Tag: "bytes,249,opt,name=x249",
2286
-}
2287
-
2288
-var E_X250 = &proto.ExtensionDesc{
2289
- ExtendedType: (*MyMessageSet)(nil),
2290
- ExtensionType: (*Empty)(nil),
2291
- Field: 250,
2292
- Name: "testdata.x250",
2293
- Tag: "bytes,250,opt,name=x250",
2294
-}
2295
-
2296
-func init() {
2297
- proto.RegisterEnum("testdata.FOO", FOO_name, FOO_value)
2298
- proto.RegisterEnum("testdata.GoTest_KIND", GoTest_KIND_name, GoTest_KIND_value)
2299
- proto.RegisterEnum("testdata.MyMessage_Color", MyMessage_Color_name, MyMessage_Color_value)
2300
- proto.RegisterEnum("testdata.Defaults_Color", Defaults_Color_name, Defaults_Color_value)
2301
- proto.RegisterEnum("testdata.RepeatedEnum_Color", RepeatedEnum_Color_name, RepeatedEnum_Color_value)
2302
- proto.RegisterExtension(E_Ext_More)
2303
- proto.RegisterExtension(E_Ext_Text)
2304
- proto.RegisterExtension(E_Ext_Number)
2305
- proto.RegisterExtension(E_Greeting)
2306
- proto.RegisterExtension(E_X201)
2307
- proto.RegisterExtension(E_X202)
2308
- proto.RegisterExtension(E_X203)
2309
- proto.RegisterExtension(E_X204)
2310
- proto.RegisterExtension(E_X205)
2311
- proto.RegisterExtension(E_X206)
2312
- proto.RegisterExtension(E_X207)
2313
- proto.RegisterExtension(E_X208)
2314
- proto.RegisterExtension(E_X209)
2315
- proto.RegisterExtension(E_X210)
2316
- proto.RegisterExtension(E_X211)
2317
- proto.RegisterExtension(E_X212)
2318
- proto.RegisterExtension(E_X213)
2319
- proto.RegisterExtension(E_X214)
2320
- proto.RegisterExtension(E_X215)
2321
- proto.RegisterExtension(E_X216)
2322
- proto.RegisterExtension(E_X217)
2323
- proto.RegisterExtension(E_X218)
2324
- proto.RegisterExtension(E_X219)
2325
- proto.RegisterExtension(E_X220)
2326
- proto.RegisterExtension(E_X221)
2327
- proto.RegisterExtension(E_X222)
2328
- proto.RegisterExtension(E_X223)
2329
- proto.RegisterExtension(E_X224)
2330
- proto.RegisterExtension(E_X225)
2331
- proto.RegisterExtension(E_X226)
2332
- proto.RegisterExtension(E_X227)
2333
- proto.RegisterExtension(E_X228)
2334
- proto.RegisterExtension(E_X229)
2335
- proto.RegisterExtension(E_X230)
2336
- proto.RegisterExtension(E_X231)
2337
- proto.RegisterExtension(E_X232)
2338
- proto.RegisterExtension(E_X233)
2339
- proto.RegisterExtension(E_X234)
2340
- proto.RegisterExtension(E_X235)
2341
- proto.RegisterExtension(E_X236)
2342
- proto.RegisterExtension(E_X237)
2343
- proto.RegisterExtension(E_X238)
2344
- proto.RegisterExtension(E_X239)
2345
- proto.RegisterExtension(E_X240)
2346
- proto.RegisterExtension(E_X241)
2347
- proto.RegisterExtension(E_X242)
2348
- proto.RegisterExtension(E_X243)
2349
- proto.RegisterExtension(E_X244)
2350
- proto.RegisterExtension(E_X245)
2351
- proto.RegisterExtension(E_X246)
2352
- proto.RegisterExtension(E_X247)
2353
- proto.RegisterExtension(E_X248)
2354
- proto.RegisterExtension(E_X249)
2355
- proto.RegisterExtension(E_X250)
2356
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/testdata/test.pb.go.golden
deleted
-1737
@@ -1,1737 +0,0 @@
1
-// Code generated by protoc-gen-gogo.
2
-// source: test.proto
3
-// DO NOT EDIT!
4
-
5
-package testdata
6
-
7
-import proto "github.com/gogo/protobuf/proto"
8
-import json "encoding/json"
9
-import math "math"
10
-
11
-import ()
12
-
13
-// Reference proto, json, and math imports to suppress error if they are not otherwise used.
14
-var _ = proto.Marshal
15
-var _ = &json.SyntaxError{}
16
-var _ = math.Inf
17
-
18
-type FOO int32
19
-
20
-const (
21
- FOO_FOO1 FOO = 1
22
-)
23
-
24
-var FOO_name = map[int32]string{
25
- 1: "FOO1",
26
-}
27
-var FOO_value = map[string]int32{
28
- "FOO1": 1,
29
-}
30
-
31
-func (x FOO) Enum() *FOO {
32
- p := new(FOO)
33
- *p = x
34
- return p
35
-}
36
-func (x FOO) String() string {
37
- return proto.EnumName(FOO_name, int32(x))
38
-}
39
-func (x FOO) MarshalJSON() ([]byte, error) {
40
- return json.Marshal(x.String())
41
-}
42
-func (x *FOO) UnmarshalJSON(data []byte) error {
43
- value, err := proto.UnmarshalJSONEnum(FOO_value, data, "FOO")
44
- if err != nil {
45
- return err
46
- }
47
- *x = FOO(value)
48
- return nil
49
-}
50
-
51
-type GoTest_KIND int32
52
-
53
-const (
54
- GoTest_VOID GoTest_KIND = 0
55
- GoTest_BOOL GoTest_KIND = 1
56
- GoTest_BYTES GoTest_KIND = 2
57
- GoTest_FINGERPRINT GoTest_KIND = 3
58
- GoTest_FLOAT GoTest_KIND = 4
59
- GoTest_INT GoTest_KIND = 5
60
- GoTest_STRING GoTest_KIND = 6
61
- GoTest_TIME GoTest_KIND = 7
62
- GoTest_TUPLE GoTest_KIND = 8
63
- GoTest_ARRAY GoTest_KIND = 9
64
- GoTest_MAP GoTest_KIND = 10
65
- GoTest_TABLE GoTest_KIND = 11
66
- GoTest_FUNCTION GoTest_KIND = 12
67
-)
68
-
69
-var GoTest_KIND_name = map[int32]string{
70
- 0: "VOID",
71
- 1: "BOOL",
72
- 2: "BYTES",
73
- 3: "FINGERPRINT",
74
- 4: "FLOAT",
75
- 5: "INT",
76
- 6: "STRING",
77
- 7: "TIME",
78
- 8: "TUPLE",
79
- 9: "ARRAY",
80
- 10: "MAP",
81
- 11: "TABLE",
82
- 12: "FUNCTION",
83
-}
84
-var GoTest_KIND_value = map[string]int32{
85
- "VOID": 0,
86
- "BOOL": 1,
87
- "BYTES": 2,
88
- "FINGERPRINT": 3,
89
- "FLOAT": 4,
90
- "INT": 5,
91
- "STRING": 6,
92
- "TIME": 7,
93
- "TUPLE": 8,
94
- "ARRAY": 9,
95
- "MAP": 10,
96
- "TABLE": 11,
97
- "FUNCTION": 12,
98
-}
99
-
100
-func (x GoTest_KIND) Enum() *GoTest_KIND {
101
- p := new(GoTest_KIND)
102
- *p = x
103
- return p
104
-}
105
-func (x GoTest_KIND) String() string {
106
- return proto.EnumName(GoTest_KIND_name, int32(x))
107
-}
108
-func (x GoTest_KIND) MarshalJSON() ([]byte, error) {
109
- return json.Marshal(x.String())
110
-}
111
-func (x *GoTest_KIND) UnmarshalJSON(data []byte) error {
112
- value, err := proto.UnmarshalJSONEnum(GoTest_KIND_value, data, "GoTest_KIND")
113
- if err != nil {
114
- return err
115
- }
116
- *x = GoTest_KIND(value)
117
- return nil
118
-}
119
-
120
-type MyMessage_Color int32
121
-
122
-const (
123
- MyMessage_RED MyMessage_Color = 0
124
- MyMessage_GREEN MyMessage_Color = 1
125
- MyMessage_BLUE MyMessage_Color = 2
126
-)
127
-
128
-var MyMessage_Color_name = map[int32]string{
129
- 0: "RED",
130
- 1: "GREEN",
131
- 2: "BLUE",
132
-}
133
-var MyMessage_Color_value = map[string]int32{
134
- "RED": 0,
135
- "GREEN": 1,
136
- "BLUE": 2,
137
-}
138
-
139
-func (x MyMessage_Color) Enum() *MyMessage_Color {
140
- p := new(MyMessage_Color)
141
- *p = x
142
- return p
143
-}
144
-func (x MyMessage_Color) String() string {
145
- return proto.EnumName(MyMessage_Color_name, int32(x))
146
-}
147
-func (x MyMessage_Color) MarshalJSON() ([]byte, error) {
148
- return json.Marshal(x.String())
149
-}
150
-func (x *MyMessage_Color) UnmarshalJSON(data []byte) error {
151
- value, err := proto.UnmarshalJSONEnum(MyMessage_Color_value, data, "MyMessage_Color")
152
- if err != nil {
153
- return err
154
- }
155
- *x = MyMessage_Color(value)
156
- return nil
157
-}
158
-
159
-type Defaults_Color int32
160
-
161
-const (
162
- Defaults_RED Defaults_Color = 0
163
- Defaults_GREEN Defaults_Color = 1
164
- Defaults_BLUE Defaults_Color = 2
165
-)
166
-
167
-var Defaults_Color_name = map[int32]string{
168
- 0: "RED",
169
- 1: "GREEN",
170
- 2: "BLUE",
171
-}
172
-var Defaults_Color_value = map[string]int32{
173
- "RED": 0,
174
- "GREEN": 1,
175
- "BLUE": 2,
176
-}
177
-
178
-func (x Defaults_Color) Enum() *Defaults_Color {
179
- p := new(Defaults_Color)
180
- *p = x
181
- return p
182
-}
183
-func (x Defaults_Color) String() string {
184
- return proto.EnumName(Defaults_Color_name, int32(x))
185
-}
186
-func (x Defaults_Color) MarshalJSON() ([]byte, error) {
187
- return json.Marshal(x.String())
188
-}
189
-func (x *Defaults_Color) UnmarshalJSON(data []byte) error {
190
- value, err := proto.UnmarshalJSONEnum(Defaults_Color_value, data, "Defaults_Color")
191
- if err != nil {
192
- return err
193
- }
194
- *x = Defaults_Color(value)
195
- return nil
196
-}
197
-
198
-type RepeatedEnum_Color int32
199
-
200
-const (
201
- RepeatedEnum_RED RepeatedEnum_Color = 1
202
-)
203
-
204
-var RepeatedEnum_Color_name = map[int32]string{
205
- 1: "RED",
206
-}
207
-var RepeatedEnum_Color_value = map[string]int32{
208
- "RED": 1,
209
-}
210
-
211
-func (x RepeatedEnum_Color) Enum() *RepeatedEnum_Color {
212
- p := new(RepeatedEnum_Color)
213
- *p = x
214
- return p
215
-}
216
-func (x RepeatedEnum_Color) String() string {
217
- return proto.EnumName(RepeatedEnum_Color_name, int32(x))
218
-}
219
-func (x RepeatedEnum_Color) MarshalJSON() ([]byte, error) {
220
- return json.Marshal(x.String())
221
-}
222
-func (x *RepeatedEnum_Color) UnmarshalJSON(data []byte) error {
223
- value, err := proto.UnmarshalJSONEnum(RepeatedEnum_Color_value, data, "RepeatedEnum_Color")
224
- if err != nil {
225
- return err
226
- }
227
- *x = RepeatedEnum_Color(value)
228
- return nil
229
-}
230
-
231
-type GoEnum struct {
232
- Foo *FOO `protobuf:"varint,1,req,name=foo,enum=testdata.FOO" json:"foo,omitempty"`
233
- XXX_unrecognized []byte `json:"-"`
234
-}
235
-
236
-func (m *GoEnum) Reset() { *m = GoEnum{} }
237
-func (m *GoEnum) String() string { return proto.CompactTextString(m) }
238
-func (*GoEnum) ProtoMessage() {}
239
-
240
-func (m *GoEnum) GetFoo() FOO {
241
- if m != nil && m.Foo != nil {
242
- return *m.Foo
243
- }
244
- return 0
245
-}
246
-
247
-type GoTestField struct {
248
- Label *string `protobuf:"bytes,1,req" json:"Label,omitempty"`
249
- Type *string `protobuf:"bytes,2,req" json:"Type,omitempty"`
250
- XXX_unrecognized []byte `json:"-"`
251
-}
252
-
253
-func (m *GoTestField) Reset() { *m = GoTestField{} }
254
-func (m *GoTestField) String() string { return proto.CompactTextString(m) }
255
-func (*GoTestField) ProtoMessage() {}
256
-
257
-func (m *GoTestField) GetLabel() string {
258
- if m != nil && m.Label != nil {
259
- return *m.Label
260
- }
261
- return ""
262
-}
263
-
264
-func (m *GoTestField) GetType() string {
265
- if m != nil && m.Type != nil {
266
- return *m.Type
267
- }
268
- return ""
269
-}
270
-
271
-type GoTest struct {
272
- Kind *GoTest_KIND `protobuf:"varint,1,req,enum=testdata.GoTest_KIND" json:"Kind,omitempty"`
273
- Table *string `protobuf:"bytes,2,opt" json:"Table,omitempty"`
274
- Param *int32 `protobuf:"varint,3,opt" json:"Param,omitempty"`
275
- RequiredField *GoTestField `protobuf:"bytes,4,req" json:"RequiredField,omitempty"`
276
- RepeatedField []*GoTestField `protobuf:"bytes,5,rep" json:"RepeatedField,omitempty"`
277
- OptionalField *GoTestField `protobuf:"bytes,6,opt" json:"OptionalField,omitempty"`
278
- F_BoolRequired *bool `protobuf:"varint,10,req,name=F_Bool_required" json:"F_Bool_required,omitempty"`
279
- F_Int32Required *int32 `protobuf:"varint,11,req,name=F_Int32_required" json:"F_Int32_required,omitempty"`
280
- F_Int64Required *int64 `protobuf:"varint,12,req,name=F_Int64_required" json:"F_Int64_required,omitempty"`
281
- F_Fixed32Required *uint32 `protobuf:"fixed32,13,req,name=F_Fixed32_required" json:"F_Fixed32_required,omitempty"`
282
- F_Fixed64Required *uint64 `protobuf:"fixed64,14,req,name=F_Fixed64_required" json:"F_Fixed64_required,omitempty"`
283
- F_Uint32Required *uint32 `protobuf:"varint,15,req,name=F_Uint32_required" json:"F_Uint32_required,omitempty"`
284
- F_Uint64Required *uint64 `protobuf:"varint,16,req,name=F_Uint64_required" json:"F_Uint64_required,omitempty"`
285
- F_FloatRequired *float32 `protobuf:"fixed32,17,req,name=F_Float_required" json:"F_Float_required,omitempty"`
286
- F_DoubleRequired *float64 `protobuf:"fixed64,18,req,name=F_Double_required" json:"F_Double_required,omitempty"`
287
- F_StringRequired *string `protobuf:"bytes,19,req,name=F_String_required" json:"F_String_required,omitempty"`
288
- F_BytesRequired []byte `protobuf:"bytes,101,req,name=F_Bytes_required" json:"F_Bytes_required,omitempty"`
289
- F_Sint32Required *int32 `protobuf:"zigzag32,102,req,name=F_Sint32_required" json:"F_Sint32_required,omitempty"`
290
- F_Sint64Required *int64 `protobuf:"zigzag64,103,req,name=F_Sint64_required" json:"F_Sint64_required,omitempty"`
291
- F_BoolRepeated []bool `protobuf:"varint,20,rep,name=F_Bool_repeated" json:"F_Bool_repeated,omitempty"`
292
- F_Int32Repeated []int32 `protobuf:"varint,21,rep,name=F_Int32_repeated" json:"F_Int32_repeated,omitempty"`
293
- F_Int64Repeated []int64 `protobuf:"varint,22,rep,name=F_Int64_repeated" json:"F_Int64_repeated,omitempty"`
294
- F_Fixed32Repeated []uint32 `protobuf:"fixed32,23,rep,name=F_Fixed32_repeated" json:"F_Fixed32_repeated,omitempty"`
295
- F_Fixed64Repeated []uint64 `protobuf:"fixed64,24,rep,name=F_Fixed64_repeated" json:"F_Fixed64_repeated,omitempty"`
296
- F_Uint32Repeated []uint32 `protobuf:"varint,25,rep,name=F_Uint32_repeated" json:"F_Uint32_repeated,omitempty"`
297
- F_Uint64Repeated []uint64 `protobuf:"varint,26,rep,name=F_Uint64_repeated" json:"F_Uint64_repeated,omitempty"`
298
- F_FloatRepeated []float32 `protobuf:"fixed32,27,rep,name=F_Float_repeated" json:"F_Float_repeated,omitempty"`
299
- F_DoubleRepeated []float64 `protobuf:"fixed64,28,rep,name=F_Double_repeated" json:"F_Double_repeated,omitempty"`
300
- F_StringRepeated []string `protobuf:"bytes,29,rep,name=F_String_repeated" json:"F_String_repeated,omitempty"`
301
- F_BytesRepeated [][]byte `protobuf:"bytes,201,rep,name=F_Bytes_repeated" json:"F_Bytes_repeated,omitempty"`
302
- F_Sint32Repeated []int32 `protobuf:"zigzag32,202,rep,name=F_Sint32_repeated" json:"F_Sint32_repeated,omitempty"`
303
- F_Sint64Repeated []int64 `protobuf:"zigzag64,203,rep,name=F_Sint64_repeated" json:"F_Sint64_repeated,omitempty"`
304
- F_BoolOptional *bool `protobuf:"varint,30,opt,name=F_Bool_optional" json:"F_Bool_optional,omitempty"`
305
- F_Int32Optional *int32 `protobuf:"varint,31,opt,name=F_Int32_optional" json:"F_Int32_optional,omitempty"`
306
- F_Int64Optional *int64 `protobuf:"varint,32,opt,name=F_Int64_optional" json:"F_Int64_optional,omitempty"`
307
- F_Fixed32Optional *uint32 `protobuf:"fixed32,33,opt,name=F_Fixed32_optional" json:"F_Fixed32_optional,omitempty"`
308
- F_Fixed64Optional *uint64 `protobuf:"fixed64,34,opt,name=F_Fixed64_optional" json:"F_Fixed64_optional,omitempty"`
309
- F_Uint32Optional *uint32 `protobuf:"varint,35,opt,name=F_Uint32_optional" json:"F_Uint32_optional,omitempty"`
310
- F_Uint64Optional *uint64 `protobuf:"varint,36,opt,name=F_Uint64_optional" json:"F_Uint64_optional,omitempty"`
311
- F_FloatOptional *float32 `protobuf:"fixed32,37,opt,name=F_Float_optional" json:"F_Float_optional,omitempty"`
312
- F_DoubleOptional *float64 `protobuf:"fixed64,38,opt,name=F_Double_optional" json:"F_Double_optional,omitempty"`
313
- F_StringOptional *string `protobuf:"bytes,39,opt,name=F_String_optional" json:"F_String_optional,omitempty"`
314
- F_BytesOptional []byte `protobuf:"bytes,301,opt,name=F_Bytes_optional" json:"F_Bytes_optional,omitempty"`
315
- F_Sint32Optional *int32 `protobuf:"zigzag32,302,opt,name=F_Sint32_optional" json:"F_Sint32_optional,omitempty"`
316
- F_Sint64Optional *int64 `protobuf:"zigzag64,303,opt,name=F_Sint64_optional" json:"F_Sint64_optional,omitempty"`
317
- F_BoolDefaulted *bool `protobuf:"varint,40,opt,name=F_Bool_defaulted,def=1" json:"F_Bool_defaulted,omitempty"`
318
- F_Int32Defaulted *int32 `protobuf:"varint,41,opt,name=F_Int32_defaulted,def=32" json:"F_Int32_defaulted,omitempty"`
319
- F_Int64Defaulted *int64 `protobuf:"varint,42,opt,name=F_Int64_defaulted,def=64" json:"F_Int64_defaulted,omitempty"`
320
- F_Fixed32Defaulted *uint32 `protobuf:"fixed32,43,opt,name=F_Fixed32_defaulted,def=320" json:"F_Fixed32_defaulted,omitempty"`
321
- F_Fixed64Defaulted *uint64 `protobuf:"fixed64,44,opt,name=F_Fixed64_defaulted,def=640" json:"F_Fixed64_defaulted,omitempty"`
322
- F_Uint32Defaulted *uint32 `protobuf:"varint,45,opt,name=F_Uint32_defaulted,def=3200" json:"F_Uint32_defaulted,omitempty"`
323
- F_Uint64Defaulted *uint64 `protobuf:"varint,46,opt,name=F_Uint64_defaulted,def=6400" json:"F_Uint64_defaulted,omitempty"`
324
- F_FloatDefaulted *float32 `protobuf:"fixed32,47,opt,name=F_Float_defaulted,def=314159" json:"F_Float_defaulted,omitempty"`
325
- F_DoubleDefaulted *float64 `protobuf:"fixed64,48,opt,name=F_Double_defaulted,def=271828" json:"F_Double_defaulted,omitempty"`
326
- F_StringDefaulted *string `protobuf:"bytes,49,opt,name=F_String_defaulted,def=hello, \"world!\"\n" json:"F_String_defaulted,omitempty"`
327
- F_BytesDefaulted []byte `protobuf:"bytes,401,opt,name=F_Bytes_defaulted,def=Bignose" json:"F_Bytes_defaulted,omitempty"`
328
- F_Sint32Defaulted *int32 `protobuf:"zigzag32,402,opt,name=F_Sint32_defaulted,def=-32" json:"F_Sint32_defaulted,omitempty"`
329
- F_Sint64Defaulted *int64 `protobuf:"zigzag64,403,opt,name=F_Sint64_defaulted,def=-64" json:"F_Sint64_defaulted,omitempty"`
330
- F_BoolRepeatedPacked []bool `protobuf:"varint,50,rep,packed,name=F_Bool_repeated_packed" json:"F_Bool_repeated_packed,omitempty"`
331
- F_Int32RepeatedPacked []int32 `protobuf:"varint,51,rep,packed,name=F_Int32_repeated_packed" json:"F_Int32_repeated_packed,omitempty"`
332
- F_Int64RepeatedPacked []int64 `protobuf:"varint,52,rep,packed,name=F_Int64_repeated_packed" json:"F_Int64_repeated_packed,omitempty"`
333
- F_Fixed32RepeatedPacked []uint32 `protobuf:"fixed32,53,rep,packed,name=F_Fixed32_repeated_packed" json:"F_Fixed32_repeated_packed,omitempty"`
334
- F_Fixed64RepeatedPacked []uint64 `protobuf:"fixed64,54,rep,packed,name=F_Fixed64_repeated_packed" json:"F_Fixed64_repeated_packed,omitempty"`
335
- F_Uint32RepeatedPacked []uint32 `protobuf:"varint,55,rep,packed,name=F_Uint32_repeated_packed" json:"F_Uint32_repeated_packed,omitempty"`
336
- F_Uint64RepeatedPacked []uint64 `protobuf:"varint,56,rep,packed,name=F_Uint64_repeated_packed" json:"F_Uint64_repeated_packed,omitempty"`
337
- F_FloatRepeatedPacked []float32 `protobuf:"fixed32,57,rep,packed,name=F_Float_repeated_packed" json:"F_Float_repeated_packed,omitempty"`
338
- F_DoubleRepeatedPacked []float64 `protobuf:"fixed64,58,rep,packed,name=F_Double_repeated_packed" json:"F_Double_repeated_packed,omitempty"`
339
- F_Sint32RepeatedPacked []int32 `protobuf:"zigzag32,502,rep,packed,name=F_Sint32_repeated_packed" json:"F_Sint32_repeated_packed,omitempty"`
340
- F_Sint64RepeatedPacked []int64 `protobuf:"zigzag64,503,rep,packed,name=F_Sint64_repeated_packed" json:"F_Sint64_repeated_packed,omitempty"`
341
- Requiredgroup *GoTest_RequiredGroup `protobuf:"group,70,req,name=RequiredGroup" json:"requiredgroup,omitempty"`
342
- Repeatedgroup []*GoTest_RepeatedGroup `protobuf:"group,80,rep,name=RepeatedGroup" json:"repeatedgroup,omitempty"`
343
- Optionalgroup *GoTest_OptionalGroup `protobuf:"group,90,opt,name=OptionalGroup" json:"optionalgroup,omitempty"`
344
- XXX_unrecognized []byte `json:"-"`
345
-}
346
-
347
-func (m *GoTest) Reset() { *m = GoTest{} }
348
-func (m *GoTest) String() string { return proto.CompactTextString(m) }
349
-func (*GoTest) ProtoMessage() {}
350
-
351
-const Default_GoTest_F_BoolDefaulted bool = true
352
-const Default_GoTest_F_Int32Defaulted int32 = 32
353
-const Default_GoTest_F_Int64Defaulted int64 = 64
354
-const Default_GoTest_F_Fixed32Defaulted uint32 = 320
355
-const Default_GoTest_F_Fixed64Defaulted uint64 = 640
356
-const Default_GoTest_F_Uint32Defaulted uint32 = 3200
357
-const Default_GoTest_F_Uint64Defaulted uint64 = 6400
358
-const Default_GoTest_F_FloatDefaulted float32 = 314159
359
-const Default_GoTest_F_DoubleDefaulted float64 = 271828
360
-const Default_GoTest_F_StringDefaulted string = "hello, \"world!\"\n"
361
-
362
-var Default_GoTest_F_BytesDefaulted []byte = []byte("Bignose")
363
-
364
-const Default_GoTest_F_Sint32Defaulted int32 = -32
365
-const Default_GoTest_F_Sint64Defaulted int64 = -64
366
-
367
-func (m *GoTest) GetKind() GoTest_KIND {
368
- if m != nil && m.Kind != nil {
369
- return *m.Kind
370
- }
371
- return 0
372
-}
373
-
374
-func (m *GoTest) GetTable() string {
375
- if m != nil && m.Table != nil {
376
- return *m.Table
377
- }
378
- return ""
379
-}
380
-
381
-func (m *GoTest) GetParam() int32 {
382
- if m != nil && m.Param != nil {
383
- return *m.Param
384
- }
385
- return 0
386
-}
387
-
388
-func (m *GoTest) GetRequiredField() *GoTestField {
389
- if m != nil {
390
- return m.RequiredField
391
- }
392
- return nil
393
-}
394
-
395
-func (m *GoTest) GetRepeatedField() []*GoTestField {
396
- if m != nil {
397
- return m.RepeatedField
398
- }
399
- return nil
400
-}
401
-
402
-func (m *GoTest) GetOptionalField() *GoTestField {
403
- if m != nil {
404
- return m.OptionalField
405
- }
406
- return nil
407
-}
408
-
409
-func (m *GoTest) GetF_BoolRequired() bool {
410
- if m != nil && m.F_BoolRequired != nil {
411
- return *m.F_BoolRequired
412
- }
413
- return false
414
-}
415
-
416
-func (m *GoTest) GetF_Int32Required() int32 {
417
- if m != nil && m.F_Int32Required != nil {
418
- return *m.F_Int32Required
419
- }
420
- return 0
421
-}
422
-
423
-func (m *GoTest) GetF_Int64Required() int64 {
424
- if m != nil && m.F_Int64Required != nil {
425
- return *m.F_Int64Required
426
- }
427
- return 0
428
-}
429
-
430
-func (m *GoTest) GetF_Fixed32Required() uint32 {
431
- if m != nil && m.F_Fixed32Required != nil {
432
- return *m.F_Fixed32Required
433
- }
434
- return 0
435
-}
436
-
437
-func (m *GoTest) GetF_Fixed64Required() uint64 {
438
- if m != nil && m.F_Fixed64Required != nil {
439
- return *m.F_Fixed64Required
440
- }
441
- return 0
442
-}
443
-
444
-func (m *GoTest) GetF_Uint32Required() uint32 {
445
- if m != nil && m.F_Uint32Required != nil {
446
- return *m.F_Uint32Required
447
- }
448
- return 0
449
-}
450
-
451
-func (m *GoTest) GetF_Uint64Required() uint64 {
452
- if m != nil && m.F_Uint64Required != nil {
453
- return *m.F_Uint64Required
454
- }
455
- return 0
456
-}
457
-
458
-func (m *GoTest) GetF_FloatRequired() float32 {
459
- if m != nil && m.F_FloatRequired != nil {
460
- return *m.F_FloatRequired
461
- }
462
- return 0
463
-}
464
-
465
-func (m *GoTest) GetF_DoubleRequired() float64 {
466
- if m != nil && m.F_DoubleRequired != nil {
467
- return *m.F_DoubleRequired
468
- }
469
- return 0
470
-}
471
-
472
-func (m *GoTest) GetF_StringRequired() string {
473
- if m != nil && m.F_StringRequired != nil {
474
- return *m.F_StringRequired
475
- }
476
- return ""
477
-}
478
-
479
-func (m *GoTest) GetF_BytesRequired() []byte {
480
- if m != nil {
481
- return m.F_BytesRequired
482
- }
483
- return nil
484
-}
485
-
486
-func (m *GoTest) GetF_Sint32Required() int32 {
487
- if m != nil && m.F_Sint32Required != nil {
488
- return *m.F_Sint32Required
489
- }
490
- return 0
491
-}
492
-
493
-func (m *GoTest) GetF_Sint64Required() int64 {
494
- if m != nil && m.F_Sint64Required != nil {
495
- return *m.F_Sint64Required
496
- }
497
- return 0
498
-}
499
-
500
-func (m *GoTest) GetF_BoolRepeated() []bool {
501
- if m != nil {
502
- return m.F_BoolRepeated
503
- }
504
- return nil
505
-}
506
-
507
-func (m *GoTest) GetF_Int32Repeated() []int32 {
508
- if m != nil {
509
- return m.F_Int32Repeated
510
- }
511
- return nil
512
-}
513
-
514
-func (m *GoTest) GetF_Int64Repeated() []int64 {
515
- if m != nil {
516
- return m.F_Int64Repeated
517
- }
518
- return nil
519
-}
520
-
521
-func (m *GoTest) GetF_Fixed32Repeated() []uint32 {
522
- if m != nil {
523
- return m.F_Fixed32Repeated
524
- }
525
- return nil
526
-}
527
-
528
-func (m *GoTest) GetF_Fixed64Repeated() []uint64 {
529
- if m != nil {
530
- return m.F_Fixed64Repeated
531
- }
532
- return nil
533
-}
534
-
535
-func (m *GoTest) GetF_Uint32Repeated() []uint32 {
536
- if m != nil {
537
- return m.F_Uint32Repeated
538
- }
539
- return nil
540
-}
541
-
542
-func (m *GoTest) GetF_Uint64Repeated() []uint64 {
543
- if m != nil {
544
- return m.F_Uint64Repeated
545
- }
546
- return nil
547
-}
548
-
549
-func (m *GoTest) GetF_FloatRepeated() []float32 {
550
- if m != nil {
551
- return m.F_FloatRepeated
552
- }
553
- return nil
554
-}
555
-
556
-func (m *GoTest) GetF_DoubleRepeated() []float64 {
557
- if m != nil {
558
- return m.F_DoubleRepeated
559
- }
560
- return nil
561
-}
562
-
563
-func (m *GoTest) GetF_StringRepeated() []string {
564
- if m != nil {
565
- return m.F_StringRepeated
566
- }
567
- return nil
568
-}
569
-
570
-func (m *GoTest) GetF_BytesRepeated() [][]byte {
571
- if m != nil {
572
- return m.F_BytesRepeated
573
- }
574
- return nil
575
-}
576
-
577
-func (m *GoTest) GetF_Sint32Repeated() []int32 {
578
- if m != nil {
579
- return m.F_Sint32Repeated
580
- }
581
- return nil
582
-}
583
-
584
-func (m *GoTest) GetF_Sint64Repeated() []int64 {
585
- if m != nil {
586
- return m.F_Sint64Repeated
587
- }
588
- return nil
589
-}
590
-
591
-func (m *GoTest) GetF_BoolOptional() bool {
592
- if m != nil && m.F_BoolOptional != nil {
593
- return *m.F_BoolOptional
594
- }
595
- return false
596
-}
597
-
598
-func (m *GoTest) GetF_Int32Optional() int32 {
599
- if m != nil && m.F_Int32Optional != nil {
600
- return *m.F_Int32Optional
601
- }
602
- return 0
603
-}
604
-
605
-func (m *GoTest) GetF_Int64Optional() int64 {
606
- if m != nil && m.F_Int64Optional != nil {
607
- return *m.F_Int64Optional
608
- }
609
- return 0
610
-}
611
-
612
-func (m *GoTest) GetF_Fixed32Optional() uint32 {
613
- if m != nil && m.F_Fixed32Optional != nil {
614
- return *m.F_Fixed32Optional
615
- }
616
- return 0
617
-}
618
-
619
-func (m *GoTest) GetF_Fixed64Optional() uint64 {
620
- if m != nil && m.F_Fixed64Optional != nil {
621
- return *m.F_Fixed64Optional
622
- }
623
- return 0
624
-}
625
-
626
-func (m *GoTest) GetF_Uint32Optional() uint32 {
627
- if m != nil && m.F_Uint32Optional != nil {
628
- return *m.F_Uint32Optional
629
- }
630
- return 0
631
-}
632
-
633
-func (m *GoTest) GetF_Uint64Optional() uint64 {
634
- if m != nil && m.F_Uint64Optional != nil {
635
- return *m.F_Uint64Optional
636
- }
637
- return 0
638
-}
639
-
640
-func (m *GoTest) GetF_FloatOptional() float32 {
641
- if m != nil && m.F_FloatOptional != nil {
642
- return *m.F_FloatOptional
643
- }
644
- return 0
645
-}
646
-
647
-func (m *GoTest) GetF_DoubleOptional() float64 {
648
- if m != nil && m.F_DoubleOptional != nil {
649
- return *m.F_DoubleOptional
650
- }
651
- return 0
652
-}
653
-
654
-func (m *GoTest) GetF_StringOptional() string {
655
- if m != nil && m.F_StringOptional != nil {
656
- return *m.F_StringOptional
657
- }
658
- return ""
659
-}
660
-
661
-func (m *GoTest) GetF_BytesOptional() []byte {
662
- if m != nil {
663
- return m.F_BytesOptional
664
- }
665
- return nil
666
-}
667
-
668
-func (m *GoTest) GetF_Sint32Optional() int32 {
669
- if m != nil && m.F_Sint32Optional != nil {
670
- return *m.F_Sint32Optional
671
- }
672
- return 0
673
-}
674
-
675
-func (m *GoTest) GetF_Sint64Optional() int64 {
676
- if m != nil && m.F_Sint64Optional != nil {
677
- return *m.F_Sint64Optional
678
- }
679
- return 0
680
-}
681
-
682
-func (m *GoTest) GetF_BoolDefaulted() bool {
683
- if m != nil && m.F_BoolDefaulted != nil {
684
- return *m.F_BoolDefaulted
685
- }
686
- return Default_GoTest_F_BoolDefaulted
687
-}
688
-
689
-func (m *GoTest) GetF_Int32Defaulted() int32 {
690
- if m != nil && m.F_Int32Defaulted != nil {
691
- return *m.F_Int32Defaulted
692
- }
693
- return Default_GoTest_F_Int32Defaulted
694
-}
695
-
696
-func (m *GoTest) GetF_Int64Defaulted() int64 {
697
- if m != nil && m.F_Int64Defaulted != nil {
698
- return *m.F_Int64Defaulted
699
- }
700
- return Default_GoTest_F_Int64Defaulted
701
-}
702
-
703
-func (m *GoTest) GetF_Fixed32Defaulted() uint32 {
704
- if m != nil && m.F_Fixed32Defaulted != nil {
705
- return *m.F_Fixed32Defaulted
706
- }
707
- return Default_GoTest_F_Fixed32Defaulted
708
-}
709
-
710
-func (m *GoTest) GetF_Fixed64Defaulted() uint64 {
711
- if m != nil && m.F_Fixed64Defaulted != nil {
712
- return *m.F_Fixed64Defaulted
713
- }
714
- return Default_GoTest_F_Fixed64Defaulted
715
-}
716
-
717
-func (m *GoTest) GetF_Uint32Defaulted() uint32 {
718
- if m != nil && m.F_Uint32Defaulted != nil {
719
- return *m.F_Uint32Defaulted
720
- }
721
- return Default_GoTest_F_Uint32Defaulted
722
-}
723
-
724
-func (m *GoTest) GetF_Uint64Defaulted() uint64 {
725
- if m != nil && m.F_Uint64Defaulted != nil {
726
- return *m.F_Uint64Defaulted
727
- }
728
- return Default_GoTest_F_Uint64Defaulted
729
-}
730
-
731
-func (m *GoTest) GetF_FloatDefaulted() float32 {
732
- if m != nil && m.F_FloatDefaulted != nil {
733
- return *m.F_FloatDefaulted
734
- }
735
- return Default_GoTest_F_FloatDefaulted
736
-}
737
-
738
-func (m *GoTest) GetF_DoubleDefaulted() float64 {
739
- if m != nil && m.F_DoubleDefaulted != nil {
740
- return *m.F_DoubleDefaulted
741
- }
742
- return Default_GoTest_F_DoubleDefaulted
743
-}
744
-
745
-func (m *GoTest) GetF_StringDefaulted() string {
746
- if m != nil && m.F_StringDefaulted != nil {
747
- return *m.F_StringDefaulted
748
- }
749
- return Default_GoTest_F_StringDefaulted
750
-}
751
-
752
-func (m *GoTest) GetF_BytesDefaulted() []byte {
753
- if m != nil && m.F_BytesDefaulted != nil {
754
- return m.F_BytesDefaulted
755
- }
756
- return append([]byte(nil), Default_GoTest_F_BytesDefaulted...)
757
-}
758
-
759
-func (m *GoTest) GetF_Sint32Defaulted() int32 {
760
- if m != nil && m.F_Sint32Defaulted != nil {
761
- return *m.F_Sint32Defaulted
762
- }
763
- return Default_GoTest_F_Sint32Defaulted
764
-}
765
-
766
-func (m *GoTest) GetF_Sint64Defaulted() int64 {
767
- if m != nil && m.F_Sint64Defaulted != nil {
768
- return *m.F_Sint64Defaulted
769
- }
770
- return Default_GoTest_F_Sint64Defaulted
771
-}
772
-
773
-func (m *GoTest) GetF_BoolRepeatedPacked() []bool {
774
- if m != nil {
775
- return m.F_BoolRepeatedPacked
776
- }
777
- return nil
778
-}
779
-
780
-func (m *GoTest) GetF_Int32RepeatedPacked() []int32 {
781
- if m != nil {
782
- return m.F_Int32RepeatedPacked
783
- }
784
- return nil
785
-}
786
-
787
-func (m *GoTest) GetF_Int64RepeatedPacked() []int64 {
788
- if m != nil {
789
- return m.F_Int64RepeatedPacked
790
- }
791
- return nil
792
-}
793
-
794
-func (m *GoTest) GetF_Fixed32RepeatedPacked() []uint32 {
795
- if m != nil {
796
- return m.F_Fixed32RepeatedPacked
797
- }
798
- return nil
799
-}
800
-
801
-func (m *GoTest) GetF_Fixed64RepeatedPacked() []uint64 {
802
- if m != nil {
803
- return m.F_Fixed64RepeatedPacked
804
- }
805
- return nil
806
-}
807
-
808
-func (m *GoTest) GetF_Uint32RepeatedPacked() []uint32 {
809
- if m != nil {
810
- return m.F_Uint32RepeatedPacked
811
- }
812
- return nil
813
-}
814
-
815
-func (m *GoTest) GetF_Uint64RepeatedPacked() []uint64 {
816
- if m != nil {
817
- return m.F_Uint64RepeatedPacked
818
- }
819
- return nil
820
-}
821
-
822
-func (m *GoTest) GetF_FloatRepeatedPacked() []float32 {
823
- if m != nil {
824
- return m.F_FloatRepeatedPacked
825
- }
826
- return nil
827
-}
828
-
829
-func (m *GoTest) GetF_DoubleRepeatedPacked() []float64 {
830
- if m != nil {
831
- return m.F_DoubleRepeatedPacked
832
- }
833
- return nil
834
-}
835
-
836
-func (m *GoTest) GetF_Sint32RepeatedPacked() []int32 {
837
- if m != nil {
838
- return m.F_Sint32RepeatedPacked
839
- }
840
- return nil
841
-}
842
-
843
-func (m *GoTest) GetF_Sint64RepeatedPacked() []int64 {
844
- if m != nil {
845
- return m.F_Sint64RepeatedPacked
846
- }
847
- return nil
848
-}
849
-
850
-func (m *GoTest) GetRequiredgroup() *GoTest_RequiredGroup {
851
- if m != nil {
852
- return m.Requiredgroup
853
- }
854
- return nil
855
-}
856
-
857
-func (m *GoTest) GetRepeatedgroup() []*GoTest_RepeatedGroup {
858
- if m != nil {
859
- return m.Repeatedgroup
860
- }
861
- return nil
862
-}
863
-
864
-func (m *GoTest) GetOptionalgroup() *GoTest_OptionalGroup {
865
- if m != nil {
866
- return m.Optionalgroup
867
- }
868
- return nil
869
-}
870
-
871
-type GoTest_RequiredGroup struct {
872
- RequiredField *string `protobuf:"bytes,71,req" json:"RequiredField,omitempty"`
873
- XXX_unrecognized []byte `json:"-"`
874
-}
875
-
876
-func (m *GoTest_RequiredGroup) Reset() { *m = GoTest_RequiredGroup{} }
877
-
878
-func (m *GoTest_RequiredGroup) GetRequiredField() string {
879
- if m != nil && m.RequiredField != nil {
880
- return *m.RequiredField
881
- }
882
- return ""
883
-}
884
-
885
-type GoTest_RepeatedGroup struct {
886
- RequiredField *string `protobuf:"bytes,81,req" json:"RequiredField,omitempty"`
887
- XXX_unrecognized []byte `json:"-"`
888
-}
889
-
890
-func (m *GoTest_RepeatedGroup) Reset() { *m = GoTest_RepeatedGroup{} }
891
-
892
-func (m *GoTest_RepeatedGroup) GetRequiredField() string {
893
- if m != nil && m.RequiredField != nil {
894
- return *m.RequiredField
895
- }
896
- return ""
897
-}
898
-
899
-type GoTest_OptionalGroup struct {
900
- RequiredField *string `protobuf:"bytes,91,req" json:"RequiredField,omitempty"`
901
- XXX_unrecognized []byte `json:"-"`
902
-}
903
-
904
-func (m *GoTest_OptionalGroup) Reset() { *m = GoTest_OptionalGroup{} }
905
-
906
-func (m *GoTest_OptionalGroup) GetRequiredField() string {
907
- if m != nil && m.RequiredField != nil {
908
- return *m.RequiredField
909
- }
910
- return ""
911
-}
912
-
913
-type GoSkipTest struct {
914
- SkipInt32 *int32 `protobuf:"varint,11,req,name=skip_int32" json:"skip_int32,omitempty"`
915
- SkipFixed32 *uint32 `protobuf:"fixed32,12,req,name=skip_fixed32" json:"skip_fixed32,omitempty"`
916
- SkipFixed64 *uint64 `protobuf:"fixed64,13,req,name=skip_fixed64" json:"skip_fixed64,omitempty"`
917
- SkipString *string `protobuf:"bytes,14,req,name=skip_string" json:"skip_string,omitempty"`
918
- Skipgroup *GoSkipTest_SkipGroup `protobuf:"group,15,req,name=SkipGroup" json:"skipgroup,omitempty"`
919
- XXX_unrecognized []byte `json:"-"`
920
-}
921
-
922
-func (m *GoSkipTest) Reset() { *m = GoSkipTest{} }
923
-func (m *GoSkipTest) String() string { return proto.CompactTextString(m) }
924
-func (*GoSkipTest) ProtoMessage() {}
925
-
926
-func (m *GoSkipTest) GetSkipInt32() int32 {
927
- if m != nil && m.SkipInt32 != nil {
928
- return *m.SkipInt32
929
- }
930
- return 0
931
-}
932
-
933
-func (m *GoSkipTest) GetSkipFixed32() uint32 {
934
- if m != nil && m.SkipFixed32 != nil {
935
- return *m.SkipFixed32
936
- }
937
- return 0
938
-}
939
-
940
-func (m *GoSkipTest) GetSkipFixed64() uint64 {
941
- if m != nil && m.SkipFixed64 != nil {
942
- return *m.SkipFixed64
943
- }
944
- return 0
945
-}
946
-
947
-func (m *GoSkipTest) GetSkipString() string {
948
- if m != nil && m.SkipString != nil {
949
- return *m.SkipString
950
- }
951
- return ""
952
-}
953
-
954
-func (m *GoSkipTest) GetSkipgroup() *GoSkipTest_SkipGroup {
955
- if m != nil {
956
- return m.Skipgroup
957
- }
958
- return nil
959
-}
960
-
961
-type GoSkipTest_SkipGroup struct {
962
- GroupInt32 *int32 `protobuf:"varint,16,req,name=group_int32" json:"group_int32,omitempty"`
963
- GroupString *string `protobuf:"bytes,17,req,name=group_string" json:"group_string,omitempty"`
964
- XXX_unrecognized []byte `json:"-"`
965
-}
966
-
967
-func (m *GoSkipTest_SkipGroup) Reset() { *m = GoSkipTest_SkipGroup{} }
968
-
969
-func (m *GoSkipTest_SkipGroup) GetGroupInt32() int32 {
970
- if m != nil && m.GroupInt32 != nil {
971
- return *m.GroupInt32
972
- }
973
- return 0
974
-}
975
-
976
-func (m *GoSkipTest_SkipGroup) GetGroupString() string {
977
- if m != nil && m.GroupString != nil {
978
- return *m.GroupString
979
- }
980
- return ""
981
-}
982
-
983
-type NonPackedTest struct {
984
- A []int32 `protobuf:"varint,1,rep,name=a" json:"a,omitempty"`
985
- XXX_unrecognized []byte `json:"-"`
986
-}
987
-
988
-func (m *NonPackedTest) Reset() { *m = NonPackedTest{} }
989
-func (m *NonPackedTest) String() string { return proto.CompactTextString(m) }
990
-func (*NonPackedTest) ProtoMessage() {}
991
-
992
-func (m *NonPackedTest) GetA() []int32 {
993
- if m != nil {
994
- return m.A
995
- }
996
- return nil
997
-}
998
-
999
-type PackedTest struct {
1000
- B []int32 `protobuf:"varint,1,rep,packed,name=b" json:"b,omitempty"`
1001
- XXX_unrecognized []byte `json:"-"`
1002
-}
1003
-
1004
-func (m *PackedTest) Reset() { *m = PackedTest{} }
1005
-func (m *PackedTest) String() string { return proto.CompactTextString(m) }
1006
-func (*PackedTest) ProtoMessage() {}
1007
-
1008
-func (m *PackedTest) GetB() []int32 {
1009
- if m != nil {
1010
- return m.B
1011
- }
1012
- return nil
1013
-}
1014
-
1015
-type MaxTag struct {
1016
- LastField *string `protobuf:"bytes,536870911,opt,name=last_field" json:"last_field,omitempty"`
1017
- XXX_unrecognized []byte `json:"-"`
1018
-}
1019
-
1020
-func (m *MaxTag) Reset() { *m = MaxTag{} }
1021
-func (m *MaxTag) String() string { return proto.CompactTextString(m) }
1022
-func (*MaxTag) ProtoMessage() {}
1023
-
1024
-func (m *MaxTag) GetLastField() string {
1025
- if m != nil && m.LastField != nil {
1026
- return *m.LastField
1027
- }
1028
- return ""
1029
-}
1030
-
1031
-type OldMessage struct {
1032
- Nested *OldMessage_Nested `protobuf:"bytes,1,opt,name=nested" json:"nested,omitempty"`
1033
- XXX_unrecognized []byte `json:"-"`
1034
-}
1035
-
1036
-func (m *OldMessage) Reset() { *m = OldMessage{} }
1037
-func (m *OldMessage) String() string { return proto.CompactTextString(m) }
1038
-func (*OldMessage) ProtoMessage() {}
1039
-
1040
-func (m *OldMessage) GetNested() *OldMessage_Nested {
1041
- if m != nil {
1042
- return m.Nested
1043
- }
1044
- return nil
1045
-}
1046
-
1047
-type OldMessage_Nested struct {
1048
- Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
1049
- XXX_unrecognized []byte `json:"-"`
1050
-}
1051
-
1052
-func (m *OldMessage_Nested) Reset() { *m = OldMessage_Nested{} }
1053
-func (m *OldMessage_Nested) String() string { return proto.CompactTextString(m) }
1054
-func (*OldMessage_Nested) ProtoMessage() {}
1055
-
1056
-func (m *OldMessage_Nested) GetName() string {
1057
- if m != nil && m.Name != nil {
1058
- return *m.Name
1059
- }
1060
- return ""
1061
-}
1062
-
1063
-type NewMessage struct {
1064
- Nested *NewMessage_Nested `protobuf:"bytes,1,opt,name=nested" json:"nested,omitempty"`
1065
- XXX_unrecognized []byte `json:"-"`
1066
-}
1067
-
1068
-func (m *NewMessage) Reset() { *m = NewMessage{} }
1069
-func (m *NewMessage) String() string { return proto.CompactTextString(m) }
1070
-func (*NewMessage) ProtoMessage() {}
1071
-
1072
-func (m *NewMessage) GetNested() *NewMessage_Nested {
1073
- if m != nil {
1074
- return m.Nested
1075
- }
1076
- return nil
1077
-}
1078
-
1079
-type NewMessage_Nested struct {
1080
- Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
1081
- FoodGroup *string `protobuf:"bytes,2,opt,name=food_group" json:"food_group,omitempty"`
1082
- XXX_unrecognized []byte `json:"-"`
1083
-}
1084
-
1085
-func (m *NewMessage_Nested) Reset() { *m = NewMessage_Nested{} }
1086
-func (m *NewMessage_Nested) String() string { return proto.CompactTextString(m) }
1087
-func (*NewMessage_Nested) ProtoMessage() {}
1088
-
1089
-func (m *NewMessage_Nested) GetName() string {
1090
- if m != nil && m.Name != nil {
1091
- return *m.Name
1092
- }
1093
- return ""
1094
-}
1095
-
1096
-func (m *NewMessage_Nested) GetFoodGroup() string {
1097
- if m != nil && m.FoodGroup != nil {
1098
- return *m.FoodGroup
1099
- }
1100
- return ""
1101
-}
1102
-
1103
-type InnerMessage struct {
1104
- Host *string `protobuf:"bytes,1,req,name=host" json:"host,omitempty"`
1105
- Port *int32 `protobuf:"varint,2,opt,name=port,def=4000" json:"port,omitempty"`
1106
- Connected *bool `protobuf:"varint,3,opt,name=connected" json:"connected,omitempty"`
1107
- XXX_unrecognized []byte `json:"-"`
1108
-}
1109
-
1110
-func (m *InnerMessage) Reset() { *m = InnerMessage{} }
1111
-func (m *InnerMessage) String() string { return proto.CompactTextString(m) }
1112
-func (*InnerMessage) ProtoMessage() {}
1113
-
1114
-const Default_InnerMessage_Port int32 = 4000
1115
-
1116
-func (m *InnerMessage) GetHost() string {
1117
- if m != nil && m.Host != nil {
1118
- return *m.Host
1119
- }
1120
- return ""
1121
-}
1122
-
1123
-func (m *InnerMessage) GetPort() int32 {
1124
- if m != nil && m.Port != nil {
1125
- return *m.Port
1126
- }
1127
- return Default_InnerMessage_Port
1128
-}
1129
-
1130
-func (m *InnerMessage) GetConnected() bool {
1131
- if m != nil && m.Connected != nil {
1132
- return *m.Connected
1133
- }
1134
- return false
1135
-}
1136
-
1137
-type OtherMessage struct {
1138
- Key *int64 `protobuf:"varint,1,opt,name=key" json:"key,omitempty"`
1139
- Value []byte `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"`
1140
- Weight *float32 `protobuf:"fixed32,3,opt,name=weight" json:"weight,omitempty"`
1141
- Inner *InnerMessage `protobuf:"bytes,4,opt,name=inner" json:"inner,omitempty"`
1142
- XXX_unrecognized []byte `json:"-"`
1143
-}
1144
-
1145
-func (m *OtherMessage) Reset() { *m = OtherMessage{} }
1146
-func (m *OtherMessage) String() string { return proto.CompactTextString(m) }
1147
-func (*OtherMessage) ProtoMessage() {}
1148
-
1149
-func (m *OtherMessage) GetKey() int64 {
1150
- if m != nil && m.Key != nil {
1151
- return *m.Key
1152
- }
1153
- return 0
1154
-}
1155
-
1156
-func (m *OtherMessage) GetValue() []byte {
1157
- if m != nil {
1158
- return m.Value
1159
- }
1160
- return nil
1161
-}
1162
-
1163
-func (m *OtherMessage) GetWeight() float32 {
1164
- if m != nil && m.Weight != nil {
1165
- return *m.Weight
1166
- }
1167
- return 0
1168
-}
1169
-
1170
-func (m *OtherMessage) GetInner() *InnerMessage {
1171
- if m != nil {
1172
- return m.Inner
1173
- }
1174
- return nil
1175
-}
1176
-
1177
-type MyMessage struct {
1178
- Count *int32 `protobuf:"varint,1,req,name=count" json:"count,omitempty"`
1179
- Name *string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
1180
- Quote *string `protobuf:"bytes,3,opt,name=quote" json:"quote,omitempty"`
1181
- Pet []string `protobuf:"bytes,4,rep,name=pet" json:"pet,omitempty"`
1182
- Inner *InnerMessage `protobuf:"bytes,5,opt,name=inner" json:"inner,omitempty"`
1183
- Others []*OtherMessage `protobuf:"bytes,6,rep,name=others" json:"others,omitempty"`
1184
- Bikeshed *MyMessage_Color `protobuf:"varint,7,opt,name=bikeshed,enum=testdata.MyMessage_Color" json:"bikeshed,omitempty"`
1185
- Somegroup *MyMessage_SomeGroup `protobuf:"group,8,opt,name=SomeGroup" json:"somegroup,omitempty"`
1186
- RepBytes [][]byte `protobuf:"bytes,10,rep,name=rep_bytes" json:"rep_bytes,omitempty"`
1187
- Bigfloat *float64 `protobuf:"fixed64,11,opt,name=bigfloat" json:"bigfloat,omitempty"`
1188
- XXX_extensions map[int32]proto.Extension `json:"-"`
1189
- XXX_unrecognized []byte `json:"-"`
1190
-}
1191
-
1192
-func (m *MyMessage) Reset() { *m = MyMessage{} }
1193
-func (m *MyMessage) String() string { return proto.CompactTextString(m) }
1194
-func (*MyMessage) ProtoMessage() {}
1195
-
1196
-var extRange_MyMessage = []proto.ExtensionRange{
1197
- {100, 536870911},
1198
-}
1199
-
1200
-func (*MyMessage) ExtensionRangeArray() []proto.ExtensionRange {
1201
- return extRange_MyMessage
1202
-}
1203
-func (m *MyMessage) ExtensionMap() map[int32]proto.Extension {
1204
- if m.XXX_extensions == nil {
1205
- m.XXX_extensions = make(map[int32]proto.Extension)
1206
- }
1207
- return m.XXX_extensions
1208
-}
1209
-
1210
-func (m *MyMessage) GetCount() int32 {
1211
- if m != nil && m.Count != nil {
1212
- return *m.Count
1213
- }
1214
- return 0
1215
-}
1216
-
1217
-func (m *MyMessage) GetName() string {
1218
- if m != nil && m.Name != nil {
1219
- return *m.Name
1220
- }
1221
- return ""
1222
-}
1223
-
1224
-func (m *MyMessage) GetQuote() string {
1225
- if m != nil && m.Quote != nil {
1226
- return *m.Quote
1227
- }
1228
- return ""
1229
-}
1230
-
1231
-func (m *MyMessage) GetPet() []string {
1232
- if m != nil {
1233
- return m.Pet
1234
- }
1235
- return nil
1236
-}
1237
-
1238
-func (m *MyMessage) GetInner() *InnerMessage {
1239
- if m != nil {
1240
- return m.Inner
1241
- }
1242
- return nil
1243
-}
1244
-
1245
-func (m *MyMessage) GetOthers() []*OtherMessage {
1246
- if m != nil {
1247
- return m.Others
1248
- }
1249
- return nil
1250
-}
1251
-
1252
-func (m *MyMessage) GetBikeshed() MyMessage_Color {
1253
- if m != nil && m.Bikeshed != nil {
1254
- return *m.Bikeshed
1255
- }
1256
- return 0
1257
-}
1258
-
1259
-func (m *MyMessage) GetSomegroup() *MyMessage_SomeGroup {
1260
- if m != nil {
1261
- return m.Somegroup
1262
- }
1263
- return nil
1264
-}
1265
-
1266
-func (m *MyMessage) GetRepBytes() [][]byte {
1267
- if m != nil {
1268
- return m.RepBytes
1269
- }
1270
- return nil
1271
-}
1272
-
1273
-func (m *MyMessage) GetBigfloat() float64 {
1274
- if m != nil && m.Bigfloat != nil {
1275
- return *m.Bigfloat
1276
- }
1277
- return 0
1278
-}
1279
-
1280
-type MyMessage_SomeGroup struct {
1281
- GroupField *int32 `protobuf:"varint,9,opt,name=group_field" json:"group_field,omitempty"`
1282
- XXX_unrecognized []byte `json:"-"`
1283
-}
1284
-
1285
-func (m *MyMessage_SomeGroup) Reset() { *m = MyMessage_SomeGroup{} }
1286
-
1287
-func (m *MyMessage_SomeGroup) GetGroupField() int32 {
1288
- if m != nil && m.GroupField != nil {
1289
- return *m.GroupField
1290
- }
1291
- return 0
1292
-}
1293
-
1294
-type Ext struct {
1295
- Data *string `protobuf:"bytes,1,opt,name=data" json:"data,omitempty"`
1296
- XXX_unrecognized []byte `json:"-"`
1297
-}
1298
-
1299
-func (m *Ext) Reset() { *m = Ext{} }
1300
-func (m *Ext) String() string { return proto.CompactTextString(m) }
1301
-func (*Ext) ProtoMessage() {}
1302
-
1303
-func (m *Ext) GetData() string {
1304
- if m != nil && m.Data != nil {
1305
- return *m.Data
1306
- }
1307
- return ""
1308
-}
1309
-
1310
-var E_Ext_More = &proto.ExtensionDesc{
1311
- ExtendedType: (*MyMessage)(nil),
1312
- ExtensionType: (*Ext)(nil),
1313
- Field: 103,
1314
- Name: "testdata.Ext.more",
1315
- Tag: "bytes,103,opt,name=more",
1316
-}
1317
-
1318
-var E_Ext_Text = &proto.ExtensionDesc{
1319
- ExtendedType: (*MyMessage)(nil),
1320
- ExtensionType: (*string)(nil),
1321
- Field: 104,
1322
- Name: "testdata.Ext.text",
1323
- Tag: "bytes,104,opt,name=text",
1324
-}
1325
-
1326
-var E_Ext_Number = &proto.ExtensionDesc{
1327
- ExtendedType: (*MyMessage)(nil),
1328
- ExtensionType: (*int32)(nil),
1329
- Field: 105,
1330
- Name: "testdata.Ext.number",
1331
- Tag: "varint,105,opt,name=number",
1332
-}
1333
-
1334
-type MessageList struct {
1335
- Message []*MessageList_Message `protobuf:"group,1,rep" json:"message,omitempty"`
1336
- XXX_unrecognized []byte `json:"-"`
1337
-}
1338
-
1339
-func (m *MessageList) Reset() { *m = MessageList{} }
1340
-func (m *MessageList) String() string { return proto.CompactTextString(m) }
1341
-func (*MessageList) ProtoMessage() {}
1342
-
1343
-func (m *MessageList) GetMessage() []*MessageList_Message {
1344
- if m != nil {
1345
- return m.Message
1346
- }
1347
- return nil
1348
-}
1349
-
1350
-type MessageList_Message struct {
1351
- Name *string `protobuf:"bytes,2,req,name=name" json:"name,omitempty"`
1352
- Count *int32 `protobuf:"varint,3,req,name=count" json:"count,omitempty"`
1353
- XXX_unrecognized []byte `json:"-"`
1354
-}
1355
-
1356
-func (m *MessageList_Message) Reset() { *m = MessageList_Message{} }
1357
-
1358
-func (m *MessageList_Message) GetName() string {
1359
- if m != nil && m.Name != nil {
1360
- return *m.Name
1361
- }
1362
- return ""
1363
-}
1364
-
1365
-func (m *MessageList_Message) GetCount() int32 {
1366
- if m != nil && m.Count != nil {
1367
- return *m.Count
1368
- }
1369
- return 0
1370
-}
1371
-
1372
-type Strings struct {
1373
- StringField *string `protobuf:"bytes,1,opt,name=string_field" json:"string_field,omitempty"`
1374
- BytesField []byte `protobuf:"bytes,2,opt,name=bytes_field" json:"bytes_field,omitempty"`
1375
- XXX_unrecognized []byte `json:"-"`
1376
-}
1377
-
1378
-func (m *Strings) Reset() { *m = Strings{} }
1379
-func (m *Strings) String() string { return proto.CompactTextString(m) }
1380
-func (*Strings) ProtoMessage() {}
1381
-
1382
-func (m *Strings) GetStringField() string {
1383
- if m != nil && m.StringField != nil {
1384
- return *m.StringField
1385
- }
1386
- return ""
1387
-}
1388
-
1389
-func (m *Strings) GetBytesField() []byte {
1390
- if m != nil {
1391
- return m.BytesField
1392
- }
1393
- return nil
1394
-}
1395
-
1396
-type Defaults struct {
1397
- F_Bool *bool `protobuf:"varint,1,opt,def=1" json:"F_Bool,omitempty"`
1398
- F_Int32 *int32 `protobuf:"varint,2,opt,def=32" json:"F_Int32,omitempty"`
1399
- F_Int64 *int64 `protobuf:"varint,3,opt,def=64" json:"F_Int64,omitempty"`
1400
- F_Fixed32 *uint32 `protobuf:"fixed32,4,opt,def=320" json:"F_Fixed32,omitempty"`
1401
- F_Fixed64 *uint64 `protobuf:"fixed64,5,opt,def=640" json:"F_Fixed64,omitempty"`
1402
- F_Uint32 *uint32 `protobuf:"varint,6,opt,def=3200" json:"F_Uint32,omitempty"`
1403
- F_Uint64 *uint64 `protobuf:"varint,7,opt,def=6400" json:"F_Uint64,omitempty"`
1404
- F_Float *float32 `protobuf:"fixed32,8,opt,def=314159" json:"F_Float,omitempty"`
1405
- F_Double *float64 `protobuf:"fixed64,9,opt,def=271828" json:"F_Double,omitempty"`
1406
- F_String *string `protobuf:"bytes,10,opt,def=hello, \"world!\"\n" json:"F_String,omitempty"`
1407
- F_Bytes []byte `protobuf:"bytes,11,opt,def=Bignose" json:"F_Bytes,omitempty"`
1408
- F_Sint32 *int32 `protobuf:"zigzag32,12,opt,def=-32" json:"F_Sint32,omitempty"`
1409
- F_Sint64 *int64 `protobuf:"zigzag64,13,opt,def=-64" json:"F_Sint64,omitempty"`
1410
- F_Enum *Defaults_Color `protobuf:"varint,14,opt,enum=testdata.Defaults_Color,def=1" json:"F_Enum,omitempty"`
1411
- F_Pinf *float32 `protobuf:"fixed32,15,opt,def=inf" json:"F_Pinf,omitempty"`
1412
- F_Ninf *float32 `protobuf:"fixed32,16,opt,def=-inf" json:"F_Ninf,omitempty"`
1413
- F_Nan *float32 `protobuf:"fixed32,17,opt,def=nan" json:"F_Nan,omitempty"`
1414
- Sub *SubDefaults `protobuf:"bytes,18,opt,name=sub" json:"sub,omitempty"`
1415
- XXX_unrecognized []byte `json:"-"`
1416
-}
1417
-
1418
-func (m *Defaults) Reset() { *m = Defaults{} }
1419
-func (m *Defaults) String() string { return proto.CompactTextString(m) }
1420
-func (*Defaults) ProtoMessage() {}
1421
-
1422
-const Default_Defaults_F_Bool bool = true
1423
-const Default_Defaults_F_Int32 int32 = 32
1424
-const Default_Defaults_F_Int64 int64 = 64
1425
-const Default_Defaults_F_Fixed32 uint32 = 320
1426
-const Default_Defaults_F_Fixed64 uint64 = 640
1427
-const Default_Defaults_F_Uint32 uint32 = 3200
1428
-const Default_Defaults_F_Uint64 uint64 = 6400
1429
-const Default_Defaults_F_Float float32 = 314159
1430
-const Default_Defaults_F_Double float64 = 271828
1431
-const Default_Defaults_F_String string = "hello, \"world!\"\n"
1432
-
1433
-var Default_Defaults_F_Bytes []byte = []byte("Bignose")
1434
-
1435
-const Default_Defaults_F_Sint32 int32 = -32
1436
-const Default_Defaults_F_Sint64 int64 = -64
1437
-const Default_Defaults_F_Enum Defaults_Color = Defaults_GREEN
1438
-
1439
-var Default_Defaults_F_Pinf float32 = float32(math.Inf(1))
1440
-var Default_Defaults_F_Ninf float32 = float32(math.Inf(-1))
1441
-var Default_Defaults_F_Nan float32 = float32(math.NaN())
1442
-
1443
-func (m *Defaults) GetF_Bool() bool {
1444
- if m != nil && m.F_Bool != nil {
1445
- return *m.F_Bool
1446
- }
1447
- return Default_Defaults_F_Bool
1448
-}
1449
-
1450
-func (m *Defaults) GetF_Int32() int32 {
1451
- if m != nil && m.F_Int32 != nil {
1452
- return *m.F_Int32
1453
- }
1454
- return Default_Defaults_F_Int32
1455
-}
1456
-
1457
-func (m *Defaults) GetF_Int64() int64 {
1458
- if m != nil && m.F_Int64 != nil {
1459
- return *m.F_Int64
1460
- }
1461
- return Default_Defaults_F_Int64
1462
-}
1463
-
1464
-func (m *Defaults) GetF_Fixed32() uint32 {
1465
- if m != nil && m.F_Fixed32 != nil {
1466
- return *m.F_Fixed32
1467
- }
1468
- return Default_Defaults_F_Fixed32
1469
-}
1470
-
1471
-func (m *Defaults) GetF_Fixed64() uint64 {
1472
- if m != nil && m.F_Fixed64 != nil {
1473
- return *m.F_Fixed64
1474
- }
1475
- return Default_Defaults_F_Fixed64
1476
-}
1477
-
1478
-func (m *Defaults) GetF_Uint32() uint32 {
1479
- if m != nil && m.F_Uint32 != nil {
1480
- return *m.F_Uint32
1481
- }
1482
- return Default_Defaults_F_Uint32
1483
-}
1484
-
1485
-func (m *Defaults) GetF_Uint64() uint64 {
1486
- if m != nil && m.F_Uint64 != nil {
1487
- return *m.F_Uint64
1488
- }
1489
- return Default_Defaults_F_Uint64
1490
-}
1491
-
1492
-func (m *Defaults) GetF_Float() float32 {
1493
- if m != nil && m.F_Float != nil {
1494
- return *m.F_Float
1495
- }
1496
- return Default_Defaults_F_Float
1497
-}
1498
-
1499
-func (m *Defaults) GetF_Double() float64 {
1500
- if m != nil && m.F_Double != nil {
1501
- return *m.F_Double
1502
- }
1503
- return Default_Defaults_F_Double
1504
-}
1505
-
1506
-func (m *Defaults) GetF_String() string {
1507
- if m != nil && m.F_String != nil {
1508
- return *m.F_String
1509
- }
1510
- return Default_Defaults_F_String
1511
-}
1512
-
1513
-func (m *Defaults) GetF_Bytes() []byte {
1514
- if m != nil && m.F_Bytes != nil {
1515
- return m.F_Bytes
1516
- }
1517
- return append([]byte(nil), Default_Defaults_F_Bytes...)
1518
-}
1519
-
1520
-func (m *Defaults) GetF_Sint32() int32 {
1521
- if m != nil && m.F_Sint32 != nil {
1522
- return *m.F_Sint32
1523
- }
1524
- return Default_Defaults_F_Sint32
1525
-}
1526
-
1527
-func (m *Defaults) GetF_Sint64() int64 {
1528
- if m != nil && m.F_Sint64 != nil {
1529
- return *m.F_Sint64
1530
- }
1531
- return Default_Defaults_F_Sint64
1532
-}
1533
-
1534
-func (m *Defaults) GetF_Enum() Defaults_Color {
1535
- if m != nil && m.F_Enum != nil {
1536
- return *m.F_Enum
1537
- }
1538
- return Default_Defaults_F_Enum
1539
-}
1540
-
1541
-func (m *Defaults) GetF_Pinf() float32 {
1542
- if m != nil && m.F_Pinf != nil {
1543
- return *m.F_Pinf
1544
- }
1545
- return Default_Defaults_F_Pinf
1546
-}
1547
-
1548
-func (m *Defaults) GetF_Ninf() float32 {
1549
- if m != nil && m.F_Ninf != nil {
1550
- return *m.F_Ninf
1551
- }
1552
- return Default_Defaults_F_Ninf
1553
-}
1554
-
1555
-func (m *Defaults) GetF_Nan() float32 {
1556
- if m != nil && m.F_Nan != nil {
1557
- return *m.F_Nan
1558
- }
1559
- return Default_Defaults_F_Nan
1560
-}
1561
-
1562
-func (m *Defaults) GetSub() *SubDefaults {
1563
- if m != nil {
1564
- return m.Sub
1565
- }
1566
- return nil
1567
-}
1568
-
1569
-type SubDefaults struct {
1570
- N *int64 `protobuf:"varint,1,opt,name=n,def=7" json:"n,omitempty"`
1571
- XXX_unrecognized []byte `json:"-"`
1572
-}
1573
-
1574
-func (m *SubDefaults) Reset() { *m = SubDefaults{} }
1575
-func (m *SubDefaults) String() string { return proto.CompactTextString(m) }
1576
-func (*SubDefaults) ProtoMessage() {}
1577
-
1578
-const Default_SubDefaults_N int64 = 7
1579
-
1580
-func (m *SubDefaults) GetN() int64 {
1581
- if m != nil && m.N != nil {
1582
- return *m.N
1583
- }
1584
- return Default_SubDefaults_N
1585
-}
1586
-
1587
-type RepeatedEnum struct {
1588
- Color []RepeatedEnum_Color `protobuf:"varint,1,rep,name=color,enum=testdata.RepeatedEnum_Color" json:"color,omitempty"`
1589
- XXX_unrecognized []byte `json:"-"`
1590
-}
1591
-
1592
-func (m *RepeatedEnum) Reset() { *m = RepeatedEnum{} }
1593
-func (m *RepeatedEnum) String() string { return proto.CompactTextString(m) }
1594
-func (*RepeatedEnum) ProtoMessage() {}
1595
-
1596
-func (m *RepeatedEnum) GetColor() []RepeatedEnum_Color {
1597
- if m != nil {
1598
- return m.Color
1599
- }
1600
- return nil
1601
-}
1602
-
1603
-type MoreRepeated struct {
1604
- Bools []bool `protobuf:"varint,1,rep,name=bools" json:"bools,omitempty"`
1605
- BoolsPacked []bool `protobuf:"varint,2,rep,packed,name=bools_packed" json:"bools_packed,omitempty"`
1606
- Ints []int32 `protobuf:"varint,3,rep,name=ints" json:"ints,omitempty"`
1607
- IntsPacked []int32 `protobuf:"varint,4,rep,packed,name=ints_packed" json:"ints_packed,omitempty"`
1608
- Strings []string `protobuf:"bytes,5,rep,name=strings" json:"strings,omitempty"`
1609
- XXX_unrecognized []byte `json:"-"`
1610
-}
1611
-
1612
-func (m *MoreRepeated) Reset() { *m = MoreRepeated{} }
1613
-func (m *MoreRepeated) String() string { return proto.CompactTextString(m) }
1614
-func (*MoreRepeated) ProtoMessage() {}
1615
-
1616
-func (m *MoreRepeated) GetBools() []bool {
1617
- if m != nil {
1618
- return m.Bools
1619
- }
1620
- return nil
1621
-}
1622
-
1623
-func (m *MoreRepeated) GetBoolsPacked() []bool {
1624
- if m != nil {
1625
- return m.BoolsPacked
1626
- }
1627
- return nil
1628
-}
1629
-
1630
-func (m *MoreRepeated) GetInts() []int32 {
1631
- if m != nil {
1632
- return m.Ints
1633
- }
1634
- return nil
1635
-}
1636
-
1637
-func (m *MoreRepeated) GetIntsPacked() []int32 {
1638
- if m != nil {
1639
- return m.IntsPacked
1640
- }
1641
- return nil
1642
-}
1643
-
1644
-func (m *MoreRepeated) GetStrings() []string {
1645
- if m != nil {
1646
- return m.Strings
1647
- }
1648
- return nil
1649
-}
1650
-
1651
-type GroupOld struct {
1652
- G *GroupOld_G `protobuf:"group,1,opt" json:"g,omitempty"`
1653
- XXX_unrecognized []byte `json:"-"`
1654
-}
1655
-
1656
-func (m *GroupOld) Reset() { *m = GroupOld{} }
1657
-func (m *GroupOld) String() string { return proto.CompactTextString(m) }
1658
-func (*GroupOld) ProtoMessage() {}
1659
-
1660
-func (m *GroupOld) GetG() *GroupOld_G {
1661
- if m != nil {
1662
- return m.G
1663
- }
1664
- return nil
1665
-}
1666
-
1667
-type GroupOld_G struct {
1668
- X *int32 `protobuf:"varint,2,opt,name=x" json:"x,omitempty"`
1669
- XXX_unrecognized []byte `json:"-"`
1670
-}
1671
-
1672
-func (m *GroupOld_G) Reset() { *m = GroupOld_G{} }
1673
-
1674
-func (m *GroupOld_G) GetX() int32 {
1675
- if m != nil && m.X != nil {
1676
- return *m.X
1677
- }
1678
- return 0
1679
-}
1680
-
1681
-type GroupNew struct {
1682
- G *GroupNew_G `protobuf:"group,1,opt" json:"g,omitempty"`
1683
- XXX_unrecognized []byte `json:"-"`
1684
-}
1685
-
1686
-func (m *GroupNew) Reset() { *m = GroupNew{} }
1687
-func (m *GroupNew) String() string { return proto.CompactTextString(m) }
1688
-func (*GroupNew) ProtoMessage() {}
1689
-
1690
-func (m *GroupNew) GetG() *GroupNew_G {
1691
- if m != nil {
1692
- return m.G
1693
- }
1694
- return nil
1695
-}
1696
-
1697
-type GroupNew_G struct {
1698
- X *int32 `protobuf:"varint,2,opt,name=x" json:"x,omitempty"`
1699
- Y *int32 `protobuf:"varint,3,opt,name=y" json:"y,omitempty"`
1700
- XXX_unrecognized []byte `json:"-"`
1701
-}
1702
-
1703
-func (m *GroupNew_G) Reset() { *m = GroupNew_G{} }
1704
-
1705
-func (m *GroupNew_G) GetX() int32 {
1706
- if m != nil && m.X != nil {
1707
- return *m.X
1708
- }
1709
- return 0
1710
-}
1711
-
1712
-func (m *GroupNew_G) GetY() int32 {
1713
- if m != nil && m.Y != nil {
1714
- return *m.Y
1715
- }
1716
- return 0
1717
-}
1718
-
1719
-var E_Greeting = &proto.ExtensionDesc{
1720
- ExtendedType: (*MyMessage)(nil),
1721
- ExtensionType: ([]string)(nil),
1722
- Field: 106,
1723
- Name: "testdata.greeting",
1724
- Tag: "bytes,106,rep,name=greeting",
1725
-}
1726
-
1727
-func init() {
1728
- proto.RegisterEnum("testdata.FOO", FOO_name, FOO_value)
1729
- proto.RegisterEnum("testdata.GoTest_KIND", GoTest_KIND_name, GoTest_KIND_value)
1730
- proto.RegisterEnum("testdata.MyMessage_Color", MyMessage_Color_name, MyMessage_Color_value)
1731
- proto.RegisterEnum("testdata.Defaults_Color", Defaults_Color_name, Defaults_Color_value)
1732
- proto.RegisterEnum("testdata.RepeatedEnum_Color", RepeatedEnum_Color_name, RepeatedEnum_Color_value)
1733
- proto.RegisterExtension(E_Ext_More)
1734
- proto.RegisterExtension(E_Ext_Text)
1735
- proto.RegisterExtension(E_Ext_Number)
1736
- proto.RegisterExtension(E_Greeting)
1737
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/testdata/test.proto
deleted
-428
@@ -1,428 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
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
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
- optional int32 num = 2;
208
-}
209
-
210
-// NewMessage is wire compatible with OldMessage;
211
-// imagine it as a future version.
212
-message NewMessage {
213
- message Nested {
214
- optional string name = 1;
215
- optional string food_group = 2;
216
- }
217
- optional Nested nested = 1;
218
-
219
- // This is an int32 in OldMessage.
220
- optional int64 num = 2;
221
-}
222
-
223
-// Smaller tests for ASCII formatting.
224
-
225
-message InnerMessage {
226
- required string host = 1;
227
- optional int32 port = 2 [default=4000];
228
- optional bool connected = 3;
229
-}
230
-
231
-message OtherMessage {
232
- optional int64 key = 1;
233
- optional bytes value = 2;
234
- optional float weight = 3;
235
- optional InnerMessage inner = 4;
236
-}
237
-
238
-message MyMessage {
239
- required int32 count = 1;
240
- optional string name = 2;
241
- optional string quote = 3;
242
- repeated string pet = 4;
243
- optional InnerMessage inner = 5;
244
- repeated OtherMessage others = 6;
245
- repeated InnerMessage rep_inner = 12;
246
-
247
- enum Color {
248
- RED = 0;
249
- GREEN = 1;
250
- BLUE = 2;
251
- };
252
- optional Color bikeshed = 7;
253
-
254
- optional group SomeGroup = 8 {
255
- optional int32 group_field = 9;
256
- }
257
-
258
- // This field becomes [][]byte in the generated code.
259
- repeated bytes rep_bytes = 10;
260
-
261
- optional double bigfloat = 11;
262
-
263
- extensions 100 to max;
264
-}
265
-
266
-message Ext {
267
- extend MyMessage {
268
- optional Ext more = 103;
269
- optional string text = 104;
270
- optional int32 number = 105;
271
- }
272
-
273
- optional string data = 1;
274
-}
275
-
276
-extend MyMessage {
277
- repeated string greeting = 106;
278
-}
279
-
280
-message MyMessageSet {
281
- option message_set_wire_format = true;
282
- extensions 100 to max;
283
-}
284
-
285
-message Empty {
286
-}
287
-
288
-extend MyMessageSet {
289
- optional Empty x201 = 201;
290
- optional Empty x202 = 202;
291
- optional Empty x203 = 203;
292
- optional Empty x204 = 204;
293
- optional Empty x205 = 205;
294
- optional Empty x206 = 206;
295
- optional Empty x207 = 207;
296
- optional Empty x208 = 208;
297
- optional Empty x209 = 209;
298
- optional Empty x210 = 210;
299
- optional Empty x211 = 211;
300
- optional Empty x212 = 212;
301
- optional Empty x213 = 213;
302
- optional Empty x214 = 214;
303
- optional Empty x215 = 215;
304
- optional Empty x216 = 216;
305
- optional Empty x217 = 217;
306
- optional Empty x218 = 218;
307
- optional Empty x219 = 219;
308
- optional Empty x220 = 220;
309
- optional Empty x221 = 221;
310
- optional Empty x222 = 222;
311
- optional Empty x223 = 223;
312
- optional Empty x224 = 224;
313
- optional Empty x225 = 225;
314
- optional Empty x226 = 226;
315
- optional Empty x227 = 227;
316
- optional Empty x228 = 228;
317
- optional Empty x229 = 229;
318
- optional Empty x230 = 230;
319
- optional Empty x231 = 231;
320
- optional Empty x232 = 232;
321
- optional Empty x233 = 233;
322
- optional Empty x234 = 234;
323
- optional Empty x235 = 235;
324
- optional Empty x236 = 236;
325
- optional Empty x237 = 237;
326
- optional Empty x238 = 238;
327
- optional Empty x239 = 239;
328
- optional Empty x240 = 240;
329
- optional Empty x241 = 241;
330
- optional Empty x242 = 242;
331
- optional Empty x243 = 243;
332
- optional Empty x244 = 244;
333
- optional Empty x245 = 245;
334
- optional Empty x246 = 246;
335
- optional Empty x247 = 247;
336
- optional Empty x248 = 248;
337
- optional Empty x249 = 249;
338
- optional Empty x250 = 250;
339
-}
340
-
341
-message MessageList {
342
- repeated group Message = 1 {
343
- required string name = 2;
344
- required int32 count = 3;
345
- }
346
-}
347
-
348
-message Strings {
349
- optional string string_field = 1;
350
- optional bytes bytes_field = 2;
351
-}
352
-
353
-message Defaults {
354
- enum Color {
355
- RED = 0;
356
- GREEN = 1;
357
- BLUE = 2;
358
- }
359
-
360
- // Default-valued fields of all basic types.
361
- // Same as GoTest, but copied here to make testing easier.
362
- optional bool F_Bool = 1 [default=true];
363
- optional int32 F_Int32 = 2 [default=32];
364
- optional int64 F_Int64 = 3 [default=64];
365
- optional fixed32 F_Fixed32 = 4 [default=320];
366
- optional fixed64 F_Fixed64 = 5 [default=640];
367
- optional uint32 F_Uint32 = 6 [default=3200];
368
- optional uint64 F_Uint64 = 7 [default=6400];
369
- optional float F_Float = 8 [default=314159.];
370
- optional double F_Double = 9 [default=271828.];
371
- optional string F_String = 10 [default="hello, \"world!\"\n"];
372
- optional bytes F_Bytes = 11 [default="Bignose"];
373
- optional sint32 F_Sint32 = 12 [default=-32];
374
- optional sint64 F_Sint64 = 13 [default=-64];
375
- optional Color F_Enum = 14 [default=GREEN];
376
-
377
- // More fields with crazy defaults.
378
- optional float F_Pinf = 15 [default=inf];
379
- optional float F_Ninf = 16 [default=-inf];
380
- optional float F_Nan = 17 [default=nan];
381
-
382
- // Sub-message.
383
- optional SubDefaults sub = 18;
384
-
385
- // Redundant but explicit defaults.
386
- optional string str_zero = 19 [default=""];
387
-}
388
-
389
-message SubDefaults {
390
- optional int64 n = 1 [default=7];
391
-}
392
-
393
-message RepeatedEnum {
394
- enum Color {
395
- RED = 1;
396
- }
397
- repeated Color color = 1;
398
-}
399
-
400
-message MoreRepeated {
401
- repeated bool bools = 1;
402
- repeated bool bools_packed = 2 [packed=true];
403
- repeated int32 ints = 3;
404
- repeated int32 ints_packed = 4 [packed=true];
405
- repeated int64 int64s_packed = 7 [packed=true];
406
- repeated string strings = 5;
407
- repeated fixed32 fixeds = 6;
408
-}
409
-
410
-// GroupOld and GroupNew have the same wire format.
411
-// GroupNew has a new field inside a group.
412
-
413
-message GroupOld {
414
- optional group G = 101 {
415
- optional int32 x = 2;
416
- }
417
-}
418
-
419
-message GroupNew {
420
- optional group G = 101 {
421
- optional int32 x = 2;
422
- optional int32 y = 3;
423
- }
424
-}
425
-
426
-message FloatingPoint {
427
- required double f = 1;
428
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/text.go
deleted
-730
@@ -1,730 +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://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
-// 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
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
-// Functions for writing the text protocol buffer format.
40
-
41
-import (
42
- "bufio"
43
- "bytes"
44
- "encoding"
45
- "fmt"
46
- "io"
47
- "log"
48
- "math"
49
- "os"
50
- "reflect"
51
- "sort"
52
- "strings"
53
-)
54
-
55
-var (
56
- newline = []byte("\n")
57
- spaces = []byte(" ")
58
- gtNewline = []byte(">\n")
59
- endBraceNewline = []byte("}\n")
60
- backslashN = []byte{'\\', 'n'}
61
- backslashR = []byte{'\\', 'r'}
62
- backslashT = []byte{'\\', 't'}
63
- backslashDQ = []byte{'\\', '"'}
64
- backslashBS = []byte{'\\', '\\'}
65
- posInf = []byte("inf")
66
- negInf = []byte("-inf")
67
- nan = []byte("nan")
68
-)
69
-
70
-type writer interface {
71
- io.Writer
72
- WriteByte(byte) error
73
-}
74
-
75
-// textWriter is an io.Writer that tracks its indentation level.
76
-type textWriter struct {
77
- ind int
78
- complete bool // if the current position is a complete line
79
- compact bool // whether to write out as a one-liner
80
- w writer
81
-}
82
-
83
-func (w *textWriter) WriteString(s string) (n int, err error) {
84
- if !strings.Contains(s, "\n") {
85
- if !w.compact && w.complete {
86
- w.writeIndent()
87
- }
88
- w.complete = false
89
- return io.WriteString(w.w, s)
90
- }
91
- // WriteString is typically called without newlines, so this
92
- // codepath and its copy are rare. We copy to avoid
93
- // duplicating all of Write's logic here.
94
- return w.Write([]byte(s))
95
-}
96
-
97
-func (w *textWriter) Write(p []byte) (n int, err error) {
98
- newlines := bytes.Count(p, newline)
99
- if newlines == 0 {
100
- if !w.compact && w.complete {
101
- w.writeIndent()
102
- }
103
- n, err = w.w.Write(p)
104
- w.complete = false
105
- return n, err
106
- }
107
-
108
- frags := bytes.SplitN(p, newline, newlines+1)
109
- if w.compact {
110
- for i, frag := range frags {
111
- if i > 0 {
112
- if err := w.w.WriteByte(' '); err != nil {
113
- return n, err
114
- }
115
- n++
116
- }
117
- nn, err := w.w.Write(frag)
118
- n += nn
119
- if err != nil {
120
- return n, err
121
- }
122
- }
123
- return n, nil
124
- }
125
-
126
- for i, frag := range frags {
127
- if w.complete {
128
- w.writeIndent()
129
- }
130
- nn, err := w.w.Write(frag)
131
- n += nn
132
- if err != nil {
133
- return n, err
134
- }
135
- if i+1 < len(frags) {
136
- if err := w.w.WriteByte('\n'); err != nil {
137
- return n, err
138
- }
139
- n++
140
- }
141
- }
142
- w.complete = len(frags[len(frags)-1]) == 0
143
- return n, nil
144
-}
145
-
146
-func (w *textWriter) WriteByte(c byte) error {
147
- if w.compact && c == '\n' {
148
- c = ' '
149
- }
150
- if !w.compact && w.complete {
151
- w.writeIndent()
152
- }
153
- err := w.w.WriteByte(c)
154
- w.complete = c == '\n'
155
- return err
156
-}
157
-
158
-func (w *textWriter) indent() { w.ind++ }
159
-
160
-func (w *textWriter) unindent() {
161
- if w.ind == 0 {
162
- log.Printf("proto: textWriter unindented too far")
163
- return
164
- }
165
- w.ind--
166
-}
167
-
168
-func writeName(w *textWriter, props *Properties) error {
169
- if _, err := w.WriteString(props.OrigName); err != nil {
170
- return err
171
- }
172
- if props.Wire != "group" {
173
- return w.WriteByte(':')
174
- }
175
- return nil
176
-}
177
-
178
-var (
179
- messageSetType = reflect.TypeOf((*MessageSet)(nil)).Elem()
180
-)
181
-
182
-// raw is the interface satisfied by RawMessage.
183
-type raw interface {
184
- Bytes() []byte
185
-}
186
-
187
-func writeStruct(w *textWriter, sv reflect.Value) error {
188
- if sv.Type() == messageSetType {
189
- return writeMessageSet(w, sv.Addr().Interface().(*MessageSet))
190
- }
191
-
192
- st := sv.Type()
193
- sprops := GetProperties(st)
194
- for i := 0; i < sv.NumField(); i++ {
195
- fv := sv.Field(i)
196
- props := sprops.Prop[i]
197
- name := st.Field(i).Name
198
-
199
- if strings.HasPrefix(name, "XXX_") {
200
- // There are two XXX_ fields:
201
- // XXX_unrecognized []byte
202
- // XXX_extensions map[int32]proto.Extension
203
- // The first is handled here;
204
- // the second is handled at the bottom of this function.
205
- if name == "XXX_unrecognized" && !fv.IsNil() {
206
- if err := writeUnknownStruct(w, fv.Interface().([]byte)); err != nil {
207
- return err
208
- }
209
- }
210
- continue
211
- }
212
- if fv.Kind() == reflect.Ptr && fv.IsNil() {
213
- // Field not filled in. This could be an optional field or
214
- // a required field that wasn't filled in. Either way, there
215
- // isn't anything we can show for it.
216
- continue
217
- }
218
- if fv.Kind() == reflect.Slice && fv.IsNil() {
219
- // Repeated field that is empty, or a bytes field that is unused.
220
- continue
221
- }
222
-
223
- if props.Repeated && fv.Kind() == reflect.Slice {
224
- // Repeated field.
225
- for j := 0; j < fv.Len(); j++ {
226
- if err := writeName(w, props); err != nil {
227
- return err
228
- }
229
- if !w.compact {
230
- if err := w.WriteByte(' '); err != nil {
231
- return err
232
- }
233
- }
234
- v := fv.Index(j)
235
- if v.Kind() == reflect.Ptr && v.IsNil() {
236
- // A nil message in a repeated field is not valid,
237
- // but we can handle that more gracefully than panicking.
238
- if _, err := w.Write([]byte("<nil>\n")); err != nil {
239
- return err
240
- }
241
- continue
242
- }
243
- if len(props.Enum) > 0 {
244
- if err := writeEnum(w, v, props); err != nil {
245
- return err
246
- }
247
- } else if err := writeAny(w, v, props); err != nil {
248
- return err
249
- }
250
- if err := w.WriteByte('\n'); err != nil {
251
- return err
252
- }
253
- }
254
- continue
255
- }
256
-
257
- if err := writeName(w, props); err != nil {
258
- return err
259
- }
260
- if !w.compact {
261
- if err := w.WriteByte(' '); err != nil {
262
- return err
263
- }
264
- }
265
- if b, ok := fv.Interface().(raw); ok {
266
- if err := writeRaw(w, b.Bytes()); err != nil {
267
- return err
268
- }
269
- continue
270
- }
271
-
272
- if len(props.Enum) > 0 {
273
- if err := writeEnum(w, fv, props); err != nil {
274
- return err
275
- }
276
- } else if err := writeAny(w, fv, props); err != nil {
277
- return err
278
- }
279
-
280
- if err := w.WriteByte('\n'); err != nil {
281
- return err
282
- }
283
- }
284
-
285
- // Extensions (the XXX_extensions field).
286
- pv := sv.Addr()
287
- if pv.Type().Implements(extendableProtoType) {
288
- if err := writeExtensions(w, pv); err != nil {
289
- return err
290
- }
291
- }
292
-
293
- return nil
294
-}
295
-
296
-// writeRaw writes an uninterpreted raw message.
297
-func writeRaw(w *textWriter, b []byte) error {
298
- if err := w.WriteByte('<'); err != nil {
299
- return err
300
- }
301
- if !w.compact {
302
- if err := w.WriteByte('\n'); err != nil {
303
- return err
304
- }
305
- }
306
- w.indent()
307
- if err := writeUnknownStruct(w, b); err != nil {
308
- return err
309
- }
310
- w.unindent()
311
- if err := w.WriteByte('>'); err != nil {
312
- return err
313
- }
314
- return nil
315
-}
316
-
317
-// writeAny writes an arbitrary field.
318
-func writeAny(w *textWriter, v reflect.Value, props *Properties) error {
319
- v = reflect.Indirect(v)
320
-
321
- if props != nil && len(props.CustomType) > 0 {
322
- var custom Marshaler = v.Interface().(Marshaler)
323
- data, err := custom.Marshal()
324
- if err != nil {
325
- return err
326
- }
327
- if err := writeString(w, string(data)); err != nil {
328
- return err
329
- }
330
- return nil
331
- }
332
-
333
- // Floats have special cases.
334
- if v.Kind() == reflect.Float32 || v.Kind() == reflect.Float64 {
335
- x := v.Float()
336
- var b []byte
337
- switch {
338
- case math.IsInf(x, 1):
339
- b = posInf
340
- case math.IsInf(x, -1):
341
- b = negInf
342
- case math.IsNaN(x):
343
- b = nan
344
- }
345
- if b != nil {
346
- _, err := w.Write(b)
347
- return err
348
- }
349
- // Other values are handled below.
350
- }
351
-
352
- // We don't attempt to serialise every possible value type; only those
353
- // that can occur in protocol buffers.
354
- switch v.Kind() {
355
- case reflect.Slice:
356
- // Should only be a []byte; repeated fields are handled in writeStruct.
357
- if err := writeString(w, string(v.Interface().([]byte))); err != nil {
358
- return err
359
- }
360
- case reflect.String:
361
- if err := writeString(w, v.String()); err != nil {
362
- return err
363
- }
364
- case reflect.Struct:
365
- // Required/optional group/message.
366
- var bra, ket byte = '<', '>'
367
- if props != nil && props.Wire == "group" {
368
- bra, ket = '{', '}'
369
- }
370
- if err := w.WriteByte(bra); err != nil {
371
- return err
372
- }
373
- if !w.compact {
374
- if err := w.WriteByte('\n'); err != nil {
375
- return err
376
- }
377
- }
378
- w.indent()
379
- if tm, ok := v.Interface().(encoding.TextMarshaler); ok {
380
- text, err := tm.MarshalText()
381
- if err != nil {
382
- return err
383
- }
384
- if _, err = w.Write(text); err != nil {
385
- return err
386
- }
387
- } else if err := writeStruct(w, v); err != nil {
388
- return err
389
- }
390
- w.unindent()
391
- if err := w.WriteByte(ket); err != nil {
392
- return err
393
- }
394
- default:
395
- _, err := fmt.Fprint(w, v.Interface())
396
- return err
397
- }
398
- return nil
399
-}
400
-
401
-// equivalent to C's isprint.
402
-func isprint(c byte) bool {
403
- return c >= 0x20 && c < 0x7f
404
-}
405
-
406
-// writeString writes a string in the protocol buffer text format.
407
-// It is similar to strconv.Quote except we don't use Go escape sequences,
408
-// we treat the string as a byte sequence, and we use octal escapes.
409
-// These differences are to maintain interoperability with the other
410
-// languages' implementations of the text format.
411
-func writeString(w *textWriter, s string) error {
412
- // use WriteByte here to get any needed indent
413
- if err := w.WriteByte('"'); err != nil {
414
- return err
415
- }
416
- // Loop over the bytes, not the runes.
417
- for i := 0; i < len(s); i++ {
418
- var err error
419
- // Divergence from C++: we don't escape apostrophes.
420
- // There's no need to escape them, and the C++ parser
421
- // copes with a naked apostrophe.
422
- switch c := s[i]; c {
423
- case '\n':
424
- _, err = w.w.Write(backslashN)
425
- case '\r':
426
- _, err = w.w.Write(backslashR)
427
- case '\t':
428
- _, err = w.w.Write(backslashT)
429
- case '"':
430
- _, err = w.w.Write(backslashDQ)
431
- case '\\':
432
- _, err = w.w.Write(backslashBS)
433
- default:
434
- if isprint(c) {
435
- err = w.w.WriteByte(c)
436
- } else {
437
- _, err = fmt.Fprintf(w.w, "\\%03o", c)
438
- }
439
- }
440
- if err != nil {
441
- return err
442
- }
443
- }
444
- return w.WriteByte('"')
445
-}
446
-
447
-func writeMessageSet(w *textWriter, ms *MessageSet) error {
448
- for _, item := range ms.Item {
449
- id := *item.TypeId
450
- if msd, ok := messageSetMap[id]; ok {
451
- // Known message set type.
452
- if _, err := fmt.Fprintf(w, "[%s]: <\n", msd.name); err != nil {
453
- return err
454
- }
455
- w.indent()
456
-
457
- pb := reflect.New(msd.t.Elem())
458
- if err := Unmarshal(item.Message, pb.Interface().(Message)); err != nil {
459
- if _, err := fmt.Fprintf(w, "/* bad message: %v */\n", err); err != nil {
460
- return err
461
- }
462
- } else {
463
- if err := writeStruct(w, pb.Elem()); err != nil {
464
- return err
465
- }
466
- }
467
- } else {
468
- // Unknown type.
469
- if _, err := fmt.Fprintf(w, "[%d]: <\n", id); err != nil {
470
- return err
471
- }
472
- w.indent()
473
- if err := writeUnknownStruct(w, item.Message); err != nil {
474
- return err
475
- }
476
- }
477
- w.unindent()
478
- if _, err := w.Write(gtNewline); err != nil {
479
- return err
480
- }
481
- }
482
- return nil
483
-}
484
-
485
-func writeUnknownStruct(w *textWriter, data []byte) (err error) {
486
- if !w.compact {
487
- if _, err := fmt.Fprintf(w, "/* %d unknown bytes */\n", len(data)); err != nil {
488
- return err
489
- }
490
- }
491
- b := NewBuffer(data)
492
- for b.index < len(b.buf) {
493
- x, err := b.DecodeVarint()
494
- if err != nil {
495
- _, err := fmt.Fprintf(w, "/* %v */\n", err)
496
- return err
497
- }
498
- wire, tag := x&7, x>>3
499
- if wire == WireEndGroup {
500
- w.unindent()
501
- if _, err := w.Write(endBraceNewline); err != nil {
502
- return err
503
- }
504
- continue
505
- }
506
- if _, err := fmt.Fprint(w, tag); err != nil {
507
- return err
508
- }
509
- if wire != WireStartGroup {
510
- if err := w.WriteByte(':'); err != nil {
511
- return err
512
- }
513
- }
514
- if !w.compact || wire == WireStartGroup {
515
- if err := w.WriteByte(' '); err != nil {
516
- return err
517
- }
518
- }
519
- switch wire {
520
- case WireBytes:
521
- buf, e := b.DecodeRawBytes(false)
522
- if e == nil {
523
- _, err = fmt.Fprintf(w, "%q", buf)
524
- } else {
525
- _, err = fmt.Fprintf(w, "/* %v */", e)
526
- }
527
- case WireFixed32:
528
- x, err = b.DecodeFixed32()
529
- err = writeUnknownInt(w, x, err)
530
- case WireFixed64:
531
- x, err = b.DecodeFixed64()
532
- err = writeUnknownInt(w, x, err)
533
- case WireStartGroup:
534
- err = w.WriteByte('{')
535
- w.indent()
536
- case WireVarint:
537
- x, err = b.DecodeVarint()
538
- err = writeUnknownInt(w, x, err)
539
- default:
540
- _, err = fmt.Fprintf(w, "/* unknown wire type %d */", wire)
541
- }
542
- if err != nil {
543
- return err
544
- }
545
- if err = w.WriteByte('\n'); err != nil {
546
- return err
547
- }
548
- }
549
- return nil
550
-}
551
-
552
-func writeUnknownInt(w *textWriter, x uint64, err error) error {
553
- if err == nil {
554
- _, err = fmt.Fprint(w, x)
555
- } else {
556
- _, err = fmt.Fprintf(w, "/* %v */", err)
557
- }
558
- return err
559
-}
560
-
561
-type int32Slice []int32
562
-
563
-func (s int32Slice) Len() int { return len(s) }
564
-func (s int32Slice) Less(i, j int) bool { return s[i] < s[j] }
565
-func (s int32Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
566
-
567
-// writeExtensions writes all the extensions in pv.
568
-// pv is assumed to be a pointer to a protocol message struct that is extendable.
569
-func writeExtensions(w *textWriter, pv reflect.Value) error {
570
- emap := extensionMaps[pv.Type().Elem()]
571
- ep := pv.Interface().(extendableProto)
572
-
573
- // Order the extensions by ID.
574
- // This isn't strictly necessary, but it will give us
575
- // canonical output, which will also make testing easier.
576
- var m map[int32]Extension
577
- if em, ok := ep.(extensionsMap); ok {
578
- m = em.ExtensionMap()
579
- } else if em, ok := ep.(extensionsBytes); ok {
580
- eb := em.GetExtensions()
581
- var err error
582
- m, err = BytesToExtensionsMap(*eb)
583
- if err != nil {
584
- return err
585
- }
586
- }
587
-
588
- ids := make([]int32, 0, len(m))
589
- for id := range m {
590
- ids = append(ids, id)
591
- }
592
- sort.Sort(int32Slice(ids))
593
-
594
- for _, extNum := range ids {
595
- ext := m[extNum]
596
- var desc *ExtensionDesc
597
- if emap != nil {
598
- desc = emap[extNum]
599
- }
600
- if desc == nil {
601
- // Unknown extension.
602
- if err := writeUnknownStruct(w, ext.enc); err != nil {
603
- return err
604
- }
605
- continue
606
- }
607
-
608
- pb, err := GetExtension(ep, desc)
609
- if err != nil {
610
- if _, err := fmt.Fprintln(os.Stderr, "proto: failed getting extension: ", err); err != nil {
611
- return err
612
- }
613
- continue
614
- }
615
-
616
- // Repeated extensions will appear as a slice.
617
- if !desc.repeated() {
618
- if err := writeExtension(w, desc.Name, pb); err != nil {
619
- return err
620
- }
621
- } else {
622
- v := reflect.ValueOf(pb)
623
- for i := 0; i < v.Len(); i++ {
624
- if err := writeExtension(w, desc.Name, v.Index(i).Interface()); err != nil {
625
- return err
626
- }
627
- }
628
- }
629
- }
630
- return nil
631
-}
632
-
633
-func writeExtension(w *textWriter, name string, pb interface{}) error {
634
- if _, err := fmt.Fprintf(w, "[%s]:", name); err != nil {
635
- return err
636
- }
637
- if !w.compact {
638
- if err := w.WriteByte(' '); err != nil {
639
- return err
640
- }
641
- }
642
- if err := writeAny(w, reflect.ValueOf(pb), nil); err != nil {
643
- return err
644
- }
645
- if err := w.WriteByte('\n'); err != nil {
646
- return err
647
- }
648
- return nil
649
-}
650
-
651
-func (w *textWriter) writeIndent() {
652
- if !w.complete {
653
- return
654
- }
655
- remain := w.ind * 2
656
- for remain > 0 {
657
- n := remain
658
- if n > len(spaces) {
659
- n = len(spaces)
660
- }
661
- w.w.Write(spaces[:n])
662
- remain -= n
663
- }
664
- w.complete = false
665
-}
666
-
667
-func marshalText(w io.Writer, pb Message, compact bool) error {
668
- val := reflect.ValueOf(pb)
669
- if pb == nil || val.IsNil() {
670
- w.Write([]byte("<nil>"))
671
- return nil
672
- }
673
- var bw *bufio.Writer
674
- ww, ok := w.(writer)
675
- if !ok {
676
- bw = bufio.NewWriter(w)
677
- ww = bw
678
- }
679
- aw := &textWriter{
680
- w: ww,
681
- complete: true,
682
- compact: compact,
683
- }
684
-
685
- if tm, ok := pb.(encoding.TextMarshaler); ok {
686
- text, err := tm.MarshalText()
687
- if err != nil {
688
- return err
689
- }
690
- if _, err = aw.Write(text); err != nil {
691
- return err
692
- }
693
- if bw != nil {
694
- return bw.Flush()
695
- }
696
- return nil
697
- }
698
- // Dereference the received pointer so we don't have outer < and >.
699
- v := reflect.Indirect(val)
700
- if err := writeStruct(aw, v); err != nil {
701
- return err
702
- }
703
- if bw != nil {
704
- return bw.Flush()
705
- }
706
- return nil
707
-}
708
-
709
-// MarshalText writes a given protocol buffer in text format.
710
-// The only errors returned are from w.
711
-func MarshalText(w io.Writer, pb Message) error {
712
- return marshalText(w, pb, false)
713
-}
714
-
715
-// MarshalTextString is the same as MarshalText, but returns the string directly.
716
-func MarshalTextString(pb Message) string {
717
- var buf bytes.Buffer
718
- marshalText(&buf, pb, false)
719
- return buf.String()
720
-}
721
-
722
-// CompactText writes a given protocol buffer in compact text format (one line).
723
-func CompactText(w io.Writer, pb Message) error { return marshalText(w, pb, true) }
724
-
725
-// CompactTextString is the same as CompactText, but returns the string directly.
726
-func CompactTextString(pb Message) string {
727
- var buf bytes.Buffer
728
- marshalText(&buf, pb, true)
729
- return buf.String()
730
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/text_gogo.go
deleted
-55
@@ -1,55 +0,0 @@
1
-// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
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
6
-// met:
7
-//
8
-// * Redistributions of source code must retain the above copyright
9
-// notice, this list of conditions and the following disclaimer.
10
-// * Redistributions in binary form must reproduce the above
11
-// copyright notice, this list of conditions and the following disclaimer
12
-// in the documentation and/or other materials provided with the
13
-// distribution.
14
-//
15
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
-
27
-package proto
28
-
29
-import (
30
- "fmt"
31
- "reflect"
32
-)
33
-
34
-func writeEnum(w *textWriter, v reflect.Value, props *Properties) error {
35
- m, ok := enumStringMaps[props.Enum]
36
- if !ok {
37
- if err := writeAny(w, v, props); err != nil {
38
- return err
39
- }
40
- }
41
- key := int32(0)
42
- if v.Kind() == reflect.Ptr {
43
- key = int32(v.Elem().Int())
44
- } else {
45
- key = int32(v.Int())
46
- }
47
- s, ok := m[key]
48
- if !ok {
49
- if err := writeAny(w, v, props); err != nil {
50
- return err
51
- }
52
- }
53
- _, err := fmt.Fprint(w, s)
54
- return err
55
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/text_parser.go
deleted
-730
@@ -1,730 +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://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
-// 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
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
-// Functions for parsing the Text protocol buffer format.
40
-// TODO: message sets.
41
-
42
-import (
43
- "encoding"
44
- "errors"
45
- "fmt"
46
- "reflect"
47
- "strconv"
48
- "strings"
49
- "unicode/utf8"
50
-)
51
-
52
-type ParseError struct {
53
- Message string
54
- Line int // 1-based line number
55
- Offset int // 0-based byte offset from start of input
56
-}
57
-
58
-func (p *ParseError) Error() string {
59
- if p.Line == 1 {
60
- // show offset only for first line
61
- return fmt.Sprintf("line 1.%d: %v", p.Offset, p.Message)
62
- }
63
- return fmt.Sprintf("line %d: %v", p.Line, p.Message)
64
-}
65
-
66
-type token struct {
67
- value string
68
- err *ParseError
69
- line int // line number
70
- offset int // byte number from start of input, not start of line
71
- unquoted string // the unquoted version of value, if it was a quoted string
72
-}
73
-
74
-func (t *token) String() string {
75
- if t.err == nil {
76
- return fmt.Sprintf("%q (line=%d, offset=%d)", t.value, t.line, t.offset)
77
- }
78
- return fmt.Sprintf("parse error: %v", t.err)
79
-}
80
-
81
-type textParser struct {
82
- s string // remaining input
83
- done bool // whether the parsing is finished (success or error)
84
- backed bool // whether back() was called
85
- offset, line int
86
- cur token
87
-}
88
-
89
-func newTextParser(s string) *textParser {
90
- p := new(textParser)
91
- p.s = s
92
- p.line = 1
93
- p.cur.line = 1
94
- return p
95
-}
96
-
97
-func (p *textParser) errorf(format string, a ...interface{}) *ParseError {
98
- pe := &ParseError{fmt.Sprintf(format, a...), p.cur.line, p.cur.offset}
99
- p.cur.err = pe
100
- p.done = true
101
- return pe
102
-}
103
-
104
-// Numbers and identifiers are matched by [-+._A-Za-z0-9]
105
-func isIdentOrNumberChar(c byte) bool {
106
- switch {
107
- case 'A' <= c && c <= 'Z', 'a' <= c && c <= 'z':
108
- return true
109
- case '0' <= c && c <= '9':
110
- return true
111
- }
112
- switch c {
113
- case '-', '+', '.', '_':
114
- return true
115
- }
116
- return false
117
-}
118
-
119
-func isWhitespace(c byte) bool {
120
- switch c {
121
- case ' ', '\t', '\n', '\r':
122
- return true
123
- }
124
- return false
125
-}
126
-
127
-func (p *textParser) skipWhitespace() {
128
- i := 0
129
- for i < len(p.s) && (isWhitespace(p.s[i]) || p.s[i] == '#') {
130
- if p.s[i] == '#' {
131
- // comment; skip to end of line or input
132
- for i < len(p.s) && p.s[i] != '\n' {
133
- i++
134
- }
135
- if i == len(p.s) {
136
- break
137
- }
138
- }
139
- if p.s[i] == '\n' {
140
- p.line++
141
- }
142
- i++
143
- }
144
- p.offset += i
145
- p.s = p.s[i:len(p.s)]
146
- if len(p.s) == 0 {
147
- p.done = true
148
- }
149
-}
150
-
151
-func (p *textParser) advance() {
152
- // Skip whitespace
153
- p.skipWhitespace()
154
- if p.done {
155
- return
156
- }
157
-
158
- // Start of non-whitespace
159
- p.cur.err = nil
160
- p.cur.offset, p.cur.line = p.offset, p.line
161
- p.cur.unquoted = ""
162
- switch p.s[0] {
163
- case '<', '>', '{', '}', ':', '[', ']', ';', ',':
164
- // Single symbol
165
- p.cur.value, p.s = p.s[0:1], p.s[1:len(p.s)]
166
- case '"', '\'':
167
- // Quoted string
168
- i := 1
169
- for i < len(p.s) && p.s[i] != p.s[0] && p.s[i] != '\n' {
170
- if p.s[i] == '\\' && i+1 < len(p.s) {
171
- // skip escaped char
172
- i++
173
- }
174
- i++
175
- }
176
- if i >= len(p.s) || p.s[i] != p.s[0] {
177
- p.errorf("unmatched quote")
178
- return
179
- }
180
- unq, err := unquoteC(p.s[1:i], rune(p.s[0]))
181
- if err != nil {
182
- p.errorf("invalid quoted string %v", p.s[0:i+1])
183
- return
184
- }
185
- p.cur.value, p.s = p.s[0:i+1], p.s[i+1:len(p.s)]
186
- p.cur.unquoted = unq
187
- default:
188
- i := 0
189
- for i < len(p.s) && isIdentOrNumberChar(p.s[i]) {
190
- i++
191
- }
192
- if i == 0 {
193
- p.errorf("unexpected byte %#x", p.s[0])
194
- return
195
- }
196
- p.cur.value, p.s = p.s[0:i], p.s[i:len(p.s)]
197
- }
198
- p.offset += len(p.cur.value)
199
-}
200
-
201
-var (
202
- errBadUTF8 = errors.New("proto: bad UTF-8")
203
- errBadHex = errors.New("proto: bad hexadecimal")
204
-)
205
-
206
-func unquoteC(s string, quote rune) (string, error) {
207
- // This is based on C++'s tokenizer.cc.
208
- // Despite its name, this is *not* parsing C syntax.
209
- // For instance, "\0" is an invalid quoted string.
210
-
211
- // Avoid allocation in trivial cases.
212
- simple := true
213
- for _, r := range s {
214
- if r == '\\' || r == quote {
215
- simple = false
216
- break
217
- }
218
- }
219
- if simple {
220
- return s, nil
221
- }
222
-
223
- buf := make([]byte, 0, 3*len(s)/2)
224
- for len(s) > 0 {
225
- r, n := utf8.DecodeRuneInString(s)
226
- if r == utf8.RuneError && n == 1 {
227
- return "", errBadUTF8
228
- }
229
- s = s[n:]
230
- if r != '\\' {
231
- if r < utf8.RuneSelf {
232
- buf = append(buf, byte(r))
233
- } else {
234
- buf = append(buf, string(r)...)
235
- }
236
- continue
237
- }
238
-
239
- ch, tail, err := unescape(s)
240
- if err != nil {
241
- return "", err
242
- }
243
- buf = append(buf, ch...)
244
- s = tail
245
- }
246
- return string(buf), nil
247
-}
248
-
249
-func unescape(s string) (ch string, tail string, err error) {
250
- r, n := utf8.DecodeRuneInString(s)
251
- if r == utf8.RuneError && n == 1 {
252
- return "", "", errBadUTF8
253
- }
254
- s = s[n:]
255
- switch r {
256
- case 'a':
257
- return "\a", s, nil
258
- case 'b':
259
- return "\b", s, nil
260
- case 'f':
261
- return "\f", s, nil
262
- case 'n':
263
- return "\n", s, nil
264
- case 'r':
265
- return "\r", s, nil
266
- case 't':
267
- return "\t", s, nil
268
- case 'v':
269
- return "\v", s, nil
270
- case '?':
271
- return "?", s, nil // trigraph workaround
272
- case '\'', '"', '\\':
273
- return string(r), s, nil
274
- case '0', '1', '2', '3', '4', '5', '6', '7', 'x', 'X':
275
- if len(s) < 2 {
276
- return "", "", fmt.Errorf(`\%c requires 2 following digits`, r)
277
- }
278
- base := 8
279
- ss := s[:2]
280
- s = s[2:]
281
- if r == 'x' || r == 'X' {
282
- base = 16
283
- } else {
284
- ss = string(r) + ss
285
- }
286
- i, err := strconv.ParseUint(ss, base, 8)
287
- if err != nil {
288
- return "", "", err
289
- }
290
- return string([]byte{byte(i)}), s, nil
291
- case 'u', 'U':
292
- n := 4
293
- if r == 'U' {
294
- n = 8
295
- }
296
- if len(s) < n {
297
- return "", "", fmt.Errorf(`\%c requires %d digits`, r, n)
298
- }
299
-
300
- bs := make([]byte, n/2)
301
- for i := 0; i < n; i += 2 {
302
- a, ok1 := unhex(s[i])
303
- b, ok2 := unhex(s[i+1])
304
- if !ok1 || !ok2 {
305
- return "", "", errBadHex
306
- }
307
- bs[i/2] = a<<4 | b
308
- }
309
- s = s[n:]
310
- return string(bs), s, nil
311
- }
312
- return "", "", fmt.Errorf(`unknown escape \%c`, r)
313
-}
314
-
315
-// Adapted from src/pkg/strconv/quote.go.
316
-func unhex(b byte) (v byte, ok bool) {
317
- switch {
318
- case '0' <= b && b <= '9':
319
- return b - '0', true
320
- case 'a' <= b && b <= 'f':
321
- return b - 'a' + 10, true
322
- case 'A' <= b && b <= 'F':
323
- return b - 'A' + 10, true
324
- }
325
- return 0, false
326
-}
327
-
328
-// Back off the parser by one token. Can only be done between calls to next().
329
-// It makes the next advance() a no-op.
330
-func (p *textParser) back() { p.backed = true }
331
-
332
-// Advances the parser and returns the new current token.
333
-func (p *textParser) next() *token {
334
- if p.backed || p.done {
335
- p.backed = false
336
- return &p.cur
337
- }
338
- p.advance()
339
- if p.done {
340
- p.cur.value = ""
341
- } else if len(p.cur.value) > 0 && p.cur.value[0] == '"' {
342
- // Look for multiple quoted strings separated by whitespace,
343
- // and concatenate them.
344
- cat := p.cur
345
- for {
346
- p.skipWhitespace()
347
- if p.done || p.s[0] != '"' {
348
- break
349
- }
350
- p.advance()
351
- if p.cur.err != nil {
352
- return &p.cur
353
- }
354
- cat.value += " " + p.cur.value
355
- cat.unquoted += p.cur.unquoted
356
- }
357
- p.done = false // parser may have seen EOF, but we want to return cat
358
- p.cur = cat
359
- }
360
- return &p.cur
361
-}
362
-
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++ {
368
- if !isNil(sv.Field(i)) {
369
- continue
370
- }
371
-
372
- props := sprops.Prop[i]
373
- if props.Required {
374
- return &RequiredNotSetError{fmt.Sprintf("%v.%v", st, props.OrigName)}
375
- }
376
- }
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.
381
-func structFieldByName(st reflect.Type, name string) (int, *Properties, bool) {
382
- sprops := GetProperties(st)
383
- i, ok := sprops.decoderOrigNames[name]
384
- if ok {
385
- return i, sprops.Prop[i], true
386
- }
387
- return -1, nil, false
388
-}
389
-
390
-// Consume a ':' from the input stream (if the next token is a colon),
391
-// returning an error if a colon is needed but not present.
392
-func (p *textParser) checkForColon(props *Properties, typ reflect.Type) *ParseError {
393
- tok := p.next()
394
- if tok.err != nil {
395
- return tok.err
396
- }
397
- if tok.value != ":" {
398
- // Colon is optional when the field is a group or message.
399
- needColon := true
400
- switch props.Wire {
401
- case "group":
402
- needColon = false
403
- case "bytes":
404
- // A "bytes" field is either a message, a string, or a repeated field;
405
- // those three become *T, *string and []T respectively, so we can check for
406
- // this field being a pointer to a non-string.
407
- if typ.Kind() == reflect.Ptr {
408
- // *T or *string
409
- if typ.Elem().Kind() == reflect.String {
410
- break
411
- }
412
- } else if typ.Kind() == reflect.Slice {
413
- // []T or []*T
414
- if typ.Elem().Kind() != reflect.Ptr {
415
- break
416
- }
417
- }
418
- needColon = false
419
- }
420
- if needColon {
421
- return p.errorf("expected ':', found %q", tok.value)
422
- }
423
- p.back()
424
- }
425
- return nil
426
-}
427
-
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]".
436
- for {
437
- tok := p.next()
438
- if tok.err != nil {
439
- return tok.err
440
- }
441
- if tok.value == terminator {
442
- break
443
- }
444
- if tok.value == "[" {
445
- // Looks like an extension.
446
- //
447
- // TODO: Check whether we need to handle
448
- // namespace rooted names (e.g. ".something.Foo").
449
- tok = p.next()
450
- if tok.err != nil {
451
- return tok.err
452
- }
453
- var desc *ExtensionDesc
454
- // This could be faster, but it's functional.
455
- // TODO: Do something smarter than a linear scan.
456
- for _, d := range RegisteredExtensions(reflect.New(st).Interface().(Message)) {
457
- if d.Name == tok.value {
458
- desc = d
459
- break
460
- }
461
- }
462
- if desc == nil {
463
- return p.errorf("unrecognized extension %q", tok.value)
464
- }
465
- // Check the extension terminator.
466
- tok = p.next()
467
- if tok.err != nil {
468
- return tok.err
469
- }
470
- if tok.value != "]" {
471
- return p.errorf("unrecognized extension terminator %q", tok.value)
472
- }
473
-
474
- props := &Properties{}
475
- props.Parse(desc.Tag)
476
-
477
- typ := reflect.TypeOf(desc.ExtensionType)
478
- if err := p.checkForColon(props, typ); err != nil {
479
- return err
480
- }
481
-
482
- rep := desc.repeated()
483
-
484
- // Read the extension structure, and set it in
485
- // the value we're constructing.
486
- var ext reflect.Value
487
- if !rep {
488
- ext = reflect.New(typ).Elem()
489
- } else {
490
- ext = reflect.New(typ.Elem()).Elem()
491
- }
492
- if err := p.readAny(ext, props); err != nil {
493
- if _, ok := err.(*RequiredNotSetError); !ok {
494
- return err
495
- }
496
- reqFieldErr = err
497
- }
498
- ep := sv.Addr().Interface().(extendableProto)
499
- if !rep {
500
- SetExtension(ep, desc, ext.Interface())
501
- } else {
502
- old, err := GetExtension(ep, desc)
503
- var sl reflect.Value
504
- if err == nil {
505
- sl = reflect.ValueOf(old) // existing slice
506
- } else {
507
- sl = reflect.MakeSlice(typ, 0, 1)
508
- }
509
- sl = reflect.Append(sl, ext)
510
- SetExtension(ep, desc, sl.Interface())
511
- }
512
- } else {
513
- // This is a normal, non-extension field.
514
- name := tok.value
515
- fi, props, ok := structFieldByName(st, name)
516
- if !ok {
517
- return p.errorf("unknown field name %q in %v", name, st)
518
- }
519
-
520
- dst := sv.Field(fi)
521
-
522
- // Check that it's not already set if it's not a repeated field.
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 {
528
- return err
529
- }
530
-
531
- // Parse into the field.
532
- fieldSet[name] = true
533
- if err := p.readAny(dst, props); err != nil {
534
- if _, ok := err.(*RequiredNotSetError); !ok {
535
- return err
536
- }
537
- reqFieldErr = err
538
- } else if props.Required {
539
- reqCount--
540
- }
541
- }
542
-
543
- // For backward compatibility, permit a semicolon or comma after a field.
544
- tok = p.next()
545
- if tok.err != nil {
546
- return tok.err
547
- }
548
- if tok.value != ";" && tok.value != "," {
549
- p.back()
550
- }
551
- }
552
-
553
- if reqCount > 0 {
554
- return p.missingRequiredFieldError(sv)
555
- }
556
- return reqFieldErr
557
-}
558
-
559
-func (p *textParser) readAny(v reflect.Value, props *Properties) error {
560
- tok := p.next()
561
- if tok.err != nil {
562
- return tok.err
563
- }
564
- if tok.value == "" {
565
- return p.errorf("unexpected EOF")
566
- }
567
- if len(props.CustomType) > 0 {
568
- if props.Repeated {
569
- t := reflect.TypeOf(v.Interface())
570
- if t.Kind() == reflect.Slice {
571
- tc := reflect.TypeOf(new(Marshaler))
572
- ok := t.Elem().Implements(tc.Elem())
573
- if ok {
574
- fv := v
575
- flen := fv.Len()
576
- if flen == fv.Cap() {
577
- nav := reflect.MakeSlice(v.Type(), flen, 2*flen+1)
578
- reflect.Copy(nav, fv)
579
- fv.Set(nav)
580
- }
581
- fv.SetLen(flen + 1)
582
-
583
- // Read one.
584
- p.back()
585
- return p.readAny(fv.Index(flen), props)
586
- }
587
- }
588
- }
589
- if reflect.TypeOf(v.Interface()).Kind() == reflect.Ptr {
590
- custom := reflect.New(props.ctype.Elem()).Interface().(Unmarshaler)
591
- err := custom.Unmarshal([]byte(tok.unquoted))
592
- if err != nil {
593
- return p.errorf("%v %v: %v", err, v.Type(), tok.value)
594
- }
595
- v.Set(reflect.ValueOf(custom))
596
- } else {
597
- custom := reflect.New(reflect.TypeOf(v.Interface())).Interface().(Unmarshaler)
598
- err := custom.Unmarshal([]byte(tok.unquoted))
599
- if err != nil {
600
- return p.errorf("%v %v: %v", err, v.Type(), tok.value)
601
- }
602
- v.Set(reflect.Indirect(reflect.ValueOf(custom)))
603
- }
604
- return nil
605
- }
606
- switch fv := v; fv.Kind() {
607
- case reflect.Slice:
608
- at := v.Type()
609
- if at.Elem().Kind() == reflect.Uint8 {
610
- // Special case for []byte
611
- if tok.value[0] != '"' && tok.value[0] != '\'' {
612
- // Deliberately written out here, as the error after
613
- // this switch statement would write "invalid []byte: ...",
614
- // which is not as user-friendly.
615
- return p.errorf("invalid string: %v", tok.value)
616
- }
617
- bytes := []byte(tok.unquoted)
618
- fv.Set(reflect.ValueOf(bytes))
619
- return nil
620
- }
621
- // Repeated field. May already exist.
622
- flen := fv.Len()
623
- if flen == fv.Cap() {
624
- nav := reflect.MakeSlice(at, flen, 2*flen+1)
625
- reflect.Copy(nav, fv)
626
- fv.Set(nav)
627
- }
628
- fv.SetLen(flen + 1)
629
-
630
- // Read one.
631
- p.back()
632
- return p.readAny(fv.Index(flen), props)
633
- case reflect.Bool:
634
- // Either "true", "false", 1 or 0.
635
- switch tok.value {
636
- case "true", "1":
637
- fv.SetBool(true)
638
- return nil
639
- case "false", "0":
640
- fv.SetBool(false)
641
- return nil
642
- }
643
- case reflect.Float32, reflect.Float64:
644
- v := tok.value
645
- // Ignore 'f' for compatibility with output generated by C++, but don't
646
- // remove 'f' when the value is "-inf" or "inf".
647
- if strings.HasSuffix(v, "f") && tok.value != "-inf" && tok.value != "inf" {
648
- v = v[:len(v)-1]
649
- }
650
- if f, err := strconv.ParseFloat(v, fv.Type().Bits()); err == nil {
651
- fv.SetFloat(f)
652
- return nil
653
- }
654
- case reflect.Int32:
655
- if x, err := strconv.ParseInt(tok.value, 0, 32); err == nil {
656
- fv.SetInt(x)
657
- return nil
658
- }
659
-
660
- if len(props.Enum) == 0 {
661
- break
662
- }
663
- m, ok := enumValueMaps[props.Enum]
664
- if !ok {
665
- break
666
- }
667
- x, ok := m[tok.value]
668
- if !ok {
669
- break
670
- }
671
- fv.SetInt(int64(x))
672
- return nil
673
- case reflect.Int64:
674
- if x, err := strconv.ParseInt(tok.value, 0, 64); err == nil {
675
- fv.SetInt(x)
676
- return nil
677
- }
678
-
679
- case reflect.Ptr:
680
- // A basic field (indirected through pointer), or a repeated message/group
681
- p.back()
682
- fv.Set(reflect.New(fv.Type().Elem()))
683
- return p.readAny(fv.Elem(), props)
684
- case reflect.String:
685
- if tok.value[0] == '"' || tok.value[0] == '\'' {
686
- fv.SetString(tok.unquoted)
687
- return nil
688
- }
689
- case reflect.Struct:
690
- var terminator string
691
- switch tok.value {
692
- case "{":
693
- terminator = "}"
694
- case "<":
695
- terminator = ">"
696
- default:
697
- return p.errorf("expected '{' or '<', found %q", tok.value)
698
- }
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 {
703
- fv.SetUint(uint64(x))
704
- return nil
705
- }
706
- case reflect.Uint64:
707
- if x, err := strconv.ParseUint(tok.value, 0, 64); err == nil {
708
- fv.SetUint(x)
709
- return nil
710
- }
711
- }
712
- return p.errorf("invalid %v: %v", v.Type(), tok.value)
713
-}
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 {
720
- if um, ok := pb.(encoding.TextUnmarshaler); ok {
721
- err := um.UnmarshalText([]byte(s))
722
- return err
723
- }
724
- pb.Reset()
725
- v := reflect.ValueOf(pb)
726
- if pe := newTextParser(s).readStruct(v.Elem(), ""); pe != nil {
727
- return pe
728
- }
729
- return nil
730
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/text_parser_test.go
deleted
-468
@@ -1,468 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
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
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/github.com/gogo/protobuf/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: `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
305
- {
306
- in: `name: "Rob" name: "Russ"`,
307
- err: `line 1.12: non-repeated field "name" was repeated`,
308
- },
309
-
310
- // Group
311
- {
312
- in: `count: 17 SomeGroup { group_field: 12 }`,
313
- out: &MyMessage{
314
- Count: Int32(17),
315
- Somegroup: &MyMessage_SomeGroup{
316
- GroupField: Int32(12),
317
- },
318
- },
319
- },
320
-
321
- // Semicolon between fields
322
- {
323
- in: `count:3;name:"Calvin"`,
324
- out: &MyMessage{
325
- Count: Int32(3),
326
- Name: String("Calvin"),
327
- },
328
- },
329
- // Comma between fields
330
- {
331
- in: `count:4,name:"Ezekiel"`,
332
- out: &MyMessage{
333
- Count: Int32(4),
334
- Name: String("Ezekiel"),
335
- },
336
- },
337
-
338
- // Extension
339
- buildExtStructTest(`count: 42 [testdata.Ext.more]:<data:"Hello, world!" >`),
340
- buildExtStructTest(`count: 42 [testdata.Ext.more] {data:"Hello, world!"}`),
341
- buildExtDataTest(`count: 42 [testdata.Ext.text]:"Hello, world!" [testdata.Ext.number]:1729`),
342
- buildExtRepStringTest(`count: 42 [testdata.greeting]:"bula" [testdata.greeting]:"hola"`),
343
-
344
- // Big all-in-one
345
- {
346
- in: "count:42 # Meaning\n" +
347
- `name:"Dave" ` +
348
- `quote:"\"I didn't want to go.\"" ` +
349
- `pet:"bunny" ` +
350
- `pet:"kitty" ` +
351
- `pet:"horsey" ` +
352
- `inner:<` +
353
- ` host:"footrest.syd" ` +
354
- ` port:7001 ` +
355
- ` connected:true ` +
356
- `> ` +
357
- `others:<` +
358
- ` key:3735928559 ` +
359
- ` value:"\x01A\a\f" ` +
360
- `> ` +
361
- `others:<` +
362
- " weight:58.9 # Atomic weight of Co\n" +
363
- ` inner:<` +
364
- ` host:"lesha.mtv" ` +
365
- ` port:8002 ` +
366
- ` >` +
367
- `>`,
368
- out: &MyMessage{
369
- Count: Int32(42),
370
- Name: String("Dave"),
371
- Quote: String(`"I didn't want to go."`),
372
- Pet: []string{"bunny", "kitty", "horsey"},
373
- Inner: &InnerMessage{
374
- Host: String("footrest.syd"),
375
- Port: Int32(7001),
376
- Connected: Bool(true),
377
- },
378
- Others: []*OtherMessage{
379
- {
380
- Key: Int64(3735928559),
381
- Value: []byte{0x1, 'A', '\a', '\f'},
382
- },
383
- {
384
- Weight: Float32(58.9),
385
- Inner: &InnerMessage{
386
- Host: String("lesha.mtv"),
387
- Port: Int32(8002),
388
- },
389
- },
390
- },
391
- },
392
- },
393
-}
394
-
395
-func TestUnmarshalText(t *testing.T) {
396
- for i, test := range unMarshalTextTests {
397
- pb := new(MyMessage)
398
- err := UnmarshalText(test.in, pb)
399
- if test.err == "" {
400
- // We don't expect failure.
401
- if err != nil {
402
- t.Errorf("Test %d: Unexpected error: %v", i, err)
403
- } else if !reflect.DeepEqual(pb, test.out) {
404
- t.Errorf("Test %d: Incorrect populated \nHave: %v\nWant: %v",
405
- i, pb, test.out)
406
- }
407
- } else {
408
- // We do expect failure.
409
- if err == nil {
410
- t.Errorf("Test %d: Didn't get expected error: %v", i, test.err)
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
- }
420
-}
421
-
422
-func TestUnmarshalTextCustomMessage(t *testing.T) {
423
- msg := &textMessage{}
424
- if err := UnmarshalText("custom", msg); err != nil {
425
- t.Errorf("Unexpected error from custom unmarshal: %v", err)
426
- }
427
- if UnmarshalText("not custom", msg) == nil {
428
- t.Errorf("Didn't get expected error from custom unmarshal")
429
- }
430
-}
431
-
432
-// Regression test; this caused a panic.
433
-func TestRepeatedEnum(t *testing.T) {
434
- pb := new(RepeatedEnum)
435
- if err := UnmarshalText("color: RED", pb); err != nil {
436
- t.Fatal(err)
437
- }
438
- exp := &RepeatedEnum{
439
- Color: []RepeatedEnum_Color{RepeatedEnum_RED},
440
- }
441
- if !Equal(pb, exp) {
442
- t.Errorf("Incorrect populated \nHave: %v\nWant: %v", pb, exp)
443
- }
444
-}
445
-
446
-var benchInput string
447
-
448
-func init() {
449
- benchInput = "count: 4\n"
450
- for i := 0; i < 1000; i++ {
451
- benchInput += "pet: \"fido\"\n"
452
- }
453
-
454
- // Check it is valid input.
455
- pb := new(MyMessage)
456
- err := UnmarshalText(benchInput, pb)
457
- if err != nil {
458
- panic("Bad benchmark input: " + err.Error())
459
- }
460
-}
461
-
462
-func BenchmarkUnmarshalText(b *testing.B) {
463
- pb := new(MyMessage)
464
- for i := 0; i < b.N; i++ {
465
- UnmarshalText(benchInput, pb)
466
- }
467
- b.SetBytes(int64(len(benchInput)))
468
-}
Godeps/_workspace/src/github.com/gogo/protobuf/proto/text_test.go
deleted
-407
@@ -1,407 +0,0 @@
1
-// Go support for Protocol Buffers - Google's data interchange format
2
-//
3
-// Copyright 2010 The Go Authors. All rights reserved.
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
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
- 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
47
-// itself as text.
48
-type textMessage struct {
49
-}
50
-
51
-func (*textMessage) MarshalText() ([]byte, error) {
52
- return []byte("custom"), nil
53
-}
54
-
55
-func (*textMessage) UnmarshalText(bytes []byte) error {
56
- if string(bytes) != "custom" {
57
- return errors.New("expected 'custom'")
58
- }
59
- return nil
60
-}
61
-
62
-func (*textMessage) Reset() {}
63
-func (*textMessage) String() string { return "" }
64
-func (*textMessage) ProtoMessage() {}
65
-
66
-func newTestMessage() *pb.MyMessage {
67
- msg := &pb.MyMessage{
68
- Count: proto.Int32(42),
69
- Name: proto.String("Dave"),
70
- Quote: proto.String(`"I didn't want to go."`),
71
- Pet: []string{"bunny", "kitty", "horsey"},
72
- Inner: &pb.InnerMessage{
73
- Host: proto.String("footrest.syd"),
74
- Port: proto.Int32(7001),
75
- Connected: proto.Bool(true),
76
- },
77
- Others: []*pb.OtherMessage{
78
- {
79
- Key: proto.Int64(0xdeadbeef),
80
- Value: []byte{1, 65, 7, 12},
81
- },
82
- {
83
- Weight: proto.Float32(6.022),
84
- Inner: &pb.InnerMessage{
85
- Host: proto.String("lesha.mtv"),
86
- Port: proto.Int32(8002),
87
- },
88
- },
89
- },
90
- Bikeshed: pb.MyMessage_BLUE.Enum(),
91
- Somegroup: &pb.MyMessage_SomeGroup{
92
- GroupField: proto.Int32(8),
93
- },
94
- // One normally wouldn't do this.
95
- // This is an undeclared tag 13, as a varint (wire type 0) with value 4.
96
- XXX_unrecognized: []byte{13<<3 | 0, 4},
97
- }
98
- ext := &pb.Ext{
99
- Data: proto.String("Big gobs for big rats"),
100
- }
101
- if err := proto.SetExtension(msg, pb.E_Ext_More, ext); err != nil {
102
- panic(err)
103
- }
104
- greetings := []string{"adg", "easy", "cow"}
105
- if err := proto.SetExtension(msg, pb.E_Greeting, greetings); err != nil {
106
- panic(err)
107
- }
108
-
109
- // Add an unknown extension. We marshal a pb.Ext, and fake the ID.
110
- b, err := proto.Marshal(&pb.Ext{Data: proto.String("3G skiing")})
111
- if err != nil {
112
- panic(err)
113
- }
114
- b = append(proto.EncodeVarint(201<<3|proto.WireBytes), b...)
115
- proto.SetRawExtension(msg, 201, b)
116
-
117
- // Extensions can be plain fields, too, so let's test that.
118
- b = append(proto.EncodeVarint(202<<3|proto.WireVarint), 19)
119
- proto.SetRawExtension(msg, 202, b)
120
-
121
- return msg
122
-}
123
-
124
-const text = `count: 42
125
-name: "Dave"
126
-quote: "\"I didn't want to go.\""
127
-pet: "bunny"
128
-pet: "kitty"
129
-pet: "horsey"
130
-inner: <
131
- host: "footrest.syd"
132
- port: 7001
133
- connected: true
134
->
135
-others: <
136
- key: 3735928559
137
- value: "\001A\007\014"
138
->
139
-others: <
140
- weight: 6.022
141
- inner: <
142
- host: "lesha.mtv"
143
- port: 8002
144
- >
145
->
146
-bikeshed: BLUE
147
-SomeGroup {
148
- group_field: 8
149
-}
150
-/* 2 unknown bytes */
151
-13: 4
152
-[testdata.Ext.more]: <
153
- data: "Big gobs for big rats"
154
->
155
-[testdata.greeting]: "adg"
156
-[testdata.greeting]: "easy"
157
-[testdata.greeting]: "cow"
158
-/* 13 unknown bytes */
159
-201: "\t3G skiing"
160
-/* 3 unknown bytes */
161
-202: 19
162
-`
163
-
164
-func TestMarshalText(t *testing.T) {
165
- buf := new(bytes.Buffer)
166
- if err := proto.MarshalText(buf, newTestMessage()); err != nil {
167
- t.Fatalf("proto.MarshalText: %v", err)
168
- }
169
- s := buf.String()
170
- if s != text {
171
- t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", s, text)
172
- }
173
-}
174
-
175
-func TestMarshalTextCustomMessage(t *testing.T) {
176
- buf := new(bytes.Buffer)
177
- if err := proto.MarshalText(buf, &textMessage{}); err != nil {
178
- t.Fatalf("proto.MarshalText: %v", err)
179
- }
180
- s := buf.String()
181
- if s != "custom" {
182
- t.Errorf("Got %q, expected %q", s, "custom")
183
- }
184
-}
185
-func TestMarshalTextNil(t *testing.T) {
186
- want := "<nil>"
187
- tests := []proto.Message{nil, (*pb.MyMessage)(nil)}
188
- for i, test := range tests {
189
- buf := new(bytes.Buffer)
190
- if err := proto.MarshalText(buf, test); err != nil {
191
- t.Fatal(err)
192
- }
193
- if got := buf.String(); got != want {
194
- t.Errorf("%d: got %q want %q", i, got, want)
195
- }
196
- }
197
-}
198
-
199
-func TestMarshalTextUnknownEnum(t *testing.T) {
200
- // The Color enum only specifies values 0-2.
201
- m := &pb.MyMessage{Bikeshed: pb.MyMessage_Color(3).Enum()}
202
- got := m.String()
203
- const want = `bikeshed:3 `
204
- if got != want {
205
- t.Errorf("\n got %q\nwant %q", got, want)
206
- }
207
-}
208
-
209
-func BenchmarkMarshalTextBuffered(b *testing.B) {
210
- buf := new(bytes.Buffer)
211
- m := newTestMessage()
212
- for i := 0; i < b.N; i++ {
213
- buf.Reset()
214
- proto.MarshalText(buf, m)
215
- }
216
-}
217
-
218
-func BenchmarkMarshalTextUnbuffered(b *testing.B) {
219
- w := ioutil.Discard
220
- m := newTestMessage()
221
- for i := 0; i < b.N; i++ {
222
- proto.MarshalText(w, m)
223
- }
224
-}
225
-
226
-func compact(src string) string {
227
- // s/[ \n]+/ /g; s/ $//;
228
- dst := make([]byte, len(src))
229
- space, comment := false, false
230
- j := 0
231
- for i := 0; i < len(src); i++ {
232
- if strings.HasPrefix(src[i:], "/*") {
233
- comment = true
234
- i++
235
- continue
236
- }
237
- if comment && strings.HasPrefix(src[i:], "*/") {
238
- comment = false
239
- i++
240
- continue
241
- }
242
- if comment {
243
- continue
244
- }
245
- c := src[i]
246
- if c == ' ' || c == '\n' {
247
- space = true
248
- continue
249
- }
250
- if j > 0 && (dst[j-1] == ':' || dst[j-1] == '<' || dst[j-1] == '{') {
251
- space = false
252
- }
253
- if c == '{' {
254
- space = false
255
- }
256
- if space {
257
- dst[j] = ' '
258
- j++
259
- space = false
260
- }
261
- dst[j] = c
262
- j++
263
- }
264
- if space {
265
- dst[j] = ' '
266
- j++
267
- }
268
- return string(dst[0:j])
269
-}
270
-
271
-var compactText = compact(text)
272
-
273
-func TestCompactText(t *testing.T) {
274
- s := proto.CompactTextString(newTestMessage())
275
- if s != compactText {
276
- t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v\n===\n", s, compactText)
277
- }
278
-}
279
-
280
-func TestStringEscaping(t *testing.T) {
281
- testCases := []struct {
282
- in *pb.Strings
283
- out string
284
- }{
285
- {
286
- // Test data from C++ test (TextFormatTest.StringEscape).
287
- // Single divergence: we don't escape apostrophes.
288
- &pb.Strings{StringField: proto.String("\"A string with ' characters \n and \r newlines and \t tabs and \001 slashes \\ and multiple spaces")},
289
- "string_field: \"\\\"A string with ' characters \\n and \\r newlines and \\t tabs and \\001 slashes \\\\ and multiple spaces\"\n",
290
- },
291
- {
292
- // Test data from the same C++ test.
293
- &pb.Strings{StringField: proto.String("\350\260\267\346\255\214")},
294
- "string_field: \"\\350\\260\\267\\346\\255\\214\"\n",
295
- },
296
- {
297
- // Some UTF-8.
298
- &pb.Strings{StringField: proto.String("\x00\x01\xff\x81")},
299
- `string_field: "\000\001\377\201"` + "\n",
300
- },
301
- }
302
-
303
- for i, tc := range testCases {
304
- var buf bytes.Buffer
305
- if err := proto.MarshalText(&buf, tc.in); err != nil {
306
- t.Errorf("proto.MarsalText: %v", err)
307
- continue
308
- }
309
- s := buf.String()
310
- if s != tc.out {
311
- t.Errorf("#%d: Got:\n%s\nExpected:\n%s\n", i, s, tc.out)
312
- continue
313
- }
314
-
315
- // Check round-trip.
316
- pb := new(pb.Strings)
317
- if err := proto.UnmarshalText(s, pb); err != nil {
318
- t.Errorf("#%d: UnmarshalText: %v", i, err)
319
- continue
320
- }
321
- if !proto.Equal(pb, tc.in) {
322
- t.Errorf("#%d: Round-trip failed:\nstart: %v\n end: %v", i, tc.in, pb)
323
- }
324
- }
325
-}
326
-
327
-// A limitedWriter accepts some output before it fails.
328
-// This is a proxy for something like a nearly-full or imminently-failing disk,
329
-// or a network connection that is about to die.
330
-type limitedWriter struct {
331
- b bytes.Buffer
332
- limit int
333
-}
334
-
335
-var outOfSpace = errors.New("proto: insufficient space")
336
-
337
-func (w *limitedWriter) Write(p []byte) (n int, err error) {
338
- var avail = w.limit - w.b.Len()
339
- if avail <= 0 {
340
- return 0, outOfSpace
341
- }
342
- if len(p) <= avail {
343
- return w.b.Write(p)
344
- }
345
- n, _ = w.b.Write(p[:avail])
346
- return n, outOfSpace
347
-}
348
-
349
-func TestMarshalTextFailing(t *testing.T) {
350
- // Try lots of different sizes to exercise more error code-paths.
351
- for lim := 0; lim < len(text); lim++ {
352
- buf := new(limitedWriter)
353
- buf.limit = lim
354
- err := proto.MarshalText(buf, newTestMessage())
355
- // We expect a certain error, but also some partial results in the buffer.
356
- if err != outOfSpace {
357
- t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", err, outOfSpace)
358
- }
359
- s := buf.b.String()
360
- x := text[:buf.limit]
361
- if s != x {
362
- t.Errorf("Got:\n===\n%v===\nExpected:\n===\n%v===\n", s, x)
363
- }
364
- }
365
-}
366
-
367
-func TestFloats(t *testing.T) {
368
- tests := []struct {
369
- f float64
370
- want string
371
- }{
372
- {0, "0"},
373
- {4.7, "4.7"},
374
- {math.Inf(1), "inf"},
375
- {math.Inf(-1), "-inf"},
376
- {math.NaN(), "nan"},
377
- }
378
- for _, test := range tests {
379
- msg := &pb.FloatingPoint{F: &test.f}
380
- got := strings.TrimSpace(msg.String())
381
- want := `f:` + test.want
382
- if got != want {
383
- t.Errorf("f=%f: got %q, want %q", test.f, got, want)
384
- }
385
- }
386
-}
387
-
388
-func TestRepeatedNilText(t *testing.T) {
389
- m := &pb.MessageList{
390
- Message: []*pb.MessageList_Message{
391
- nil,
392
- {
393
- Name: proto.String("Horse"),
394
- },
395
- nil,
396
- },
397
- }
398
- want := `Message <nil>
399
-Message {
400
- name: "Horse"
401
-}
402
-Message <nil>
403
-`
404
- if s := proto.MarshalTextString(m); s != want {
405
- t.Errorf(" got: %s\nwant: %s", s, want)
406
- }
407
-}
diagnostics/diag.go
+2
-2
@@ -11,8 +11,8 @@ import (
11
"sync"
12
"time"
13
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"
14
+ ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io"
15
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
16
ctxio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-context/io"
17
pb "github.com/ipfs/go-ipfs/diagnostics/pb"
18
host "gx/ipfs/QmUBogf4nUefBjmYjn6jfsfPJRkmDGSeMhNj4usRKq69f4/go-libp2p/p2p/host"
diagnostics/pb/diagnostics.pb.go
+1
-1
@@ -13,7 +13,7 @@ It has these top-level messages:
13
*/
14
package diagnostics_pb
15
16
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
16
+import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/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
wantlist "github.com/ipfs/go-ipfs/exchange/bitswap/wantlist"
10
inet "gx/ipfs/QmUBogf4nUefBjmYjn6jfsfPJRkmDGSeMhNj4usRKq69f4/go-libp2p/p2p/net"
11
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"
12
+ ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io"
13
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/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/github.com/gogo/protobuf/proto"
7
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
8
9
blocks "github.com/ipfs/go-ipfs/blocks"
10
key "github.com/ipfs/go-ipfs/blocks/key"
exchange/bitswap/message/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/github.com/gogo/protobuf/proto"
16
+import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
17
import math "math"
18
19
// Reference imports to suppress errors if they are not otherwise used.
fuse/readonly/readonly_unix.go
+1
-1
@@ -11,7 +11,7 @@ import (
11
12
fuse "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
13
fs "github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs"
14
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
14
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
15
core "github.com/ipfs/go-ipfs/core"
16
mdag "github.com/ipfs/go-ipfs/merkledag"
17
path "github.com/ipfs/go-ipfs/path"
merkledag/pb/merkledag.pb.go
+2
-2
@@ -14,14 +14,14 @@
14
*/
15
package merkledag_pb
16
17
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
17
+import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/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 github_com_gogo_protobuf_proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
24
+import github_com_gogo_protobuf_proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
25
26
import strings "strings"
27
import reflect "reflect"
merkledag/pb/merkledagpb_test.go
+1
-1
@@ -17,7 +17,7 @@ package merkledag_pb
17
import testing "testing"
18
import math_rand "math/rand"
19
import time "time"
20
-import github_com_gogo_protobuf_proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
20
+import github_com_gogo_protobuf_proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
21
import encoding_json "encoding/json"
22
import fmt "fmt"
23
import go_parser "go/parser"
namesys/ipns_select_test.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
"testing"
7
"time"
8
9
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
9
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
10
11
pb "github.com/ipfs/go-ipfs/namesys/pb"
12
path "github.com/ipfs/go-ipfs/path"
namesys/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/github.com/gogo/protobuf/proto"
16
+import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/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/github.com/gogo/protobuf/proto"
9
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
10
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
11
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
12
namesys/republisher/repub.go
+1
-1
@@ -13,7 +13,7 @@ import (
13
dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb"
14
peer "gx/ipfs/QmUBogf4nUefBjmYjn6jfsfPJRkmDGSeMhNj4usRKq69f4/go-libp2p/p2p/peer"
15
16
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
16
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
17
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
18
goprocess "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess"
19
gpctx "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context"
namesys/routing.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"fmt"
5
"time"
6
7
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
7
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
8
lru "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/hashicorp/golang-lru"
9
mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
10
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
package.json
+5
@@ -26,6 +26,11 @@
26
"name": "randbo",
27
"hash": "QmYvsG72GsfLgUeSojXArjnU6L4Wmwk7wuAxtNLuyXcc1T",
28
"version": "0.0.0"
29
+ },
30
+ {
31
+ "name": "gogo-protobuf",
32
+ "hash": "QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV",
33
+ "version": "0.0.0"
34
}
35
],
36
"language": "go",
pin/internal/pb/header.pb.go
+1
-1
@@ -13,7 +13,7 @@ It has these top-level messages:
13
*/
14
package pb
15
16
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
16
+import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
17
import math "math"
18
19
// Reference imports to suppress errors if they are not otherwise used.
pin/set.go
+1
-1
@@ -11,7 +11,7 @@ import (
11
"sort"
12
"unsafe"
13
14
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
14
+ "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
15
"github.com/ipfs/go-ipfs/blocks/key"
16
"github.com/ipfs/go-ipfs/merkledag"
17
"github.com/ipfs/go-ipfs/pin/internal/pb"
routing/dht/dht.go
+1
-1
@@ -20,7 +20,7 @@ import (
20
protocol "gx/ipfs/QmUBogf4nUefBjmYjn6jfsfPJRkmDGSeMhNj4usRKq69f4/go-libp2p/p2p/protocol"
21
logging "gx/ipfs/Qmazh5oNUVsDZTs2g59rq8aYQqwpss8tcUWQzor5sCCEuH/go-log"
22
23
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
23
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
24
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
25
goprocess "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess"
26
goprocessctx "gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context"
routing/dht/dht_net.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"errors"
5
"time"
6
7
- ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
7
+ ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io"
8
ctxio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-context/io"
9
pb "github.com/ipfs/go-ipfs/routing/dht/pb"
10
inet "gx/ipfs/QmUBogf4nUefBjmYjn6jfsfPJRkmDGSeMhNj4usRKq69f4/go-libp2p/p2p/net"
routing/dht/ext_test.go
+1
-1
@@ -7,7 +7,7 @@ import (
7
"testing"
8
"time"
9
10
- ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
10
+ ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io"
11
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
12
dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
13
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
routing/dht/handlers.go
+1
-1
@@ -5,7 +5,7 @@ import (
5
"fmt"
6
"time"
7
8
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
8
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
9
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
10
key "github.com/ipfs/go-ipfs/blocks/key"
11
pb "github.com/ipfs/go-ipfs/routing/dht/pb"
routing/dht/pb/dht.pb.go
+1
-1
@@ -14,7 +14,7 @@ It has these top-level messages:
14
*/
15
package dht_pb
16
17
-import proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
17
+import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
18
import math "math"
19
20
// Reference imports to suppress errors if they are not otherwise used.
routing/mock/centralized_client.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"errors"
5
"time"
6
7
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
7
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
8
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
key "github.com/ipfs/go-ipfs/blocks/key"
10
routing "github.com/ipfs/go-ipfs/routing"
routing/offline/offline.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"errors"
5
"time"
6
7
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
7
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
8
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
key "github.com/ipfs/go-ipfs/blocks/key"
10
routing "github.com/ipfs/go-ipfs/routing"
routing/record/record.go
+1
-1
@@ -3,7 +3,7 @@ package record
3
import (
4
"bytes"
5
6
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
6
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
7
8
key "github.com/ipfs/go-ipfs/blocks/key"
9
pb "github.com/ipfs/go-ipfs/routing/dht/pb"
routing/supernode/client.go
+1
-1
@@ -5,7 +5,7 @@ import (
5
"errors"
6
"time"
7
8
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
8
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
9
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
10
11
key "github.com/ipfs/go-ipfs/blocks/key"
routing/supernode/proxy/loopback.go
+1
-1
@@ -1,7 +1,7 @@
1
package proxy
2
3
import (
4
- ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
4
+ ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io"
5
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
6
7
dhtpb "github.com/ipfs/go-ipfs/routing/dht/pb"
routing/supernode/proxy/standard.go
+1
-1
@@ -3,7 +3,7 @@ package proxy
3
import (
4
"errors"
5
6
- ggio "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/io"
6
+ ggio "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/io"
7
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
8
9
key "github.com/ipfs/go-ipfs/blocks/key"
routing/supernode/server.go
+1
-1
@@ -4,7 +4,7 @@ import (
4
"errors"
5
"fmt"
6
7
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
7
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
8
datastore "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
10
unixfs/archive/tar/writer.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
"path"
7
"time"
8
9
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
9
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
10
cxt "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
11
12
mdag "github.com/ipfs/go-ipfs/merkledag"
unixfs/format.go
+1
-1
@@ -6,7 +6,7 @@ package unixfs
6
import (
7
"errors"
8
9
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
9
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
10
pb "github.com/ipfs/go-ipfs/unixfs/pb"
11
)
12
unixfs/format_test.go
+1
-1
@@ -3,7 +3,7 @@ package unixfs
3
import (
4
"testing"
5
6
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
6
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
7
8
pb "github.com/ipfs/go-ipfs/unixfs/pb"
9
)
unixfs/io/dagreader.go
+1
-1
@@ -7,7 +7,7 @@ import (
7
"io"
8
"os"
9
10
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
10
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
11
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
12
13
mdag "github.com/ipfs/go-ipfs/merkledag"
unixfs/mod/dagmodifier.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
"io"
7
"os"
8
9
- proto "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/gogo/protobuf/proto"
9
+ proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
10
mh "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
11
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
12
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/github.com/gogo/protobuf/proto"
17
+import proto "gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
18
import math "math"
19
20
// Reference imports to suppress errors if they are not otherwise used.