Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1 | // Copyright 2018 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style. |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Code generated by generate-types. DO NOT EDIT. |
| 6 | |
| 7 | package impl |
| 8 | |
| 9 | import ( |
| 10 | "math" |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 11 | "unicode/utf8" |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 12 | |
| 13 | "google.golang.org/protobuf/internal/encoding/wire" |
| 14 | "google.golang.org/protobuf/reflect/protoreflect" |
| 15 | ) |
| 16 | |
| 17 | // sizeBool returns the size of wire encoding a bool pointer as a Bool. |
| 18 | func sizeBool(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 19 | v := *p.Bool() |
| 20 | return tagsize + wire.SizeVarint(wire.EncodeBool(v)) |
| 21 | } |
| 22 | |
| 23 | // appendBool wire encodes a bool pointer as a Bool. |
| 24 | func appendBool(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 25 | v := *p.Bool() |
| 26 | b = wire.AppendVarint(b, wiretag) |
| 27 | b = wire.AppendVarint(b, wire.EncodeBool(v)) |
| 28 | return b, nil |
| 29 | } |
| 30 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 31 | // consumeBool wire decodes a bool pointer as a Bool. |
| 32 | func consumeBool(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 33 | if wtyp != wire.VarintType { |
| 34 | return 0, errUnknown |
| 35 | } |
| 36 | v, n := wire.ConsumeVarint(b) |
| 37 | if n < 0 { |
| 38 | return 0, wire.ParseError(n) |
| 39 | } |
| 40 | *p.Bool() = wire.DecodeBool(v) |
| 41 | return n, nil |
| 42 | } |
| 43 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 44 | var coderBool = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 45 | size: sizeBool, |
| 46 | marshal: appendBool, |
| 47 | unmarshal: consumeBool, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 50 | // sizeBoolNoZero returns the size of wire encoding a bool pointer as a Bool. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 51 | // The zero value is not encoded. |
| 52 | func sizeBoolNoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 53 | v := *p.Bool() |
| 54 | if v == false { |
| 55 | return 0 |
| 56 | } |
| 57 | return tagsize + wire.SizeVarint(wire.EncodeBool(v)) |
| 58 | } |
| 59 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 60 | // appendBoolNoZero wire encodes a bool pointer as a Bool. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 61 | // The zero value is not encoded. |
| 62 | func appendBoolNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 63 | v := *p.Bool() |
| 64 | if v == false { |
| 65 | return b, nil |
| 66 | } |
| 67 | b = wire.AppendVarint(b, wiretag) |
| 68 | b = wire.AppendVarint(b, wire.EncodeBool(v)) |
| 69 | return b, nil |
| 70 | } |
| 71 | |
| 72 | var coderBoolNoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 73 | size: sizeBoolNoZero, |
| 74 | marshal: appendBoolNoZero, |
| 75 | unmarshal: consumeBool, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | // sizeBoolPtr returns the size of wire encoding a *bool pointer as a Bool. |
| 79 | // It panics if the pointer is nil. |
| 80 | func sizeBoolPtr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 81 | v := **p.BoolPtr() |
| 82 | return tagsize + wire.SizeVarint(wire.EncodeBool(v)) |
| 83 | } |
| 84 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 85 | // appendBoolPtr wire encodes a *bool pointer as a Bool. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 86 | // It panics if the pointer is nil. |
| 87 | func appendBoolPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 88 | v := **p.BoolPtr() |
| 89 | b = wire.AppendVarint(b, wiretag) |
| 90 | b = wire.AppendVarint(b, wire.EncodeBool(v)) |
| 91 | return b, nil |
| 92 | } |
| 93 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 94 | // consumeBoolPtr wire decodes a *bool pointer as a Bool. |
| 95 | func consumeBoolPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 96 | if wtyp != wire.VarintType { |
| 97 | return 0, errUnknown |
| 98 | } |
| 99 | v, n := wire.ConsumeVarint(b) |
| 100 | if n < 0 { |
| 101 | return 0, wire.ParseError(n) |
| 102 | } |
| 103 | vp := p.BoolPtr() |
| 104 | if *vp == nil { |
| 105 | *vp = new(bool) |
| 106 | } |
| 107 | **vp = wire.DecodeBool(v) |
| 108 | return n, nil |
| 109 | } |
| 110 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 111 | var coderBoolPtr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 112 | size: sizeBoolPtr, |
| 113 | marshal: appendBoolPtr, |
| 114 | unmarshal: consumeBoolPtr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | // sizeBoolSlice returns the size of wire encoding a []bool pointer as a repeated Bool. |
| 118 | func sizeBoolSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 119 | s := *p.BoolSlice() |
| 120 | for _, v := range s { |
| 121 | size += tagsize + wire.SizeVarint(wire.EncodeBool(v)) |
| 122 | } |
| 123 | return size |
| 124 | } |
| 125 | |
| 126 | // appendBoolSlice encodes a []bool pointer as a repeated Bool. |
| 127 | func appendBoolSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 128 | s := *p.BoolSlice() |
| 129 | for _, v := range s { |
| 130 | b = wire.AppendVarint(b, wiretag) |
| 131 | b = wire.AppendVarint(b, wire.EncodeBool(v)) |
| 132 | } |
| 133 | return b, nil |
| 134 | } |
| 135 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 136 | // consumeBoolSlice wire decodes a []bool pointer as a repeated Bool. |
| 137 | func consumeBoolSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 138 | sp := p.BoolSlice() |
| 139 | if wtyp == wire.BytesType { |
| 140 | s := *sp |
| 141 | b, n = wire.ConsumeBytes(b) |
| 142 | if n < 0 { |
| 143 | return 0, wire.ParseError(n) |
| 144 | } |
| 145 | for len(b) > 0 { |
| 146 | v, n := wire.ConsumeVarint(b) |
| 147 | if n < 0 { |
| 148 | return 0, wire.ParseError(n) |
| 149 | } |
| 150 | s = append(s, wire.DecodeBool(v)) |
| 151 | b = b[n:] |
| 152 | } |
| 153 | *sp = s |
| 154 | return n, nil |
| 155 | } |
| 156 | if wtyp != wire.VarintType { |
| 157 | return 0, errUnknown |
| 158 | } |
| 159 | v, n := wire.ConsumeVarint(b) |
| 160 | if n < 0 { |
| 161 | return 0, wire.ParseError(n) |
| 162 | } |
| 163 | *sp = append(*sp, wire.DecodeBool(v)) |
| 164 | return n, nil |
| 165 | } |
| 166 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 167 | var coderBoolSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 168 | size: sizeBoolSlice, |
| 169 | marshal: appendBoolSlice, |
| 170 | unmarshal: consumeBoolSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | // sizeBoolPackedSlice returns the size of wire encoding a []bool pointer as a packed repeated Bool. |
| 174 | func sizeBoolPackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 175 | s := *p.BoolSlice() |
| 176 | if len(s) == 0 { |
| 177 | return 0 |
| 178 | } |
| 179 | n := 0 |
| 180 | for _, v := range s { |
| 181 | n += wire.SizeVarint(wire.EncodeBool(v)) |
| 182 | } |
| 183 | return tagsize + wire.SizeBytes(n) |
| 184 | } |
| 185 | |
| 186 | // appendBoolPackedSlice encodes a []bool pointer as a packed repeated Bool. |
| 187 | func appendBoolPackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 188 | s := *p.BoolSlice() |
| 189 | if len(s) == 0 { |
| 190 | return b, nil |
| 191 | } |
| 192 | b = wire.AppendVarint(b, wiretag) |
| 193 | n := 0 |
| 194 | for _, v := range s { |
| 195 | n += wire.SizeVarint(wire.EncodeBool(v)) |
| 196 | } |
| 197 | b = wire.AppendVarint(b, uint64(n)) |
| 198 | for _, v := range s { |
| 199 | b = wire.AppendVarint(b, wire.EncodeBool(v)) |
| 200 | } |
| 201 | return b, nil |
| 202 | } |
| 203 | |
| 204 | var coderBoolPackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 205 | size: sizeBoolPackedSlice, |
| 206 | marshal: appendBoolPackedSlice, |
| 207 | unmarshal: consumeBoolSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 210 | // sizeBoolValue returns the size of wire encoding a bool value as a Bool. |
| 211 | func sizeBoolValue(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
| 212 | return tagsize + wire.SizeVarint(wire.EncodeBool(v.Bool())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 215 | // appendBoolValue encodes a bool value as a Bool. |
| 216 | func appendBoolValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 217 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 218 | b = wire.AppendVarint(b, wire.EncodeBool(v.Bool())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 219 | return b, nil |
| 220 | } |
| 221 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 222 | // consumeBoolValue decodes a bool value as a Bool. |
| 223 | func consumeBoolValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 224 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 225 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 226 | } |
| 227 | v, n := wire.ConsumeVarint(b) |
| 228 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 229 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 230 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 231 | return protoreflect.ValueOfBool(wire.DecodeBool(v)), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 234 | var coderBoolValue = valueCoderFuncs{ |
| 235 | size: sizeBoolValue, |
| 236 | marshal: appendBoolValue, |
| 237 | unmarshal: consumeBoolValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 240 | // sizeBoolSliceValue returns the size of wire encoding a []bool value as a repeated Bool. |
| 241 | func sizeBoolSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 242 | list := listv.List() |
| 243 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 244 | v := list.Get(i) |
| 245 | size += tagsize + wire.SizeVarint(wire.EncodeBool(v.Bool())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 246 | } |
| 247 | return size |
| 248 | } |
| 249 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 250 | // appendBoolSliceValue encodes a []bool value as a repeated Bool. |
| 251 | func appendBoolSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 252 | list := listv.List() |
| 253 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 254 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 255 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 256 | b = wire.AppendVarint(b, wire.EncodeBool(v.Bool())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 257 | } |
| 258 | return b, nil |
| 259 | } |
| 260 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 261 | // consumeBoolSliceValue wire decodes a []bool value as a repeated Bool. |
| 262 | func consumeBoolSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 263 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 264 | if wtyp == wire.BytesType { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 265 | b, n = wire.ConsumeBytes(b) |
| 266 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 267 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 268 | } |
| 269 | for len(b) > 0 { |
| 270 | v, n := wire.ConsumeVarint(b) |
| 271 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 272 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 273 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 274 | list.Append(protoreflect.ValueOfBool(wire.DecodeBool(v))) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 275 | b = b[n:] |
| 276 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 277 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 278 | } |
| 279 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 280 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 281 | } |
| 282 | v, n := wire.ConsumeVarint(b) |
| 283 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 284 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 285 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 286 | list.Append(protoreflect.ValueOfBool(wire.DecodeBool(v))) |
| 287 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 290 | var coderBoolSliceValue = valueCoderFuncs{ |
| 291 | size: sizeBoolSliceValue, |
| 292 | marshal: appendBoolSliceValue, |
| 293 | unmarshal: consumeBoolSliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 296 | // sizeBoolPackedSliceValue returns the size of wire encoding a []bool value as a packed repeated Bool. |
| 297 | func sizeBoolPackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 298 | list := listv.List() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 299 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 300 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 301 | v := list.Get(i) |
| 302 | n += wire.SizeVarint(wire.EncodeBool(v.Bool())) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 303 | } |
| 304 | return tagsize + wire.SizeBytes(n) |
| 305 | } |
| 306 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 307 | // appendBoolPackedSliceValue encodes a []bool value as a packed repeated Bool. |
| 308 | func appendBoolPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 309 | list := listv.List() |
| 310 | llen := list.Len() |
| 311 | if llen == 0 { |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 312 | return b, nil |
| 313 | } |
| 314 | b = wire.AppendVarint(b, wiretag) |
| 315 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 316 | for i := 0; i < llen; i++ { |
| 317 | v := list.Get(i) |
| 318 | n += wire.SizeVarint(wire.EncodeBool(v.Bool())) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 319 | } |
| 320 | b = wire.AppendVarint(b, uint64(n)) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 321 | for i := 0; i < llen; i++ { |
| 322 | v := list.Get(i) |
| 323 | b = wire.AppendVarint(b, wire.EncodeBool(v.Bool())) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 324 | } |
| 325 | return b, nil |
| 326 | } |
| 327 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 328 | var coderBoolPackedSliceValue = valueCoderFuncs{ |
| 329 | size: sizeBoolPackedSliceValue, |
| 330 | marshal: appendBoolPackedSliceValue, |
| 331 | unmarshal: consumeBoolSliceValue, |
| 332 | } |
| 333 | |
| 334 | // sizeEnumValue returns the size of wire encoding a value as a Enum. |
| 335 | func sizeEnumValue(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
| 336 | return tagsize + wire.SizeVarint(uint64(v.Enum())) |
| 337 | } |
| 338 | |
| 339 | // appendEnumValue encodes a value as a Enum. |
| 340 | func appendEnumValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 341 | b = wire.AppendVarint(b, wiretag) |
| 342 | b = wire.AppendVarint(b, uint64(v.Enum())) |
| 343 | return b, nil |
| 344 | } |
| 345 | |
| 346 | // consumeEnumValue decodes a value as a Enum. |
| 347 | func consumeEnumValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
| 348 | if wtyp != wire.VarintType { |
| 349 | return protoreflect.Value{}, 0, errUnknown |
| 350 | } |
| 351 | v, n := wire.ConsumeVarint(b) |
| 352 | if n < 0 { |
| 353 | return protoreflect.Value{}, 0, wire.ParseError(n) |
| 354 | } |
| 355 | return protoreflect.ValueOfEnum(protoreflect.EnumNumber(v)), n, nil |
| 356 | } |
| 357 | |
| 358 | var coderEnumValue = valueCoderFuncs{ |
| 359 | size: sizeEnumValue, |
| 360 | marshal: appendEnumValue, |
| 361 | unmarshal: consumeEnumValue, |
| 362 | } |
| 363 | |
| 364 | // sizeEnumSliceValue returns the size of wire encoding a [] value as a repeated Enum. |
| 365 | func sizeEnumSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 366 | list := listv.List() |
| 367 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 368 | v := list.Get(i) |
| 369 | size += tagsize + wire.SizeVarint(uint64(v.Enum())) |
| 370 | } |
| 371 | return size |
| 372 | } |
| 373 | |
| 374 | // appendEnumSliceValue encodes a [] value as a repeated Enum. |
| 375 | func appendEnumSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 376 | list := listv.List() |
| 377 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 378 | v := list.Get(i) |
| 379 | b = wire.AppendVarint(b, wiretag) |
| 380 | b = wire.AppendVarint(b, uint64(v.Enum())) |
| 381 | } |
| 382 | return b, nil |
| 383 | } |
| 384 | |
| 385 | // consumeEnumSliceValue wire decodes a [] value as a repeated Enum. |
| 386 | func consumeEnumSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 387 | list := listv.List() |
| 388 | if wtyp == wire.BytesType { |
| 389 | b, n = wire.ConsumeBytes(b) |
| 390 | if n < 0 { |
| 391 | return protoreflect.Value{}, 0, wire.ParseError(n) |
| 392 | } |
| 393 | for len(b) > 0 { |
| 394 | v, n := wire.ConsumeVarint(b) |
| 395 | if n < 0 { |
| 396 | return protoreflect.Value{}, 0, wire.ParseError(n) |
| 397 | } |
| 398 | list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v))) |
| 399 | b = b[n:] |
| 400 | } |
| 401 | return listv, n, nil |
| 402 | } |
| 403 | if wtyp != wire.VarintType { |
| 404 | return protoreflect.Value{}, 0, errUnknown |
| 405 | } |
| 406 | v, n := wire.ConsumeVarint(b) |
| 407 | if n < 0 { |
| 408 | return protoreflect.Value{}, 0, wire.ParseError(n) |
| 409 | } |
| 410 | list.Append(protoreflect.ValueOfEnum(protoreflect.EnumNumber(v))) |
| 411 | return listv, n, nil |
| 412 | } |
| 413 | |
| 414 | var coderEnumSliceValue = valueCoderFuncs{ |
| 415 | size: sizeEnumSliceValue, |
| 416 | marshal: appendEnumSliceValue, |
| 417 | unmarshal: consumeEnumSliceValue, |
| 418 | } |
| 419 | |
| 420 | // sizeEnumPackedSliceValue returns the size of wire encoding a [] value as a packed repeated Enum. |
| 421 | func sizeEnumPackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 422 | list := listv.List() |
| 423 | n := 0 |
| 424 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 425 | v := list.Get(i) |
| 426 | n += wire.SizeVarint(uint64(v.Enum())) |
| 427 | } |
| 428 | return tagsize + wire.SizeBytes(n) |
| 429 | } |
| 430 | |
| 431 | // appendEnumPackedSliceValue encodes a [] value as a packed repeated Enum. |
| 432 | func appendEnumPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 433 | list := listv.List() |
| 434 | llen := list.Len() |
| 435 | if llen == 0 { |
| 436 | return b, nil |
| 437 | } |
| 438 | b = wire.AppendVarint(b, wiretag) |
| 439 | n := 0 |
| 440 | for i := 0; i < llen; i++ { |
| 441 | v := list.Get(i) |
| 442 | n += wire.SizeVarint(uint64(v.Enum())) |
| 443 | } |
| 444 | b = wire.AppendVarint(b, uint64(n)) |
| 445 | for i := 0; i < llen; i++ { |
| 446 | v := list.Get(i) |
| 447 | b = wire.AppendVarint(b, uint64(v.Enum())) |
| 448 | } |
| 449 | return b, nil |
| 450 | } |
| 451 | |
| 452 | var coderEnumPackedSliceValue = valueCoderFuncs{ |
| 453 | size: sizeEnumPackedSliceValue, |
| 454 | marshal: appendEnumPackedSliceValue, |
| 455 | unmarshal: consumeEnumSliceValue, |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 458 | // sizeInt32 returns the size of wire encoding a int32 pointer as a Int32. |
| 459 | func sizeInt32(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 460 | v := *p.Int32() |
| 461 | return tagsize + wire.SizeVarint(uint64(v)) |
| 462 | } |
| 463 | |
| 464 | // appendInt32 wire encodes a int32 pointer as a Int32. |
| 465 | func appendInt32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 466 | v := *p.Int32() |
| 467 | b = wire.AppendVarint(b, wiretag) |
| 468 | b = wire.AppendVarint(b, uint64(v)) |
| 469 | return b, nil |
| 470 | } |
| 471 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 472 | // consumeInt32 wire decodes a int32 pointer as a Int32. |
| 473 | func consumeInt32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 474 | if wtyp != wire.VarintType { |
| 475 | return 0, errUnknown |
| 476 | } |
| 477 | v, n := wire.ConsumeVarint(b) |
| 478 | if n < 0 { |
| 479 | return 0, wire.ParseError(n) |
| 480 | } |
| 481 | *p.Int32() = int32(v) |
| 482 | return n, nil |
| 483 | } |
| 484 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 485 | var coderInt32 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 486 | size: sizeInt32, |
| 487 | marshal: appendInt32, |
| 488 | unmarshal: consumeInt32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 491 | // sizeInt32NoZero returns the size of wire encoding a int32 pointer as a Int32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 492 | // The zero value is not encoded. |
| 493 | func sizeInt32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 494 | v := *p.Int32() |
| 495 | if v == 0 { |
| 496 | return 0 |
| 497 | } |
| 498 | return tagsize + wire.SizeVarint(uint64(v)) |
| 499 | } |
| 500 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 501 | // appendInt32NoZero wire encodes a int32 pointer as a Int32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 502 | // The zero value is not encoded. |
| 503 | func appendInt32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 504 | v := *p.Int32() |
| 505 | if v == 0 { |
| 506 | return b, nil |
| 507 | } |
| 508 | b = wire.AppendVarint(b, wiretag) |
| 509 | b = wire.AppendVarint(b, uint64(v)) |
| 510 | return b, nil |
| 511 | } |
| 512 | |
| 513 | var coderInt32NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 514 | size: sizeInt32NoZero, |
| 515 | marshal: appendInt32NoZero, |
| 516 | unmarshal: consumeInt32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | // sizeInt32Ptr returns the size of wire encoding a *int32 pointer as a Int32. |
| 520 | // It panics if the pointer is nil. |
| 521 | func sizeInt32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 522 | v := **p.Int32Ptr() |
| 523 | return tagsize + wire.SizeVarint(uint64(v)) |
| 524 | } |
| 525 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 526 | // appendInt32Ptr wire encodes a *int32 pointer as a Int32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 527 | // It panics if the pointer is nil. |
| 528 | func appendInt32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 529 | v := **p.Int32Ptr() |
| 530 | b = wire.AppendVarint(b, wiretag) |
| 531 | b = wire.AppendVarint(b, uint64(v)) |
| 532 | return b, nil |
| 533 | } |
| 534 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 535 | // consumeInt32Ptr wire decodes a *int32 pointer as a Int32. |
| 536 | func consumeInt32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 537 | if wtyp != wire.VarintType { |
| 538 | return 0, errUnknown |
| 539 | } |
| 540 | v, n := wire.ConsumeVarint(b) |
| 541 | if n < 0 { |
| 542 | return 0, wire.ParseError(n) |
| 543 | } |
| 544 | vp := p.Int32Ptr() |
| 545 | if *vp == nil { |
| 546 | *vp = new(int32) |
| 547 | } |
| 548 | **vp = int32(v) |
| 549 | return n, nil |
| 550 | } |
| 551 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 552 | var coderInt32Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 553 | size: sizeInt32Ptr, |
| 554 | marshal: appendInt32Ptr, |
| 555 | unmarshal: consumeInt32Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | // sizeInt32Slice returns the size of wire encoding a []int32 pointer as a repeated Int32. |
| 559 | func sizeInt32Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 560 | s := *p.Int32Slice() |
| 561 | for _, v := range s { |
| 562 | size += tagsize + wire.SizeVarint(uint64(v)) |
| 563 | } |
| 564 | return size |
| 565 | } |
| 566 | |
| 567 | // appendInt32Slice encodes a []int32 pointer as a repeated Int32. |
| 568 | func appendInt32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 569 | s := *p.Int32Slice() |
| 570 | for _, v := range s { |
| 571 | b = wire.AppendVarint(b, wiretag) |
| 572 | b = wire.AppendVarint(b, uint64(v)) |
| 573 | } |
| 574 | return b, nil |
| 575 | } |
| 576 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 577 | // consumeInt32Slice wire decodes a []int32 pointer as a repeated Int32. |
| 578 | func consumeInt32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 579 | sp := p.Int32Slice() |
| 580 | if wtyp == wire.BytesType { |
| 581 | s := *sp |
| 582 | b, n = wire.ConsumeBytes(b) |
| 583 | if n < 0 { |
| 584 | return 0, wire.ParseError(n) |
| 585 | } |
| 586 | for len(b) > 0 { |
| 587 | v, n := wire.ConsumeVarint(b) |
| 588 | if n < 0 { |
| 589 | return 0, wire.ParseError(n) |
| 590 | } |
| 591 | s = append(s, int32(v)) |
| 592 | b = b[n:] |
| 593 | } |
| 594 | *sp = s |
| 595 | return n, nil |
| 596 | } |
| 597 | if wtyp != wire.VarintType { |
| 598 | return 0, errUnknown |
| 599 | } |
| 600 | v, n := wire.ConsumeVarint(b) |
| 601 | if n < 0 { |
| 602 | return 0, wire.ParseError(n) |
| 603 | } |
| 604 | *sp = append(*sp, int32(v)) |
| 605 | return n, nil |
| 606 | } |
| 607 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 608 | var coderInt32Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 609 | size: sizeInt32Slice, |
| 610 | marshal: appendInt32Slice, |
| 611 | unmarshal: consumeInt32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | // sizeInt32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Int32. |
| 615 | func sizeInt32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 616 | s := *p.Int32Slice() |
| 617 | if len(s) == 0 { |
| 618 | return 0 |
| 619 | } |
| 620 | n := 0 |
| 621 | for _, v := range s { |
| 622 | n += wire.SizeVarint(uint64(v)) |
| 623 | } |
| 624 | return tagsize + wire.SizeBytes(n) |
| 625 | } |
| 626 | |
| 627 | // appendInt32PackedSlice encodes a []int32 pointer as a packed repeated Int32. |
| 628 | func appendInt32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 629 | s := *p.Int32Slice() |
| 630 | if len(s) == 0 { |
| 631 | return b, nil |
| 632 | } |
| 633 | b = wire.AppendVarint(b, wiretag) |
| 634 | n := 0 |
| 635 | for _, v := range s { |
| 636 | n += wire.SizeVarint(uint64(v)) |
| 637 | } |
| 638 | b = wire.AppendVarint(b, uint64(n)) |
| 639 | for _, v := range s { |
| 640 | b = wire.AppendVarint(b, uint64(v)) |
| 641 | } |
| 642 | return b, nil |
| 643 | } |
| 644 | |
| 645 | var coderInt32PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 646 | size: sizeInt32PackedSlice, |
| 647 | marshal: appendInt32PackedSlice, |
| 648 | unmarshal: consumeInt32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 649 | } |
| 650 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 651 | // sizeInt32Value returns the size of wire encoding a int32 value as a Int32. |
| 652 | func sizeInt32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
| 653 | return tagsize + wire.SizeVarint(uint64(int32(v.Int()))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 656 | // appendInt32Value encodes a int32 value as a Int32. |
| 657 | func appendInt32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 658 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 659 | b = wire.AppendVarint(b, uint64(int32(v.Int()))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 660 | return b, nil |
| 661 | } |
| 662 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 663 | // consumeInt32Value decodes a int32 value as a Int32. |
| 664 | func consumeInt32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 665 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 666 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 667 | } |
| 668 | v, n := wire.ConsumeVarint(b) |
| 669 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 670 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 671 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 672 | return protoreflect.ValueOfInt32(int32(v)), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 675 | var coderInt32Value = valueCoderFuncs{ |
| 676 | size: sizeInt32Value, |
| 677 | marshal: appendInt32Value, |
| 678 | unmarshal: consumeInt32Value, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 681 | // sizeInt32SliceValue returns the size of wire encoding a []int32 value as a repeated Int32. |
| 682 | func sizeInt32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 683 | list := listv.List() |
| 684 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 685 | v := list.Get(i) |
| 686 | size += tagsize + wire.SizeVarint(uint64(int32(v.Int()))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 687 | } |
| 688 | return size |
| 689 | } |
| 690 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 691 | // appendInt32SliceValue encodes a []int32 value as a repeated Int32. |
| 692 | func appendInt32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 693 | list := listv.List() |
| 694 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 695 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 696 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 697 | b = wire.AppendVarint(b, uint64(int32(v.Int()))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 698 | } |
| 699 | return b, nil |
| 700 | } |
| 701 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 702 | // consumeInt32SliceValue wire decodes a []int32 value as a repeated Int32. |
| 703 | func consumeInt32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 704 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 705 | if wtyp == wire.BytesType { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 706 | b, n = wire.ConsumeBytes(b) |
| 707 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 708 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 709 | } |
| 710 | for len(b) > 0 { |
| 711 | v, n := wire.ConsumeVarint(b) |
| 712 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 713 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 714 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 715 | list.Append(protoreflect.ValueOfInt32(int32(v))) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 716 | b = b[n:] |
| 717 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 718 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 719 | } |
| 720 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 721 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 722 | } |
| 723 | v, n := wire.ConsumeVarint(b) |
| 724 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 725 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 726 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 727 | list.Append(protoreflect.ValueOfInt32(int32(v))) |
| 728 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 729 | } |
| 730 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 731 | var coderInt32SliceValue = valueCoderFuncs{ |
| 732 | size: sizeInt32SliceValue, |
| 733 | marshal: appendInt32SliceValue, |
| 734 | unmarshal: consumeInt32SliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 735 | } |
| 736 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 737 | // sizeInt32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Int32. |
| 738 | func sizeInt32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 739 | list := listv.List() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 740 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 741 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 742 | v := list.Get(i) |
| 743 | n += wire.SizeVarint(uint64(int32(v.Int()))) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 744 | } |
| 745 | return tagsize + wire.SizeBytes(n) |
| 746 | } |
| 747 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 748 | // appendInt32PackedSliceValue encodes a []int32 value as a packed repeated Int32. |
| 749 | func appendInt32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 750 | list := listv.List() |
| 751 | llen := list.Len() |
| 752 | if llen == 0 { |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 753 | return b, nil |
| 754 | } |
| 755 | b = wire.AppendVarint(b, wiretag) |
| 756 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 757 | for i := 0; i < llen; i++ { |
| 758 | v := list.Get(i) |
| 759 | n += wire.SizeVarint(uint64(int32(v.Int()))) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 760 | } |
| 761 | b = wire.AppendVarint(b, uint64(n)) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 762 | for i := 0; i < llen; i++ { |
| 763 | v := list.Get(i) |
| 764 | b = wire.AppendVarint(b, uint64(int32(v.Int()))) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 765 | } |
| 766 | return b, nil |
| 767 | } |
| 768 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 769 | var coderInt32PackedSliceValue = valueCoderFuncs{ |
| 770 | size: sizeInt32PackedSliceValue, |
| 771 | marshal: appendInt32PackedSliceValue, |
| 772 | unmarshal: consumeInt32SliceValue, |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 775 | // sizeSint32 returns the size of wire encoding a int32 pointer as a Sint32. |
| 776 | func sizeSint32(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 777 | v := *p.Int32() |
| 778 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 779 | } |
| 780 | |
| 781 | // appendSint32 wire encodes a int32 pointer as a Sint32. |
| 782 | func appendSint32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 783 | v := *p.Int32() |
| 784 | b = wire.AppendVarint(b, wiretag) |
| 785 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v))) |
| 786 | return b, nil |
| 787 | } |
| 788 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 789 | // consumeSint32 wire decodes a int32 pointer as a Sint32. |
| 790 | func consumeSint32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 791 | if wtyp != wire.VarintType { |
| 792 | return 0, errUnknown |
| 793 | } |
| 794 | v, n := wire.ConsumeVarint(b) |
| 795 | if n < 0 { |
| 796 | return 0, wire.ParseError(n) |
| 797 | } |
| 798 | *p.Int32() = int32(wire.DecodeZigZag(v & math.MaxUint32)) |
| 799 | return n, nil |
| 800 | } |
| 801 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 802 | var coderSint32 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 803 | size: sizeSint32, |
| 804 | marshal: appendSint32, |
| 805 | unmarshal: consumeSint32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 808 | // sizeSint32NoZero returns the size of wire encoding a int32 pointer as a Sint32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 809 | // The zero value is not encoded. |
| 810 | func sizeSint32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 811 | v := *p.Int32() |
| 812 | if v == 0 { |
| 813 | return 0 |
| 814 | } |
| 815 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 816 | } |
| 817 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 818 | // appendSint32NoZero wire encodes a int32 pointer as a Sint32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 819 | // The zero value is not encoded. |
| 820 | func appendSint32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 821 | v := *p.Int32() |
| 822 | if v == 0 { |
| 823 | return b, nil |
| 824 | } |
| 825 | b = wire.AppendVarint(b, wiretag) |
| 826 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v))) |
| 827 | return b, nil |
| 828 | } |
| 829 | |
| 830 | var coderSint32NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 831 | size: sizeSint32NoZero, |
| 832 | marshal: appendSint32NoZero, |
| 833 | unmarshal: consumeSint32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | // sizeSint32Ptr returns the size of wire encoding a *int32 pointer as a Sint32. |
| 837 | // It panics if the pointer is nil. |
| 838 | func sizeSint32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 839 | v := **p.Int32Ptr() |
| 840 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 841 | } |
| 842 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 843 | // appendSint32Ptr wire encodes a *int32 pointer as a Sint32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 844 | // It panics if the pointer is nil. |
| 845 | func appendSint32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 846 | v := **p.Int32Ptr() |
| 847 | b = wire.AppendVarint(b, wiretag) |
| 848 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v))) |
| 849 | return b, nil |
| 850 | } |
| 851 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 852 | // consumeSint32Ptr wire decodes a *int32 pointer as a Sint32. |
| 853 | func consumeSint32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 854 | if wtyp != wire.VarintType { |
| 855 | return 0, errUnknown |
| 856 | } |
| 857 | v, n := wire.ConsumeVarint(b) |
| 858 | if n < 0 { |
| 859 | return 0, wire.ParseError(n) |
| 860 | } |
| 861 | vp := p.Int32Ptr() |
| 862 | if *vp == nil { |
| 863 | *vp = new(int32) |
| 864 | } |
| 865 | **vp = int32(wire.DecodeZigZag(v & math.MaxUint32)) |
| 866 | return n, nil |
| 867 | } |
| 868 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 869 | var coderSint32Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 870 | size: sizeSint32Ptr, |
| 871 | marshal: appendSint32Ptr, |
| 872 | unmarshal: consumeSint32Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | // sizeSint32Slice returns the size of wire encoding a []int32 pointer as a repeated Sint32. |
| 876 | func sizeSint32Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 877 | s := *p.Int32Slice() |
| 878 | for _, v := range s { |
| 879 | size += tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 880 | } |
| 881 | return size |
| 882 | } |
| 883 | |
| 884 | // appendSint32Slice encodes a []int32 pointer as a repeated Sint32. |
| 885 | func appendSint32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 886 | s := *p.Int32Slice() |
| 887 | for _, v := range s { |
| 888 | b = wire.AppendVarint(b, wiretag) |
| 889 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v))) |
| 890 | } |
| 891 | return b, nil |
| 892 | } |
| 893 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 894 | // consumeSint32Slice wire decodes a []int32 pointer as a repeated Sint32. |
| 895 | func consumeSint32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 896 | sp := p.Int32Slice() |
| 897 | if wtyp == wire.BytesType { |
| 898 | s := *sp |
| 899 | b, n = wire.ConsumeBytes(b) |
| 900 | if n < 0 { |
| 901 | return 0, wire.ParseError(n) |
| 902 | } |
| 903 | for len(b) > 0 { |
| 904 | v, n := wire.ConsumeVarint(b) |
| 905 | if n < 0 { |
| 906 | return 0, wire.ParseError(n) |
| 907 | } |
| 908 | s = append(s, int32(wire.DecodeZigZag(v&math.MaxUint32))) |
| 909 | b = b[n:] |
| 910 | } |
| 911 | *sp = s |
| 912 | return n, nil |
| 913 | } |
| 914 | if wtyp != wire.VarintType { |
| 915 | return 0, errUnknown |
| 916 | } |
| 917 | v, n := wire.ConsumeVarint(b) |
| 918 | if n < 0 { |
| 919 | return 0, wire.ParseError(n) |
| 920 | } |
| 921 | *sp = append(*sp, int32(wire.DecodeZigZag(v&math.MaxUint32))) |
| 922 | return n, nil |
| 923 | } |
| 924 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 925 | var coderSint32Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 926 | size: sizeSint32Slice, |
| 927 | marshal: appendSint32Slice, |
| 928 | unmarshal: consumeSint32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | // sizeSint32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sint32. |
| 932 | func sizeSint32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 933 | s := *p.Int32Slice() |
| 934 | if len(s) == 0 { |
| 935 | return 0 |
| 936 | } |
| 937 | n := 0 |
| 938 | for _, v := range s { |
| 939 | n += wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 940 | } |
| 941 | return tagsize + wire.SizeBytes(n) |
| 942 | } |
| 943 | |
| 944 | // appendSint32PackedSlice encodes a []int32 pointer as a packed repeated Sint32. |
| 945 | func appendSint32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 946 | s := *p.Int32Slice() |
| 947 | if len(s) == 0 { |
| 948 | return b, nil |
| 949 | } |
| 950 | b = wire.AppendVarint(b, wiretag) |
| 951 | n := 0 |
| 952 | for _, v := range s { |
| 953 | n += wire.SizeVarint(wire.EncodeZigZag(int64(v))) |
| 954 | } |
| 955 | b = wire.AppendVarint(b, uint64(n)) |
| 956 | for _, v := range s { |
| 957 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(v))) |
| 958 | } |
| 959 | return b, nil |
| 960 | } |
| 961 | |
| 962 | var coderSint32PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 963 | size: sizeSint32PackedSlice, |
| 964 | marshal: appendSint32PackedSlice, |
| 965 | unmarshal: consumeSint32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 966 | } |
| 967 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 968 | // sizeSint32Value returns the size of wire encoding a int32 value as a Sint32. |
| 969 | func sizeSint32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
| 970 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(int32(v.Int())))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 971 | } |
| 972 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 973 | // appendSint32Value encodes a int32 value as a Sint32. |
| 974 | func appendSint32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 975 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 976 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(int32(v.Int())))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 977 | return b, nil |
| 978 | } |
| 979 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 980 | // consumeSint32Value decodes a int32 value as a Sint32. |
| 981 | func consumeSint32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 982 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 983 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 984 | } |
| 985 | v, n := wire.ConsumeVarint(b) |
| 986 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 987 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 988 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 989 | return protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32))), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 990 | } |
| 991 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 992 | var coderSint32Value = valueCoderFuncs{ |
| 993 | size: sizeSint32Value, |
| 994 | marshal: appendSint32Value, |
| 995 | unmarshal: consumeSint32Value, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 998 | // sizeSint32SliceValue returns the size of wire encoding a []int32 value as a repeated Sint32. |
| 999 | func sizeSint32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 1000 | list := listv.List() |
| 1001 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1002 | v := list.Get(i) |
| 1003 | size += tagsize + wire.SizeVarint(wire.EncodeZigZag(int64(int32(v.Int())))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1004 | } |
| 1005 | return size |
| 1006 | } |
| 1007 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1008 | // appendSint32SliceValue encodes a []int32 value as a repeated Sint32. |
| 1009 | func appendSint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1010 | list := listv.List() |
| 1011 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1012 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1013 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1014 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(int32(v.Int())))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1015 | } |
| 1016 | return b, nil |
| 1017 | } |
| 1018 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1019 | // consumeSint32SliceValue wire decodes a []int32 value as a repeated Sint32. |
| 1020 | func consumeSint32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 1021 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1022 | if wtyp == wire.BytesType { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1023 | b, n = wire.ConsumeBytes(b) |
| 1024 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1025 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1026 | } |
| 1027 | for len(b) > 0 { |
| 1028 | v, n := wire.ConsumeVarint(b) |
| 1029 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1030 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1031 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1032 | list.Append(protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32)))) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1033 | b = b[n:] |
| 1034 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1035 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1036 | } |
| 1037 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1038 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1039 | } |
| 1040 | v, n := wire.ConsumeVarint(b) |
| 1041 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1042 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1043 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1044 | list.Append(protoreflect.ValueOfInt32(int32(wire.DecodeZigZag(v & math.MaxUint32)))) |
| 1045 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1048 | var coderSint32SliceValue = valueCoderFuncs{ |
| 1049 | size: sizeSint32SliceValue, |
| 1050 | marshal: appendSint32SliceValue, |
| 1051 | unmarshal: consumeSint32SliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1054 | // sizeSint32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Sint32. |
| 1055 | func sizeSint32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 1056 | list := listv.List() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1057 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1058 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1059 | v := list.Get(i) |
| 1060 | n += wire.SizeVarint(wire.EncodeZigZag(int64(int32(v.Int())))) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1061 | } |
| 1062 | return tagsize + wire.SizeBytes(n) |
| 1063 | } |
| 1064 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1065 | // appendSint32PackedSliceValue encodes a []int32 value as a packed repeated Sint32. |
| 1066 | func appendSint32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1067 | list := listv.List() |
| 1068 | llen := list.Len() |
| 1069 | if llen == 0 { |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1070 | return b, nil |
| 1071 | } |
| 1072 | b = wire.AppendVarint(b, wiretag) |
| 1073 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1074 | for i := 0; i < llen; i++ { |
| 1075 | v := list.Get(i) |
| 1076 | n += wire.SizeVarint(wire.EncodeZigZag(int64(int32(v.Int())))) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1077 | } |
| 1078 | b = wire.AppendVarint(b, uint64(n)) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1079 | for i := 0; i < llen; i++ { |
| 1080 | v := list.Get(i) |
| 1081 | b = wire.AppendVarint(b, wire.EncodeZigZag(int64(int32(v.Int())))) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1082 | } |
| 1083 | return b, nil |
| 1084 | } |
| 1085 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1086 | var coderSint32PackedSliceValue = valueCoderFuncs{ |
| 1087 | size: sizeSint32PackedSliceValue, |
| 1088 | marshal: appendSint32PackedSliceValue, |
| 1089 | unmarshal: consumeSint32SliceValue, |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1092 | // sizeUint32 returns the size of wire encoding a uint32 pointer as a Uint32. |
| 1093 | func sizeUint32(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1094 | v := *p.Uint32() |
| 1095 | return tagsize + wire.SizeVarint(uint64(v)) |
| 1096 | } |
| 1097 | |
| 1098 | // appendUint32 wire encodes a uint32 pointer as a Uint32. |
| 1099 | func appendUint32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1100 | v := *p.Uint32() |
| 1101 | b = wire.AppendVarint(b, wiretag) |
| 1102 | b = wire.AppendVarint(b, uint64(v)) |
| 1103 | return b, nil |
| 1104 | } |
| 1105 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1106 | // consumeUint32 wire decodes a uint32 pointer as a Uint32. |
| 1107 | func consumeUint32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1108 | if wtyp != wire.VarintType { |
| 1109 | return 0, errUnknown |
| 1110 | } |
| 1111 | v, n := wire.ConsumeVarint(b) |
| 1112 | if n < 0 { |
| 1113 | return 0, wire.ParseError(n) |
| 1114 | } |
| 1115 | *p.Uint32() = uint32(v) |
| 1116 | return n, nil |
| 1117 | } |
| 1118 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1119 | var coderUint32 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1120 | size: sizeUint32, |
| 1121 | marshal: appendUint32, |
| 1122 | unmarshal: consumeUint32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 1125 | // sizeUint32NoZero returns the size of wire encoding a uint32 pointer as a Uint32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1126 | // The zero value is not encoded. |
| 1127 | func sizeUint32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1128 | v := *p.Uint32() |
| 1129 | if v == 0 { |
| 1130 | return 0 |
| 1131 | } |
| 1132 | return tagsize + wire.SizeVarint(uint64(v)) |
| 1133 | } |
| 1134 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 1135 | // appendUint32NoZero wire encodes a uint32 pointer as a Uint32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1136 | // The zero value is not encoded. |
| 1137 | func appendUint32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1138 | v := *p.Uint32() |
| 1139 | if v == 0 { |
| 1140 | return b, nil |
| 1141 | } |
| 1142 | b = wire.AppendVarint(b, wiretag) |
| 1143 | b = wire.AppendVarint(b, uint64(v)) |
| 1144 | return b, nil |
| 1145 | } |
| 1146 | |
| 1147 | var coderUint32NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1148 | size: sizeUint32NoZero, |
| 1149 | marshal: appendUint32NoZero, |
| 1150 | unmarshal: consumeUint32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | // sizeUint32Ptr returns the size of wire encoding a *uint32 pointer as a Uint32. |
| 1154 | // It panics if the pointer is nil. |
| 1155 | func sizeUint32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1156 | v := **p.Uint32Ptr() |
| 1157 | return tagsize + wire.SizeVarint(uint64(v)) |
| 1158 | } |
| 1159 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1160 | // appendUint32Ptr wire encodes a *uint32 pointer as a Uint32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1161 | // It panics if the pointer is nil. |
| 1162 | func appendUint32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1163 | v := **p.Uint32Ptr() |
| 1164 | b = wire.AppendVarint(b, wiretag) |
| 1165 | b = wire.AppendVarint(b, uint64(v)) |
| 1166 | return b, nil |
| 1167 | } |
| 1168 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1169 | // consumeUint32Ptr wire decodes a *uint32 pointer as a Uint32. |
| 1170 | func consumeUint32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1171 | if wtyp != wire.VarintType { |
| 1172 | return 0, errUnknown |
| 1173 | } |
| 1174 | v, n := wire.ConsumeVarint(b) |
| 1175 | if n < 0 { |
| 1176 | return 0, wire.ParseError(n) |
| 1177 | } |
| 1178 | vp := p.Uint32Ptr() |
| 1179 | if *vp == nil { |
| 1180 | *vp = new(uint32) |
| 1181 | } |
| 1182 | **vp = uint32(v) |
| 1183 | return n, nil |
| 1184 | } |
| 1185 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1186 | var coderUint32Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1187 | size: sizeUint32Ptr, |
| 1188 | marshal: appendUint32Ptr, |
| 1189 | unmarshal: consumeUint32Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | // sizeUint32Slice returns the size of wire encoding a []uint32 pointer as a repeated Uint32. |
| 1193 | func sizeUint32Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1194 | s := *p.Uint32Slice() |
| 1195 | for _, v := range s { |
| 1196 | size += tagsize + wire.SizeVarint(uint64(v)) |
| 1197 | } |
| 1198 | return size |
| 1199 | } |
| 1200 | |
| 1201 | // appendUint32Slice encodes a []uint32 pointer as a repeated Uint32. |
| 1202 | func appendUint32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1203 | s := *p.Uint32Slice() |
| 1204 | for _, v := range s { |
| 1205 | b = wire.AppendVarint(b, wiretag) |
| 1206 | b = wire.AppendVarint(b, uint64(v)) |
| 1207 | } |
| 1208 | return b, nil |
| 1209 | } |
| 1210 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1211 | // consumeUint32Slice wire decodes a []uint32 pointer as a repeated Uint32. |
| 1212 | func consumeUint32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1213 | sp := p.Uint32Slice() |
| 1214 | if wtyp == wire.BytesType { |
| 1215 | s := *sp |
| 1216 | b, n = wire.ConsumeBytes(b) |
| 1217 | if n < 0 { |
| 1218 | return 0, wire.ParseError(n) |
| 1219 | } |
| 1220 | for len(b) > 0 { |
| 1221 | v, n := wire.ConsumeVarint(b) |
| 1222 | if n < 0 { |
| 1223 | return 0, wire.ParseError(n) |
| 1224 | } |
| 1225 | s = append(s, uint32(v)) |
| 1226 | b = b[n:] |
| 1227 | } |
| 1228 | *sp = s |
| 1229 | return n, nil |
| 1230 | } |
| 1231 | if wtyp != wire.VarintType { |
| 1232 | return 0, errUnknown |
| 1233 | } |
| 1234 | v, n := wire.ConsumeVarint(b) |
| 1235 | if n < 0 { |
| 1236 | return 0, wire.ParseError(n) |
| 1237 | } |
| 1238 | *sp = append(*sp, uint32(v)) |
| 1239 | return n, nil |
| 1240 | } |
| 1241 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1242 | var coderUint32Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1243 | size: sizeUint32Slice, |
| 1244 | marshal: appendUint32Slice, |
| 1245 | unmarshal: consumeUint32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | // sizeUint32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Uint32. |
| 1249 | func sizeUint32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1250 | s := *p.Uint32Slice() |
| 1251 | if len(s) == 0 { |
| 1252 | return 0 |
| 1253 | } |
| 1254 | n := 0 |
| 1255 | for _, v := range s { |
| 1256 | n += wire.SizeVarint(uint64(v)) |
| 1257 | } |
| 1258 | return tagsize + wire.SizeBytes(n) |
| 1259 | } |
| 1260 | |
| 1261 | // appendUint32PackedSlice encodes a []uint32 pointer as a packed repeated Uint32. |
| 1262 | func appendUint32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1263 | s := *p.Uint32Slice() |
| 1264 | if len(s) == 0 { |
| 1265 | return b, nil |
| 1266 | } |
| 1267 | b = wire.AppendVarint(b, wiretag) |
| 1268 | n := 0 |
| 1269 | for _, v := range s { |
| 1270 | n += wire.SizeVarint(uint64(v)) |
| 1271 | } |
| 1272 | b = wire.AppendVarint(b, uint64(n)) |
| 1273 | for _, v := range s { |
| 1274 | b = wire.AppendVarint(b, uint64(v)) |
| 1275 | } |
| 1276 | return b, nil |
| 1277 | } |
| 1278 | |
| 1279 | var coderUint32PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1280 | size: sizeUint32PackedSlice, |
| 1281 | marshal: appendUint32PackedSlice, |
| 1282 | unmarshal: consumeUint32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1285 | // sizeUint32Value returns the size of wire encoding a uint32 value as a Uint32. |
| 1286 | func sizeUint32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
| 1287 | return tagsize + wire.SizeVarint(uint64(uint32(v.Uint()))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1290 | // appendUint32Value encodes a uint32 value as a Uint32. |
| 1291 | func appendUint32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1292 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1293 | b = wire.AppendVarint(b, uint64(uint32(v.Uint()))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1294 | return b, nil |
| 1295 | } |
| 1296 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1297 | // consumeUint32Value decodes a uint32 value as a Uint32. |
| 1298 | func consumeUint32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1299 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1300 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1301 | } |
| 1302 | v, n := wire.ConsumeVarint(b) |
| 1303 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1304 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1305 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1306 | return protoreflect.ValueOfUint32(uint32(v)), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1309 | var coderUint32Value = valueCoderFuncs{ |
| 1310 | size: sizeUint32Value, |
| 1311 | marshal: appendUint32Value, |
| 1312 | unmarshal: consumeUint32Value, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1315 | // sizeUint32SliceValue returns the size of wire encoding a []uint32 value as a repeated Uint32. |
| 1316 | func sizeUint32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 1317 | list := listv.List() |
| 1318 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1319 | v := list.Get(i) |
| 1320 | size += tagsize + wire.SizeVarint(uint64(uint32(v.Uint()))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1321 | } |
| 1322 | return size |
| 1323 | } |
| 1324 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1325 | // appendUint32SliceValue encodes a []uint32 value as a repeated Uint32. |
| 1326 | func appendUint32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1327 | list := listv.List() |
| 1328 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1329 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1330 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1331 | b = wire.AppendVarint(b, uint64(uint32(v.Uint()))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1332 | } |
| 1333 | return b, nil |
| 1334 | } |
| 1335 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1336 | // consumeUint32SliceValue wire decodes a []uint32 value as a repeated Uint32. |
| 1337 | func consumeUint32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 1338 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1339 | if wtyp == wire.BytesType { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1340 | b, n = wire.ConsumeBytes(b) |
| 1341 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1342 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1343 | } |
| 1344 | for len(b) > 0 { |
| 1345 | v, n := wire.ConsumeVarint(b) |
| 1346 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1347 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1348 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1349 | list.Append(protoreflect.ValueOfUint32(uint32(v))) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1350 | b = b[n:] |
| 1351 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1352 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1353 | } |
| 1354 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1355 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1356 | } |
| 1357 | v, n := wire.ConsumeVarint(b) |
| 1358 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1359 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1360 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1361 | list.Append(protoreflect.ValueOfUint32(uint32(v))) |
| 1362 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1365 | var coderUint32SliceValue = valueCoderFuncs{ |
| 1366 | size: sizeUint32SliceValue, |
| 1367 | marshal: appendUint32SliceValue, |
| 1368 | unmarshal: consumeUint32SliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1369 | } |
| 1370 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1371 | // sizeUint32PackedSliceValue returns the size of wire encoding a []uint32 value as a packed repeated Uint32. |
| 1372 | func sizeUint32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 1373 | list := listv.List() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1374 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1375 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1376 | v := list.Get(i) |
| 1377 | n += wire.SizeVarint(uint64(uint32(v.Uint()))) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1378 | } |
| 1379 | return tagsize + wire.SizeBytes(n) |
| 1380 | } |
| 1381 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1382 | // appendUint32PackedSliceValue encodes a []uint32 value as a packed repeated Uint32. |
| 1383 | func appendUint32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1384 | list := listv.List() |
| 1385 | llen := list.Len() |
| 1386 | if llen == 0 { |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1387 | return b, nil |
| 1388 | } |
| 1389 | b = wire.AppendVarint(b, wiretag) |
| 1390 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1391 | for i := 0; i < llen; i++ { |
| 1392 | v := list.Get(i) |
| 1393 | n += wire.SizeVarint(uint64(uint32(v.Uint()))) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1394 | } |
| 1395 | b = wire.AppendVarint(b, uint64(n)) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1396 | for i := 0; i < llen; i++ { |
| 1397 | v := list.Get(i) |
| 1398 | b = wire.AppendVarint(b, uint64(uint32(v.Uint()))) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1399 | } |
| 1400 | return b, nil |
| 1401 | } |
| 1402 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1403 | var coderUint32PackedSliceValue = valueCoderFuncs{ |
| 1404 | size: sizeUint32PackedSliceValue, |
| 1405 | marshal: appendUint32PackedSliceValue, |
| 1406 | unmarshal: consumeUint32SliceValue, |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1409 | // sizeInt64 returns the size of wire encoding a int64 pointer as a Int64. |
| 1410 | func sizeInt64(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1411 | v := *p.Int64() |
| 1412 | return tagsize + wire.SizeVarint(uint64(v)) |
| 1413 | } |
| 1414 | |
| 1415 | // appendInt64 wire encodes a int64 pointer as a Int64. |
| 1416 | func appendInt64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1417 | v := *p.Int64() |
| 1418 | b = wire.AppendVarint(b, wiretag) |
| 1419 | b = wire.AppendVarint(b, uint64(v)) |
| 1420 | return b, nil |
| 1421 | } |
| 1422 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1423 | // consumeInt64 wire decodes a int64 pointer as a Int64. |
| 1424 | func consumeInt64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1425 | if wtyp != wire.VarintType { |
| 1426 | return 0, errUnknown |
| 1427 | } |
| 1428 | v, n := wire.ConsumeVarint(b) |
| 1429 | if n < 0 { |
| 1430 | return 0, wire.ParseError(n) |
| 1431 | } |
| 1432 | *p.Int64() = int64(v) |
| 1433 | return n, nil |
| 1434 | } |
| 1435 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1436 | var coderInt64 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1437 | size: sizeInt64, |
| 1438 | marshal: appendInt64, |
| 1439 | unmarshal: consumeInt64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 1442 | // sizeInt64NoZero returns the size of wire encoding a int64 pointer as a Int64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1443 | // The zero value is not encoded. |
| 1444 | func sizeInt64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1445 | v := *p.Int64() |
| 1446 | if v == 0 { |
| 1447 | return 0 |
| 1448 | } |
| 1449 | return tagsize + wire.SizeVarint(uint64(v)) |
| 1450 | } |
| 1451 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 1452 | // appendInt64NoZero wire encodes a int64 pointer as a Int64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1453 | // The zero value is not encoded. |
| 1454 | func appendInt64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1455 | v := *p.Int64() |
| 1456 | if v == 0 { |
| 1457 | return b, nil |
| 1458 | } |
| 1459 | b = wire.AppendVarint(b, wiretag) |
| 1460 | b = wire.AppendVarint(b, uint64(v)) |
| 1461 | return b, nil |
| 1462 | } |
| 1463 | |
| 1464 | var coderInt64NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1465 | size: sizeInt64NoZero, |
| 1466 | marshal: appendInt64NoZero, |
| 1467 | unmarshal: consumeInt64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | // sizeInt64Ptr returns the size of wire encoding a *int64 pointer as a Int64. |
| 1471 | // It panics if the pointer is nil. |
| 1472 | func sizeInt64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1473 | v := **p.Int64Ptr() |
| 1474 | return tagsize + wire.SizeVarint(uint64(v)) |
| 1475 | } |
| 1476 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1477 | // appendInt64Ptr wire encodes a *int64 pointer as a Int64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1478 | // It panics if the pointer is nil. |
| 1479 | func appendInt64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1480 | v := **p.Int64Ptr() |
| 1481 | b = wire.AppendVarint(b, wiretag) |
| 1482 | b = wire.AppendVarint(b, uint64(v)) |
| 1483 | return b, nil |
| 1484 | } |
| 1485 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1486 | // consumeInt64Ptr wire decodes a *int64 pointer as a Int64. |
| 1487 | func consumeInt64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1488 | if wtyp != wire.VarintType { |
| 1489 | return 0, errUnknown |
| 1490 | } |
| 1491 | v, n := wire.ConsumeVarint(b) |
| 1492 | if n < 0 { |
| 1493 | return 0, wire.ParseError(n) |
| 1494 | } |
| 1495 | vp := p.Int64Ptr() |
| 1496 | if *vp == nil { |
| 1497 | *vp = new(int64) |
| 1498 | } |
| 1499 | **vp = int64(v) |
| 1500 | return n, nil |
| 1501 | } |
| 1502 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1503 | var coderInt64Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1504 | size: sizeInt64Ptr, |
| 1505 | marshal: appendInt64Ptr, |
| 1506 | unmarshal: consumeInt64Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | // sizeInt64Slice returns the size of wire encoding a []int64 pointer as a repeated Int64. |
| 1510 | func sizeInt64Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1511 | s := *p.Int64Slice() |
| 1512 | for _, v := range s { |
| 1513 | size += tagsize + wire.SizeVarint(uint64(v)) |
| 1514 | } |
| 1515 | return size |
| 1516 | } |
| 1517 | |
| 1518 | // appendInt64Slice encodes a []int64 pointer as a repeated Int64. |
| 1519 | func appendInt64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1520 | s := *p.Int64Slice() |
| 1521 | for _, v := range s { |
| 1522 | b = wire.AppendVarint(b, wiretag) |
| 1523 | b = wire.AppendVarint(b, uint64(v)) |
| 1524 | } |
| 1525 | return b, nil |
| 1526 | } |
| 1527 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1528 | // consumeInt64Slice wire decodes a []int64 pointer as a repeated Int64. |
| 1529 | func consumeInt64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1530 | sp := p.Int64Slice() |
| 1531 | if wtyp == wire.BytesType { |
| 1532 | s := *sp |
| 1533 | b, n = wire.ConsumeBytes(b) |
| 1534 | if n < 0 { |
| 1535 | return 0, wire.ParseError(n) |
| 1536 | } |
| 1537 | for len(b) > 0 { |
| 1538 | v, n := wire.ConsumeVarint(b) |
| 1539 | if n < 0 { |
| 1540 | return 0, wire.ParseError(n) |
| 1541 | } |
| 1542 | s = append(s, int64(v)) |
| 1543 | b = b[n:] |
| 1544 | } |
| 1545 | *sp = s |
| 1546 | return n, nil |
| 1547 | } |
| 1548 | if wtyp != wire.VarintType { |
| 1549 | return 0, errUnknown |
| 1550 | } |
| 1551 | v, n := wire.ConsumeVarint(b) |
| 1552 | if n < 0 { |
| 1553 | return 0, wire.ParseError(n) |
| 1554 | } |
| 1555 | *sp = append(*sp, int64(v)) |
| 1556 | return n, nil |
| 1557 | } |
| 1558 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1559 | var coderInt64Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1560 | size: sizeInt64Slice, |
| 1561 | marshal: appendInt64Slice, |
| 1562 | unmarshal: consumeInt64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | // sizeInt64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Int64. |
| 1566 | func sizeInt64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1567 | s := *p.Int64Slice() |
| 1568 | if len(s) == 0 { |
| 1569 | return 0 |
| 1570 | } |
| 1571 | n := 0 |
| 1572 | for _, v := range s { |
| 1573 | n += wire.SizeVarint(uint64(v)) |
| 1574 | } |
| 1575 | return tagsize + wire.SizeBytes(n) |
| 1576 | } |
| 1577 | |
| 1578 | // appendInt64PackedSlice encodes a []int64 pointer as a packed repeated Int64. |
| 1579 | func appendInt64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1580 | s := *p.Int64Slice() |
| 1581 | if len(s) == 0 { |
| 1582 | return b, nil |
| 1583 | } |
| 1584 | b = wire.AppendVarint(b, wiretag) |
| 1585 | n := 0 |
| 1586 | for _, v := range s { |
| 1587 | n += wire.SizeVarint(uint64(v)) |
| 1588 | } |
| 1589 | b = wire.AppendVarint(b, uint64(n)) |
| 1590 | for _, v := range s { |
| 1591 | b = wire.AppendVarint(b, uint64(v)) |
| 1592 | } |
| 1593 | return b, nil |
| 1594 | } |
| 1595 | |
| 1596 | var coderInt64PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1597 | size: sizeInt64PackedSlice, |
| 1598 | marshal: appendInt64PackedSlice, |
| 1599 | unmarshal: consumeInt64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1602 | // sizeInt64Value returns the size of wire encoding a int64 value as a Int64. |
| 1603 | func sizeInt64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
| 1604 | return tagsize + wire.SizeVarint(uint64(v.Int())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1605 | } |
| 1606 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1607 | // appendInt64Value encodes a int64 value as a Int64. |
| 1608 | func appendInt64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1609 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1610 | b = wire.AppendVarint(b, uint64(v.Int())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1611 | return b, nil |
| 1612 | } |
| 1613 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1614 | // consumeInt64Value decodes a int64 value as a Int64. |
| 1615 | func consumeInt64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1616 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1617 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1618 | } |
| 1619 | v, n := wire.ConsumeVarint(b) |
| 1620 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1621 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1622 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1623 | return protoreflect.ValueOfInt64(int64(v)), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1626 | var coderInt64Value = valueCoderFuncs{ |
| 1627 | size: sizeInt64Value, |
| 1628 | marshal: appendInt64Value, |
| 1629 | unmarshal: consumeInt64Value, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1630 | } |
| 1631 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1632 | // sizeInt64SliceValue returns the size of wire encoding a []int64 value as a repeated Int64. |
| 1633 | func sizeInt64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 1634 | list := listv.List() |
| 1635 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1636 | v := list.Get(i) |
| 1637 | size += tagsize + wire.SizeVarint(uint64(v.Int())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1638 | } |
| 1639 | return size |
| 1640 | } |
| 1641 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1642 | // appendInt64SliceValue encodes a []int64 value as a repeated Int64. |
| 1643 | func appendInt64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1644 | list := listv.List() |
| 1645 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1646 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1647 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1648 | b = wire.AppendVarint(b, uint64(v.Int())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1649 | } |
| 1650 | return b, nil |
| 1651 | } |
| 1652 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1653 | // consumeInt64SliceValue wire decodes a []int64 value as a repeated Int64. |
| 1654 | func consumeInt64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 1655 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1656 | if wtyp == wire.BytesType { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1657 | b, n = wire.ConsumeBytes(b) |
| 1658 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1659 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1660 | } |
| 1661 | for len(b) > 0 { |
| 1662 | v, n := wire.ConsumeVarint(b) |
| 1663 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1664 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1665 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1666 | list.Append(protoreflect.ValueOfInt64(int64(v))) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1667 | b = b[n:] |
| 1668 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1669 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1670 | } |
| 1671 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1672 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1673 | } |
| 1674 | v, n := wire.ConsumeVarint(b) |
| 1675 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1676 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1677 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1678 | list.Append(protoreflect.ValueOfInt64(int64(v))) |
| 1679 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1680 | } |
| 1681 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1682 | var coderInt64SliceValue = valueCoderFuncs{ |
| 1683 | size: sizeInt64SliceValue, |
| 1684 | marshal: appendInt64SliceValue, |
| 1685 | unmarshal: consumeInt64SliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1686 | } |
| 1687 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1688 | // sizeInt64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Int64. |
| 1689 | func sizeInt64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 1690 | list := listv.List() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1691 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1692 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1693 | v := list.Get(i) |
| 1694 | n += wire.SizeVarint(uint64(v.Int())) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1695 | } |
| 1696 | return tagsize + wire.SizeBytes(n) |
| 1697 | } |
| 1698 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1699 | // appendInt64PackedSliceValue encodes a []int64 value as a packed repeated Int64. |
| 1700 | func appendInt64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1701 | list := listv.List() |
| 1702 | llen := list.Len() |
| 1703 | if llen == 0 { |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1704 | return b, nil |
| 1705 | } |
| 1706 | b = wire.AppendVarint(b, wiretag) |
| 1707 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1708 | for i := 0; i < llen; i++ { |
| 1709 | v := list.Get(i) |
| 1710 | n += wire.SizeVarint(uint64(v.Int())) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1711 | } |
| 1712 | b = wire.AppendVarint(b, uint64(n)) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1713 | for i := 0; i < llen; i++ { |
| 1714 | v := list.Get(i) |
| 1715 | b = wire.AppendVarint(b, uint64(v.Int())) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1716 | } |
| 1717 | return b, nil |
| 1718 | } |
| 1719 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1720 | var coderInt64PackedSliceValue = valueCoderFuncs{ |
| 1721 | size: sizeInt64PackedSliceValue, |
| 1722 | marshal: appendInt64PackedSliceValue, |
| 1723 | unmarshal: consumeInt64SliceValue, |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1726 | // sizeSint64 returns the size of wire encoding a int64 pointer as a Sint64. |
| 1727 | func sizeSint64(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1728 | v := *p.Int64() |
| 1729 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1730 | } |
| 1731 | |
| 1732 | // appendSint64 wire encodes a int64 pointer as a Sint64. |
| 1733 | func appendSint64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1734 | v := *p.Int64() |
| 1735 | b = wire.AppendVarint(b, wiretag) |
| 1736 | b = wire.AppendVarint(b, wire.EncodeZigZag(v)) |
| 1737 | return b, nil |
| 1738 | } |
| 1739 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1740 | // consumeSint64 wire decodes a int64 pointer as a Sint64. |
| 1741 | func consumeSint64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1742 | if wtyp != wire.VarintType { |
| 1743 | return 0, errUnknown |
| 1744 | } |
| 1745 | v, n := wire.ConsumeVarint(b) |
| 1746 | if n < 0 { |
| 1747 | return 0, wire.ParseError(n) |
| 1748 | } |
| 1749 | *p.Int64() = wire.DecodeZigZag(v) |
| 1750 | return n, nil |
| 1751 | } |
| 1752 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1753 | var coderSint64 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1754 | size: sizeSint64, |
| 1755 | marshal: appendSint64, |
| 1756 | unmarshal: consumeSint64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1757 | } |
| 1758 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 1759 | // sizeSint64NoZero returns the size of wire encoding a int64 pointer as a Sint64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1760 | // The zero value is not encoded. |
| 1761 | func sizeSint64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1762 | v := *p.Int64() |
| 1763 | if v == 0 { |
| 1764 | return 0 |
| 1765 | } |
| 1766 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1767 | } |
| 1768 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 1769 | // appendSint64NoZero wire encodes a int64 pointer as a Sint64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1770 | // The zero value is not encoded. |
| 1771 | func appendSint64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1772 | v := *p.Int64() |
| 1773 | if v == 0 { |
| 1774 | return b, nil |
| 1775 | } |
| 1776 | b = wire.AppendVarint(b, wiretag) |
| 1777 | b = wire.AppendVarint(b, wire.EncodeZigZag(v)) |
| 1778 | return b, nil |
| 1779 | } |
| 1780 | |
| 1781 | var coderSint64NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1782 | size: sizeSint64NoZero, |
| 1783 | marshal: appendSint64NoZero, |
| 1784 | unmarshal: consumeSint64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | // sizeSint64Ptr returns the size of wire encoding a *int64 pointer as a Sint64. |
| 1788 | // It panics if the pointer is nil. |
| 1789 | func sizeSint64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1790 | v := **p.Int64Ptr() |
| 1791 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1792 | } |
| 1793 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1794 | // appendSint64Ptr wire encodes a *int64 pointer as a Sint64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1795 | // It panics if the pointer is nil. |
| 1796 | func appendSint64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1797 | v := **p.Int64Ptr() |
| 1798 | b = wire.AppendVarint(b, wiretag) |
| 1799 | b = wire.AppendVarint(b, wire.EncodeZigZag(v)) |
| 1800 | return b, nil |
| 1801 | } |
| 1802 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1803 | // consumeSint64Ptr wire decodes a *int64 pointer as a Sint64. |
| 1804 | func consumeSint64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1805 | if wtyp != wire.VarintType { |
| 1806 | return 0, errUnknown |
| 1807 | } |
| 1808 | v, n := wire.ConsumeVarint(b) |
| 1809 | if n < 0 { |
| 1810 | return 0, wire.ParseError(n) |
| 1811 | } |
| 1812 | vp := p.Int64Ptr() |
| 1813 | if *vp == nil { |
| 1814 | *vp = new(int64) |
| 1815 | } |
| 1816 | **vp = wire.DecodeZigZag(v) |
| 1817 | return n, nil |
| 1818 | } |
| 1819 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1820 | var coderSint64Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1821 | size: sizeSint64Ptr, |
| 1822 | marshal: appendSint64Ptr, |
| 1823 | unmarshal: consumeSint64Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | // sizeSint64Slice returns the size of wire encoding a []int64 pointer as a repeated Sint64. |
| 1827 | func sizeSint64Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1828 | s := *p.Int64Slice() |
| 1829 | for _, v := range s { |
| 1830 | size += tagsize + wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1831 | } |
| 1832 | return size |
| 1833 | } |
| 1834 | |
| 1835 | // appendSint64Slice encodes a []int64 pointer as a repeated Sint64. |
| 1836 | func appendSint64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1837 | s := *p.Int64Slice() |
| 1838 | for _, v := range s { |
| 1839 | b = wire.AppendVarint(b, wiretag) |
| 1840 | b = wire.AppendVarint(b, wire.EncodeZigZag(v)) |
| 1841 | } |
| 1842 | return b, nil |
| 1843 | } |
| 1844 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1845 | // consumeSint64Slice wire decodes a []int64 pointer as a repeated Sint64. |
| 1846 | func consumeSint64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 1847 | sp := p.Int64Slice() |
| 1848 | if wtyp == wire.BytesType { |
| 1849 | s := *sp |
| 1850 | b, n = wire.ConsumeBytes(b) |
| 1851 | if n < 0 { |
| 1852 | return 0, wire.ParseError(n) |
| 1853 | } |
| 1854 | for len(b) > 0 { |
| 1855 | v, n := wire.ConsumeVarint(b) |
| 1856 | if n < 0 { |
| 1857 | return 0, wire.ParseError(n) |
| 1858 | } |
| 1859 | s = append(s, wire.DecodeZigZag(v)) |
| 1860 | b = b[n:] |
| 1861 | } |
| 1862 | *sp = s |
| 1863 | return n, nil |
| 1864 | } |
| 1865 | if wtyp != wire.VarintType { |
| 1866 | return 0, errUnknown |
| 1867 | } |
| 1868 | v, n := wire.ConsumeVarint(b) |
| 1869 | if n < 0 { |
| 1870 | return 0, wire.ParseError(n) |
| 1871 | } |
| 1872 | *sp = append(*sp, wire.DecodeZigZag(v)) |
| 1873 | return n, nil |
| 1874 | } |
| 1875 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1876 | var coderSint64Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1877 | size: sizeSint64Slice, |
| 1878 | marshal: appendSint64Slice, |
| 1879 | unmarshal: consumeSint64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | // sizeSint64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sint64. |
| 1883 | func sizeSint64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 1884 | s := *p.Int64Slice() |
| 1885 | if len(s) == 0 { |
| 1886 | return 0 |
| 1887 | } |
| 1888 | n := 0 |
| 1889 | for _, v := range s { |
| 1890 | n += wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1891 | } |
| 1892 | return tagsize + wire.SizeBytes(n) |
| 1893 | } |
| 1894 | |
| 1895 | // appendSint64PackedSlice encodes a []int64 pointer as a packed repeated Sint64. |
| 1896 | func appendSint64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1897 | s := *p.Int64Slice() |
| 1898 | if len(s) == 0 { |
| 1899 | return b, nil |
| 1900 | } |
| 1901 | b = wire.AppendVarint(b, wiretag) |
| 1902 | n := 0 |
| 1903 | for _, v := range s { |
| 1904 | n += wire.SizeVarint(wire.EncodeZigZag(v)) |
| 1905 | } |
| 1906 | b = wire.AppendVarint(b, uint64(n)) |
| 1907 | for _, v := range s { |
| 1908 | b = wire.AppendVarint(b, wire.EncodeZigZag(v)) |
| 1909 | } |
| 1910 | return b, nil |
| 1911 | } |
| 1912 | |
| 1913 | var coderSint64PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1914 | size: sizeSint64PackedSlice, |
| 1915 | marshal: appendSint64PackedSlice, |
| 1916 | unmarshal: consumeSint64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1917 | } |
| 1918 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1919 | // sizeSint64Value returns the size of wire encoding a int64 value as a Sint64. |
| 1920 | func sizeSint64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
| 1921 | return tagsize + wire.SizeVarint(wire.EncodeZigZag(v.Int())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1924 | // appendSint64Value encodes a int64 value as a Sint64. |
| 1925 | func appendSint64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1926 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1927 | b = wire.AppendVarint(b, wire.EncodeZigZag(v.Int())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1928 | return b, nil |
| 1929 | } |
| 1930 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1931 | // consumeSint64Value decodes a int64 value as a Sint64. |
| 1932 | func consumeSint64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1933 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1934 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1935 | } |
| 1936 | v, n := wire.ConsumeVarint(b) |
| 1937 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1938 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1939 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1940 | return protoreflect.ValueOfInt64(wire.DecodeZigZag(v)), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1941 | } |
| 1942 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1943 | var coderSint64Value = valueCoderFuncs{ |
| 1944 | size: sizeSint64Value, |
| 1945 | marshal: appendSint64Value, |
| 1946 | unmarshal: consumeSint64Value, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1949 | // sizeSint64SliceValue returns the size of wire encoding a []int64 value as a repeated Sint64. |
| 1950 | func sizeSint64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 1951 | list := listv.List() |
| 1952 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1953 | v := list.Get(i) |
| 1954 | size += tagsize + wire.SizeVarint(wire.EncodeZigZag(v.Int())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1955 | } |
| 1956 | return size |
| 1957 | } |
| 1958 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1959 | // appendSint64SliceValue encodes a []int64 value as a repeated Sint64. |
| 1960 | func appendSint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 1961 | list := listv.List() |
| 1962 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 1963 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1964 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1965 | b = wire.AppendVarint(b, wire.EncodeZigZag(v.Int())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 1966 | } |
| 1967 | return b, nil |
| 1968 | } |
| 1969 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1970 | // consumeSint64SliceValue wire decodes a []int64 value as a repeated Sint64. |
| 1971 | func consumeSint64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 1972 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1973 | if wtyp == wire.BytesType { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1974 | b, n = wire.ConsumeBytes(b) |
| 1975 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1976 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1977 | } |
| 1978 | for len(b) > 0 { |
| 1979 | v, n := wire.ConsumeVarint(b) |
| 1980 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1981 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1982 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1983 | list.Append(protoreflect.ValueOfInt64(wire.DecodeZigZag(v))) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1984 | b = b[n:] |
| 1985 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1986 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1987 | } |
| 1988 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1989 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1990 | } |
| 1991 | v, n := wire.ConsumeVarint(b) |
| 1992 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1993 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1994 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1995 | list.Append(protoreflect.ValueOfInt64(wire.DecodeZigZag(v))) |
| 1996 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 1999 | var coderSint64SliceValue = valueCoderFuncs{ |
| 2000 | size: sizeSint64SliceValue, |
| 2001 | marshal: appendSint64SliceValue, |
| 2002 | unmarshal: consumeSint64SliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2005 | // sizeSint64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Sint64. |
| 2006 | func sizeSint64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 2007 | list := listv.List() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2008 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2009 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 2010 | v := list.Get(i) |
| 2011 | n += wire.SizeVarint(wire.EncodeZigZag(v.Int())) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2012 | } |
| 2013 | return tagsize + wire.SizeBytes(n) |
| 2014 | } |
| 2015 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2016 | // appendSint64PackedSliceValue encodes a []int64 value as a packed repeated Sint64. |
| 2017 | func appendSint64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2018 | list := listv.List() |
| 2019 | llen := list.Len() |
| 2020 | if llen == 0 { |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2021 | return b, nil |
| 2022 | } |
| 2023 | b = wire.AppendVarint(b, wiretag) |
| 2024 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2025 | for i := 0; i < llen; i++ { |
| 2026 | v := list.Get(i) |
| 2027 | n += wire.SizeVarint(wire.EncodeZigZag(v.Int())) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2028 | } |
| 2029 | b = wire.AppendVarint(b, uint64(n)) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2030 | for i := 0; i < llen; i++ { |
| 2031 | v := list.Get(i) |
| 2032 | b = wire.AppendVarint(b, wire.EncodeZigZag(v.Int())) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2033 | } |
| 2034 | return b, nil |
| 2035 | } |
| 2036 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2037 | var coderSint64PackedSliceValue = valueCoderFuncs{ |
| 2038 | size: sizeSint64PackedSliceValue, |
| 2039 | marshal: appendSint64PackedSliceValue, |
| 2040 | unmarshal: consumeSint64SliceValue, |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2041 | } |
| 2042 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2043 | // sizeUint64 returns the size of wire encoding a uint64 pointer as a Uint64. |
| 2044 | func sizeUint64(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2045 | v := *p.Uint64() |
| 2046 | return tagsize + wire.SizeVarint(v) |
| 2047 | } |
| 2048 | |
| 2049 | // appendUint64 wire encodes a uint64 pointer as a Uint64. |
| 2050 | func appendUint64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2051 | v := *p.Uint64() |
| 2052 | b = wire.AppendVarint(b, wiretag) |
| 2053 | b = wire.AppendVarint(b, v) |
| 2054 | return b, nil |
| 2055 | } |
| 2056 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2057 | // consumeUint64 wire decodes a uint64 pointer as a Uint64. |
| 2058 | func consumeUint64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2059 | if wtyp != wire.VarintType { |
| 2060 | return 0, errUnknown |
| 2061 | } |
| 2062 | v, n := wire.ConsumeVarint(b) |
| 2063 | if n < 0 { |
| 2064 | return 0, wire.ParseError(n) |
| 2065 | } |
| 2066 | *p.Uint64() = v |
| 2067 | return n, nil |
| 2068 | } |
| 2069 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2070 | var coderUint64 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2071 | size: sizeUint64, |
| 2072 | marshal: appendUint64, |
| 2073 | unmarshal: consumeUint64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2074 | } |
| 2075 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 2076 | // sizeUint64NoZero returns the size of wire encoding a uint64 pointer as a Uint64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2077 | // The zero value is not encoded. |
| 2078 | func sizeUint64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2079 | v := *p.Uint64() |
| 2080 | if v == 0 { |
| 2081 | return 0 |
| 2082 | } |
| 2083 | return tagsize + wire.SizeVarint(v) |
| 2084 | } |
| 2085 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 2086 | // appendUint64NoZero wire encodes a uint64 pointer as a Uint64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2087 | // The zero value is not encoded. |
| 2088 | func appendUint64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2089 | v := *p.Uint64() |
| 2090 | if v == 0 { |
| 2091 | return b, nil |
| 2092 | } |
| 2093 | b = wire.AppendVarint(b, wiretag) |
| 2094 | b = wire.AppendVarint(b, v) |
| 2095 | return b, nil |
| 2096 | } |
| 2097 | |
| 2098 | var coderUint64NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2099 | size: sizeUint64NoZero, |
| 2100 | marshal: appendUint64NoZero, |
| 2101 | unmarshal: consumeUint64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2102 | } |
| 2103 | |
| 2104 | // sizeUint64Ptr returns the size of wire encoding a *uint64 pointer as a Uint64. |
| 2105 | // It panics if the pointer is nil. |
| 2106 | func sizeUint64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2107 | v := **p.Uint64Ptr() |
| 2108 | return tagsize + wire.SizeVarint(v) |
| 2109 | } |
| 2110 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2111 | // appendUint64Ptr wire encodes a *uint64 pointer as a Uint64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2112 | // It panics if the pointer is nil. |
| 2113 | func appendUint64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2114 | v := **p.Uint64Ptr() |
| 2115 | b = wire.AppendVarint(b, wiretag) |
| 2116 | b = wire.AppendVarint(b, v) |
| 2117 | return b, nil |
| 2118 | } |
| 2119 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2120 | // consumeUint64Ptr wire decodes a *uint64 pointer as a Uint64. |
| 2121 | func consumeUint64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2122 | if wtyp != wire.VarintType { |
| 2123 | return 0, errUnknown |
| 2124 | } |
| 2125 | v, n := wire.ConsumeVarint(b) |
| 2126 | if n < 0 { |
| 2127 | return 0, wire.ParseError(n) |
| 2128 | } |
| 2129 | vp := p.Uint64Ptr() |
| 2130 | if *vp == nil { |
| 2131 | *vp = new(uint64) |
| 2132 | } |
| 2133 | **vp = v |
| 2134 | return n, nil |
| 2135 | } |
| 2136 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2137 | var coderUint64Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2138 | size: sizeUint64Ptr, |
| 2139 | marshal: appendUint64Ptr, |
| 2140 | unmarshal: consumeUint64Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | // sizeUint64Slice returns the size of wire encoding a []uint64 pointer as a repeated Uint64. |
| 2144 | func sizeUint64Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2145 | s := *p.Uint64Slice() |
| 2146 | for _, v := range s { |
| 2147 | size += tagsize + wire.SizeVarint(v) |
| 2148 | } |
| 2149 | return size |
| 2150 | } |
| 2151 | |
| 2152 | // appendUint64Slice encodes a []uint64 pointer as a repeated Uint64. |
| 2153 | func appendUint64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2154 | s := *p.Uint64Slice() |
| 2155 | for _, v := range s { |
| 2156 | b = wire.AppendVarint(b, wiretag) |
| 2157 | b = wire.AppendVarint(b, v) |
| 2158 | } |
| 2159 | return b, nil |
| 2160 | } |
| 2161 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2162 | // consumeUint64Slice wire decodes a []uint64 pointer as a repeated Uint64. |
| 2163 | func consumeUint64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2164 | sp := p.Uint64Slice() |
| 2165 | if wtyp == wire.BytesType { |
| 2166 | s := *sp |
| 2167 | b, n = wire.ConsumeBytes(b) |
| 2168 | if n < 0 { |
| 2169 | return 0, wire.ParseError(n) |
| 2170 | } |
| 2171 | for len(b) > 0 { |
| 2172 | v, n := wire.ConsumeVarint(b) |
| 2173 | if n < 0 { |
| 2174 | return 0, wire.ParseError(n) |
| 2175 | } |
| 2176 | s = append(s, v) |
| 2177 | b = b[n:] |
| 2178 | } |
| 2179 | *sp = s |
| 2180 | return n, nil |
| 2181 | } |
| 2182 | if wtyp != wire.VarintType { |
| 2183 | return 0, errUnknown |
| 2184 | } |
| 2185 | v, n := wire.ConsumeVarint(b) |
| 2186 | if n < 0 { |
| 2187 | return 0, wire.ParseError(n) |
| 2188 | } |
| 2189 | *sp = append(*sp, v) |
| 2190 | return n, nil |
| 2191 | } |
| 2192 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2193 | var coderUint64Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2194 | size: sizeUint64Slice, |
| 2195 | marshal: appendUint64Slice, |
| 2196 | unmarshal: consumeUint64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | // sizeUint64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Uint64. |
| 2200 | func sizeUint64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2201 | s := *p.Uint64Slice() |
| 2202 | if len(s) == 0 { |
| 2203 | return 0 |
| 2204 | } |
| 2205 | n := 0 |
| 2206 | for _, v := range s { |
| 2207 | n += wire.SizeVarint(v) |
| 2208 | } |
| 2209 | return tagsize + wire.SizeBytes(n) |
| 2210 | } |
| 2211 | |
| 2212 | // appendUint64PackedSlice encodes a []uint64 pointer as a packed repeated Uint64. |
| 2213 | func appendUint64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2214 | s := *p.Uint64Slice() |
| 2215 | if len(s) == 0 { |
| 2216 | return b, nil |
| 2217 | } |
| 2218 | b = wire.AppendVarint(b, wiretag) |
| 2219 | n := 0 |
| 2220 | for _, v := range s { |
| 2221 | n += wire.SizeVarint(v) |
| 2222 | } |
| 2223 | b = wire.AppendVarint(b, uint64(n)) |
| 2224 | for _, v := range s { |
| 2225 | b = wire.AppendVarint(b, v) |
| 2226 | } |
| 2227 | return b, nil |
| 2228 | } |
| 2229 | |
| 2230 | var coderUint64PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2231 | size: sizeUint64PackedSlice, |
| 2232 | marshal: appendUint64PackedSlice, |
| 2233 | unmarshal: consumeUint64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2236 | // sizeUint64Value returns the size of wire encoding a uint64 value as a Uint64. |
| 2237 | func sizeUint64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
| 2238 | return tagsize + wire.SizeVarint(v.Uint()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2239 | } |
| 2240 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2241 | // appendUint64Value encodes a uint64 value as a Uint64. |
| 2242 | func appendUint64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2243 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2244 | b = wire.AppendVarint(b, v.Uint()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2245 | return b, nil |
| 2246 | } |
| 2247 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2248 | // consumeUint64Value decodes a uint64 value as a Uint64. |
| 2249 | func consumeUint64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2250 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2251 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2252 | } |
| 2253 | v, n := wire.ConsumeVarint(b) |
| 2254 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2255 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2256 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2257 | return protoreflect.ValueOfUint64(v), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2258 | } |
| 2259 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2260 | var coderUint64Value = valueCoderFuncs{ |
| 2261 | size: sizeUint64Value, |
| 2262 | marshal: appendUint64Value, |
| 2263 | unmarshal: consumeUint64Value, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2264 | } |
| 2265 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2266 | // sizeUint64SliceValue returns the size of wire encoding a []uint64 value as a repeated Uint64. |
| 2267 | func sizeUint64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 2268 | list := listv.List() |
| 2269 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 2270 | v := list.Get(i) |
| 2271 | size += tagsize + wire.SizeVarint(v.Uint()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2272 | } |
| 2273 | return size |
| 2274 | } |
| 2275 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2276 | // appendUint64SliceValue encodes a []uint64 value as a repeated Uint64. |
| 2277 | func appendUint64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2278 | list := listv.List() |
| 2279 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 2280 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2281 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2282 | b = wire.AppendVarint(b, v.Uint()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2283 | } |
| 2284 | return b, nil |
| 2285 | } |
| 2286 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2287 | // consumeUint64SliceValue wire decodes a []uint64 value as a repeated Uint64. |
| 2288 | func consumeUint64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 2289 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2290 | if wtyp == wire.BytesType { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2291 | b, n = wire.ConsumeBytes(b) |
| 2292 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2293 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2294 | } |
| 2295 | for len(b) > 0 { |
| 2296 | v, n := wire.ConsumeVarint(b) |
| 2297 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2298 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2299 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2300 | list.Append(protoreflect.ValueOfUint64(v)) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2301 | b = b[n:] |
| 2302 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2303 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2304 | } |
| 2305 | if wtyp != wire.VarintType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2306 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2307 | } |
| 2308 | v, n := wire.ConsumeVarint(b) |
| 2309 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2310 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2311 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2312 | list.Append(protoreflect.ValueOfUint64(v)) |
| 2313 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2316 | var coderUint64SliceValue = valueCoderFuncs{ |
| 2317 | size: sizeUint64SliceValue, |
| 2318 | marshal: appendUint64SliceValue, |
| 2319 | unmarshal: consumeUint64SliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2320 | } |
| 2321 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2322 | // sizeUint64PackedSliceValue returns the size of wire encoding a []uint64 value as a packed repeated Uint64. |
| 2323 | func sizeUint64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 2324 | list := listv.List() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2325 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2326 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 2327 | v := list.Get(i) |
| 2328 | n += wire.SizeVarint(v.Uint()) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2329 | } |
| 2330 | return tagsize + wire.SizeBytes(n) |
| 2331 | } |
| 2332 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2333 | // appendUint64PackedSliceValue encodes a []uint64 value as a packed repeated Uint64. |
| 2334 | func appendUint64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2335 | list := listv.List() |
| 2336 | llen := list.Len() |
| 2337 | if llen == 0 { |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2338 | return b, nil |
| 2339 | } |
| 2340 | b = wire.AppendVarint(b, wiretag) |
| 2341 | n := 0 |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2342 | for i := 0; i < llen; i++ { |
| 2343 | v := list.Get(i) |
| 2344 | n += wire.SizeVarint(v.Uint()) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2345 | } |
| 2346 | b = wire.AppendVarint(b, uint64(n)) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2347 | for i := 0; i < llen; i++ { |
| 2348 | v := list.Get(i) |
| 2349 | b = wire.AppendVarint(b, v.Uint()) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2350 | } |
| 2351 | return b, nil |
| 2352 | } |
| 2353 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2354 | var coderUint64PackedSliceValue = valueCoderFuncs{ |
| 2355 | size: sizeUint64PackedSliceValue, |
| 2356 | marshal: appendUint64PackedSliceValue, |
| 2357 | unmarshal: consumeUint64SliceValue, |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2360 | // sizeSfixed32 returns the size of wire encoding a int32 pointer as a Sfixed32. |
| 2361 | func sizeSfixed32(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2362 | |
| 2363 | return tagsize + wire.SizeFixed32() |
| 2364 | } |
| 2365 | |
| 2366 | // appendSfixed32 wire encodes a int32 pointer as a Sfixed32. |
| 2367 | func appendSfixed32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2368 | v := *p.Int32() |
| 2369 | b = wire.AppendVarint(b, wiretag) |
| 2370 | b = wire.AppendFixed32(b, uint32(v)) |
| 2371 | return b, nil |
| 2372 | } |
| 2373 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2374 | // consumeSfixed32 wire decodes a int32 pointer as a Sfixed32. |
| 2375 | func consumeSfixed32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2376 | if wtyp != wire.Fixed32Type { |
| 2377 | return 0, errUnknown |
| 2378 | } |
| 2379 | v, n := wire.ConsumeFixed32(b) |
| 2380 | if n < 0 { |
| 2381 | return 0, wire.ParseError(n) |
| 2382 | } |
| 2383 | *p.Int32() = int32(v) |
| 2384 | return n, nil |
| 2385 | } |
| 2386 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2387 | var coderSfixed32 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2388 | size: sizeSfixed32, |
| 2389 | marshal: appendSfixed32, |
| 2390 | unmarshal: consumeSfixed32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2391 | } |
| 2392 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 2393 | // sizeSfixed32NoZero returns the size of wire encoding a int32 pointer as a Sfixed32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2394 | // The zero value is not encoded. |
| 2395 | func sizeSfixed32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2396 | v := *p.Int32() |
| 2397 | if v == 0 { |
| 2398 | return 0 |
| 2399 | } |
| 2400 | return tagsize + wire.SizeFixed32() |
| 2401 | } |
| 2402 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 2403 | // appendSfixed32NoZero wire encodes a int32 pointer as a Sfixed32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2404 | // The zero value is not encoded. |
| 2405 | func appendSfixed32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2406 | v := *p.Int32() |
| 2407 | if v == 0 { |
| 2408 | return b, nil |
| 2409 | } |
| 2410 | b = wire.AppendVarint(b, wiretag) |
| 2411 | b = wire.AppendFixed32(b, uint32(v)) |
| 2412 | return b, nil |
| 2413 | } |
| 2414 | |
| 2415 | var coderSfixed32NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2416 | size: sizeSfixed32NoZero, |
| 2417 | marshal: appendSfixed32NoZero, |
| 2418 | unmarshal: consumeSfixed32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2419 | } |
| 2420 | |
| 2421 | // sizeSfixed32Ptr returns the size of wire encoding a *int32 pointer as a Sfixed32. |
| 2422 | // It panics if the pointer is nil. |
| 2423 | func sizeSfixed32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2424 | return tagsize + wire.SizeFixed32() |
| 2425 | } |
| 2426 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2427 | // appendSfixed32Ptr wire encodes a *int32 pointer as a Sfixed32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2428 | // It panics if the pointer is nil. |
| 2429 | func appendSfixed32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2430 | v := **p.Int32Ptr() |
| 2431 | b = wire.AppendVarint(b, wiretag) |
| 2432 | b = wire.AppendFixed32(b, uint32(v)) |
| 2433 | return b, nil |
| 2434 | } |
| 2435 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2436 | // consumeSfixed32Ptr wire decodes a *int32 pointer as a Sfixed32. |
| 2437 | func consumeSfixed32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2438 | if wtyp != wire.Fixed32Type { |
| 2439 | return 0, errUnknown |
| 2440 | } |
| 2441 | v, n := wire.ConsumeFixed32(b) |
| 2442 | if n < 0 { |
| 2443 | return 0, wire.ParseError(n) |
| 2444 | } |
| 2445 | vp := p.Int32Ptr() |
| 2446 | if *vp == nil { |
| 2447 | *vp = new(int32) |
| 2448 | } |
| 2449 | **vp = int32(v) |
| 2450 | return n, nil |
| 2451 | } |
| 2452 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2453 | var coderSfixed32Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2454 | size: sizeSfixed32Ptr, |
| 2455 | marshal: appendSfixed32Ptr, |
| 2456 | unmarshal: consumeSfixed32Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | // sizeSfixed32Slice returns the size of wire encoding a []int32 pointer as a repeated Sfixed32. |
| 2460 | func sizeSfixed32Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2461 | s := *p.Int32Slice() |
| 2462 | size = len(s) * (tagsize + wire.SizeFixed32()) |
| 2463 | return size |
| 2464 | } |
| 2465 | |
| 2466 | // appendSfixed32Slice encodes a []int32 pointer as a repeated Sfixed32. |
| 2467 | func appendSfixed32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2468 | s := *p.Int32Slice() |
| 2469 | for _, v := range s { |
| 2470 | b = wire.AppendVarint(b, wiretag) |
| 2471 | b = wire.AppendFixed32(b, uint32(v)) |
| 2472 | } |
| 2473 | return b, nil |
| 2474 | } |
| 2475 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2476 | // consumeSfixed32Slice wire decodes a []int32 pointer as a repeated Sfixed32. |
| 2477 | func consumeSfixed32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2478 | sp := p.Int32Slice() |
| 2479 | if wtyp == wire.BytesType { |
| 2480 | s := *sp |
| 2481 | b, n = wire.ConsumeBytes(b) |
| 2482 | if n < 0 { |
| 2483 | return 0, wire.ParseError(n) |
| 2484 | } |
| 2485 | for len(b) > 0 { |
| 2486 | v, n := wire.ConsumeFixed32(b) |
| 2487 | if n < 0 { |
| 2488 | return 0, wire.ParseError(n) |
| 2489 | } |
| 2490 | s = append(s, int32(v)) |
| 2491 | b = b[n:] |
| 2492 | } |
| 2493 | *sp = s |
| 2494 | return n, nil |
| 2495 | } |
| 2496 | if wtyp != wire.Fixed32Type { |
| 2497 | return 0, errUnknown |
| 2498 | } |
| 2499 | v, n := wire.ConsumeFixed32(b) |
| 2500 | if n < 0 { |
| 2501 | return 0, wire.ParseError(n) |
| 2502 | } |
| 2503 | *sp = append(*sp, int32(v)) |
| 2504 | return n, nil |
| 2505 | } |
| 2506 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2507 | var coderSfixed32Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2508 | size: sizeSfixed32Slice, |
| 2509 | marshal: appendSfixed32Slice, |
| 2510 | unmarshal: consumeSfixed32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | // sizeSfixed32PackedSlice returns the size of wire encoding a []int32 pointer as a packed repeated Sfixed32. |
| 2514 | func sizeSfixed32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2515 | s := *p.Int32Slice() |
| 2516 | if len(s) == 0 { |
| 2517 | return 0 |
| 2518 | } |
| 2519 | n := len(s) * wire.SizeFixed32() |
| 2520 | return tagsize + wire.SizeBytes(n) |
| 2521 | } |
| 2522 | |
| 2523 | // appendSfixed32PackedSlice encodes a []int32 pointer as a packed repeated Sfixed32. |
| 2524 | func appendSfixed32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2525 | s := *p.Int32Slice() |
| 2526 | if len(s) == 0 { |
| 2527 | return b, nil |
| 2528 | } |
| 2529 | b = wire.AppendVarint(b, wiretag) |
| 2530 | n := len(s) * wire.SizeFixed32() |
| 2531 | b = wire.AppendVarint(b, uint64(n)) |
| 2532 | for _, v := range s { |
| 2533 | b = wire.AppendFixed32(b, uint32(v)) |
| 2534 | } |
| 2535 | return b, nil |
| 2536 | } |
| 2537 | |
| 2538 | var coderSfixed32PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2539 | size: sizeSfixed32PackedSlice, |
| 2540 | marshal: appendSfixed32PackedSlice, |
| 2541 | unmarshal: consumeSfixed32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2544 | // sizeSfixed32Value returns the size of wire encoding a int32 value as a Sfixed32. |
| 2545 | func sizeSfixed32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2546 | return tagsize + wire.SizeFixed32() |
| 2547 | } |
| 2548 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2549 | // appendSfixed32Value encodes a int32 value as a Sfixed32. |
| 2550 | func appendSfixed32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2551 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2552 | b = wire.AppendFixed32(b, uint32(v.Int())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2553 | return b, nil |
| 2554 | } |
| 2555 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2556 | // consumeSfixed32Value decodes a int32 value as a Sfixed32. |
| 2557 | func consumeSfixed32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2558 | if wtyp != wire.Fixed32Type { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2559 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2560 | } |
| 2561 | v, n := wire.ConsumeFixed32(b) |
| 2562 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2563 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2564 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2565 | return protoreflect.ValueOfInt32(int32(v)), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2566 | } |
| 2567 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2568 | var coderSfixed32Value = valueCoderFuncs{ |
| 2569 | size: sizeSfixed32Value, |
| 2570 | marshal: appendSfixed32Value, |
| 2571 | unmarshal: consumeSfixed32Value, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2574 | // sizeSfixed32SliceValue returns the size of wire encoding a []int32 value as a repeated Sfixed32. |
| 2575 | func sizeSfixed32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 2576 | list := listv.List() |
| 2577 | size = list.Len() * (tagsize + wire.SizeFixed32()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2578 | return size |
| 2579 | } |
| 2580 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2581 | // appendSfixed32SliceValue encodes a []int32 value as a repeated Sfixed32. |
| 2582 | func appendSfixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2583 | list := listv.List() |
| 2584 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 2585 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2586 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2587 | b = wire.AppendFixed32(b, uint32(v.Int())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2588 | } |
| 2589 | return b, nil |
| 2590 | } |
| 2591 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2592 | // consumeSfixed32SliceValue wire decodes a []int32 value as a repeated Sfixed32. |
| 2593 | func consumeSfixed32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 2594 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2595 | if wtyp == wire.BytesType { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2596 | b, n = wire.ConsumeBytes(b) |
| 2597 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2598 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2599 | } |
| 2600 | for len(b) > 0 { |
| 2601 | v, n := wire.ConsumeFixed32(b) |
| 2602 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2603 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2604 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2605 | list.Append(protoreflect.ValueOfInt32(int32(v))) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2606 | b = b[n:] |
| 2607 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2608 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2609 | } |
| 2610 | if wtyp != wire.Fixed32Type { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2611 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2612 | } |
| 2613 | v, n := wire.ConsumeFixed32(b) |
| 2614 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2615 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2616 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2617 | list.Append(protoreflect.ValueOfInt32(int32(v))) |
| 2618 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2619 | } |
| 2620 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2621 | var coderSfixed32SliceValue = valueCoderFuncs{ |
| 2622 | size: sizeSfixed32SliceValue, |
| 2623 | marshal: appendSfixed32SliceValue, |
| 2624 | unmarshal: consumeSfixed32SliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2627 | // sizeSfixed32PackedSliceValue returns the size of wire encoding a []int32 value as a packed repeated Sfixed32. |
| 2628 | func sizeSfixed32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 2629 | list := listv.List() |
| 2630 | n := list.Len() * wire.SizeFixed32() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2631 | return tagsize + wire.SizeBytes(n) |
| 2632 | } |
| 2633 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2634 | // appendSfixed32PackedSliceValue encodes a []int32 value as a packed repeated Sfixed32. |
| 2635 | func appendSfixed32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2636 | list := listv.List() |
| 2637 | llen := list.Len() |
| 2638 | if llen == 0 { |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2639 | return b, nil |
| 2640 | } |
| 2641 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2642 | n := llen * wire.SizeFixed32() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2643 | b = wire.AppendVarint(b, uint64(n)) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2644 | for i := 0; i < llen; i++ { |
| 2645 | v := list.Get(i) |
| 2646 | b = wire.AppendFixed32(b, uint32(v.Int())) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2647 | } |
| 2648 | return b, nil |
| 2649 | } |
| 2650 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2651 | var coderSfixed32PackedSliceValue = valueCoderFuncs{ |
| 2652 | size: sizeSfixed32PackedSliceValue, |
| 2653 | marshal: appendSfixed32PackedSliceValue, |
| 2654 | unmarshal: consumeSfixed32SliceValue, |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2657 | // sizeFixed32 returns the size of wire encoding a uint32 pointer as a Fixed32. |
| 2658 | func sizeFixed32(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2659 | |
| 2660 | return tagsize + wire.SizeFixed32() |
| 2661 | } |
| 2662 | |
| 2663 | // appendFixed32 wire encodes a uint32 pointer as a Fixed32. |
| 2664 | func appendFixed32(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2665 | v := *p.Uint32() |
| 2666 | b = wire.AppendVarint(b, wiretag) |
| 2667 | b = wire.AppendFixed32(b, v) |
| 2668 | return b, nil |
| 2669 | } |
| 2670 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2671 | // consumeFixed32 wire decodes a uint32 pointer as a Fixed32. |
| 2672 | func consumeFixed32(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2673 | if wtyp != wire.Fixed32Type { |
| 2674 | return 0, errUnknown |
| 2675 | } |
| 2676 | v, n := wire.ConsumeFixed32(b) |
| 2677 | if n < 0 { |
| 2678 | return 0, wire.ParseError(n) |
| 2679 | } |
| 2680 | *p.Uint32() = v |
| 2681 | return n, nil |
| 2682 | } |
| 2683 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2684 | var coderFixed32 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2685 | size: sizeFixed32, |
| 2686 | marshal: appendFixed32, |
| 2687 | unmarshal: consumeFixed32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2688 | } |
| 2689 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 2690 | // sizeFixed32NoZero returns the size of wire encoding a uint32 pointer as a Fixed32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2691 | // The zero value is not encoded. |
| 2692 | func sizeFixed32NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2693 | v := *p.Uint32() |
| 2694 | if v == 0 { |
| 2695 | return 0 |
| 2696 | } |
| 2697 | return tagsize + wire.SizeFixed32() |
| 2698 | } |
| 2699 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 2700 | // appendFixed32NoZero wire encodes a uint32 pointer as a Fixed32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2701 | // The zero value is not encoded. |
| 2702 | func appendFixed32NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2703 | v := *p.Uint32() |
| 2704 | if v == 0 { |
| 2705 | return b, nil |
| 2706 | } |
| 2707 | b = wire.AppendVarint(b, wiretag) |
| 2708 | b = wire.AppendFixed32(b, v) |
| 2709 | return b, nil |
| 2710 | } |
| 2711 | |
| 2712 | var coderFixed32NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2713 | size: sizeFixed32NoZero, |
| 2714 | marshal: appendFixed32NoZero, |
| 2715 | unmarshal: consumeFixed32, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | // sizeFixed32Ptr returns the size of wire encoding a *uint32 pointer as a Fixed32. |
| 2719 | // It panics if the pointer is nil. |
| 2720 | func sizeFixed32Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2721 | return tagsize + wire.SizeFixed32() |
| 2722 | } |
| 2723 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2724 | // appendFixed32Ptr wire encodes a *uint32 pointer as a Fixed32. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2725 | // It panics if the pointer is nil. |
| 2726 | func appendFixed32Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2727 | v := **p.Uint32Ptr() |
| 2728 | b = wire.AppendVarint(b, wiretag) |
| 2729 | b = wire.AppendFixed32(b, v) |
| 2730 | return b, nil |
| 2731 | } |
| 2732 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2733 | // consumeFixed32Ptr wire decodes a *uint32 pointer as a Fixed32. |
| 2734 | func consumeFixed32Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2735 | if wtyp != wire.Fixed32Type { |
| 2736 | return 0, errUnknown |
| 2737 | } |
| 2738 | v, n := wire.ConsumeFixed32(b) |
| 2739 | if n < 0 { |
| 2740 | return 0, wire.ParseError(n) |
| 2741 | } |
| 2742 | vp := p.Uint32Ptr() |
| 2743 | if *vp == nil { |
| 2744 | *vp = new(uint32) |
| 2745 | } |
| 2746 | **vp = v |
| 2747 | return n, nil |
| 2748 | } |
| 2749 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2750 | var coderFixed32Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2751 | size: sizeFixed32Ptr, |
| 2752 | marshal: appendFixed32Ptr, |
| 2753 | unmarshal: consumeFixed32Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | // sizeFixed32Slice returns the size of wire encoding a []uint32 pointer as a repeated Fixed32. |
| 2757 | func sizeFixed32Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2758 | s := *p.Uint32Slice() |
| 2759 | size = len(s) * (tagsize + wire.SizeFixed32()) |
| 2760 | return size |
| 2761 | } |
| 2762 | |
| 2763 | // appendFixed32Slice encodes a []uint32 pointer as a repeated Fixed32. |
| 2764 | func appendFixed32Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2765 | s := *p.Uint32Slice() |
| 2766 | for _, v := range s { |
| 2767 | b = wire.AppendVarint(b, wiretag) |
| 2768 | b = wire.AppendFixed32(b, v) |
| 2769 | } |
| 2770 | return b, nil |
| 2771 | } |
| 2772 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2773 | // consumeFixed32Slice wire decodes a []uint32 pointer as a repeated Fixed32. |
| 2774 | func consumeFixed32Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2775 | sp := p.Uint32Slice() |
| 2776 | if wtyp == wire.BytesType { |
| 2777 | s := *sp |
| 2778 | b, n = wire.ConsumeBytes(b) |
| 2779 | if n < 0 { |
| 2780 | return 0, wire.ParseError(n) |
| 2781 | } |
| 2782 | for len(b) > 0 { |
| 2783 | v, n := wire.ConsumeFixed32(b) |
| 2784 | if n < 0 { |
| 2785 | return 0, wire.ParseError(n) |
| 2786 | } |
| 2787 | s = append(s, v) |
| 2788 | b = b[n:] |
| 2789 | } |
| 2790 | *sp = s |
| 2791 | return n, nil |
| 2792 | } |
| 2793 | if wtyp != wire.Fixed32Type { |
| 2794 | return 0, errUnknown |
| 2795 | } |
| 2796 | v, n := wire.ConsumeFixed32(b) |
| 2797 | if n < 0 { |
| 2798 | return 0, wire.ParseError(n) |
| 2799 | } |
| 2800 | *sp = append(*sp, v) |
| 2801 | return n, nil |
| 2802 | } |
| 2803 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2804 | var coderFixed32Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2805 | size: sizeFixed32Slice, |
| 2806 | marshal: appendFixed32Slice, |
| 2807 | unmarshal: consumeFixed32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2808 | } |
| 2809 | |
| 2810 | // sizeFixed32PackedSlice returns the size of wire encoding a []uint32 pointer as a packed repeated Fixed32. |
| 2811 | func sizeFixed32PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2812 | s := *p.Uint32Slice() |
| 2813 | if len(s) == 0 { |
| 2814 | return 0 |
| 2815 | } |
| 2816 | n := len(s) * wire.SizeFixed32() |
| 2817 | return tagsize + wire.SizeBytes(n) |
| 2818 | } |
| 2819 | |
| 2820 | // appendFixed32PackedSlice encodes a []uint32 pointer as a packed repeated Fixed32. |
| 2821 | func appendFixed32PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2822 | s := *p.Uint32Slice() |
| 2823 | if len(s) == 0 { |
| 2824 | return b, nil |
| 2825 | } |
| 2826 | b = wire.AppendVarint(b, wiretag) |
| 2827 | n := len(s) * wire.SizeFixed32() |
| 2828 | b = wire.AppendVarint(b, uint64(n)) |
| 2829 | for _, v := range s { |
| 2830 | b = wire.AppendFixed32(b, v) |
| 2831 | } |
| 2832 | return b, nil |
| 2833 | } |
| 2834 | |
| 2835 | var coderFixed32PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2836 | size: sizeFixed32PackedSlice, |
| 2837 | marshal: appendFixed32PackedSlice, |
| 2838 | unmarshal: consumeFixed32Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2839 | } |
| 2840 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2841 | // sizeFixed32Value returns the size of wire encoding a uint32 value as a Fixed32. |
| 2842 | func sizeFixed32Value(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2843 | return tagsize + wire.SizeFixed32() |
| 2844 | } |
| 2845 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2846 | // appendFixed32Value encodes a uint32 value as a Fixed32. |
| 2847 | func appendFixed32Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2848 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2849 | b = wire.AppendFixed32(b, uint32(v.Uint())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2850 | return b, nil |
| 2851 | } |
| 2852 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2853 | // consumeFixed32Value decodes a uint32 value as a Fixed32. |
| 2854 | func consumeFixed32Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2855 | if wtyp != wire.Fixed32Type { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2856 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2857 | } |
| 2858 | v, n := wire.ConsumeFixed32(b) |
| 2859 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2860 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2861 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2862 | return protoreflect.ValueOfUint32(uint32(v)), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2863 | } |
| 2864 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2865 | var coderFixed32Value = valueCoderFuncs{ |
| 2866 | size: sizeFixed32Value, |
| 2867 | marshal: appendFixed32Value, |
| 2868 | unmarshal: consumeFixed32Value, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2869 | } |
| 2870 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2871 | // sizeFixed32SliceValue returns the size of wire encoding a []uint32 value as a repeated Fixed32. |
| 2872 | func sizeFixed32SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 2873 | list := listv.List() |
| 2874 | size = list.Len() * (tagsize + wire.SizeFixed32()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2875 | return size |
| 2876 | } |
| 2877 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2878 | // appendFixed32SliceValue encodes a []uint32 value as a repeated Fixed32. |
| 2879 | func appendFixed32SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2880 | list := listv.List() |
| 2881 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 2882 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2883 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2884 | b = wire.AppendFixed32(b, uint32(v.Uint())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2885 | } |
| 2886 | return b, nil |
| 2887 | } |
| 2888 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2889 | // consumeFixed32SliceValue wire decodes a []uint32 value as a repeated Fixed32. |
| 2890 | func consumeFixed32SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 2891 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2892 | if wtyp == wire.BytesType { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2893 | b, n = wire.ConsumeBytes(b) |
| 2894 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2895 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2896 | } |
| 2897 | for len(b) > 0 { |
| 2898 | v, n := wire.ConsumeFixed32(b) |
| 2899 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2900 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2901 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2902 | list.Append(protoreflect.ValueOfUint32(uint32(v))) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2903 | b = b[n:] |
| 2904 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2905 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2906 | } |
| 2907 | if wtyp != wire.Fixed32Type { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2908 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2909 | } |
| 2910 | v, n := wire.ConsumeFixed32(b) |
| 2911 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2912 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2913 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2914 | list.Append(protoreflect.ValueOfUint32(uint32(v))) |
| 2915 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2916 | } |
| 2917 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2918 | var coderFixed32SliceValue = valueCoderFuncs{ |
| 2919 | size: sizeFixed32SliceValue, |
| 2920 | marshal: appendFixed32SliceValue, |
| 2921 | unmarshal: consumeFixed32SliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2922 | } |
| 2923 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2924 | // sizeFixed32PackedSliceValue returns the size of wire encoding a []uint32 value as a packed repeated Fixed32. |
| 2925 | func sizeFixed32PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 2926 | list := listv.List() |
| 2927 | n := list.Len() * wire.SizeFixed32() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2928 | return tagsize + wire.SizeBytes(n) |
| 2929 | } |
| 2930 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2931 | // appendFixed32PackedSliceValue encodes a []uint32 value as a packed repeated Fixed32. |
| 2932 | func appendFixed32PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2933 | list := listv.List() |
| 2934 | llen := list.Len() |
| 2935 | if llen == 0 { |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2936 | return b, nil |
| 2937 | } |
| 2938 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2939 | n := llen * wire.SizeFixed32() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2940 | b = wire.AppendVarint(b, uint64(n)) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2941 | for i := 0; i < llen; i++ { |
| 2942 | v := list.Get(i) |
| 2943 | b = wire.AppendFixed32(b, uint32(v.Uint())) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2944 | } |
| 2945 | return b, nil |
| 2946 | } |
| 2947 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 2948 | var coderFixed32PackedSliceValue = valueCoderFuncs{ |
| 2949 | size: sizeFixed32PackedSliceValue, |
| 2950 | marshal: appendFixed32PackedSliceValue, |
| 2951 | unmarshal: consumeFixed32SliceValue, |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2954 | // sizeFloat returns the size of wire encoding a float32 pointer as a Float. |
| 2955 | func sizeFloat(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2956 | |
| 2957 | return tagsize + wire.SizeFixed32() |
| 2958 | } |
| 2959 | |
| 2960 | // appendFloat wire encodes a float32 pointer as a Float. |
| 2961 | func appendFloat(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 2962 | v := *p.Float32() |
| 2963 | b = wire.AppendVarint(b, wiretag) |
| 2964 | b = wire.AppendFixed32(b, math.Float32bits(v)) |
| 2965 | return b, nil |
| 2966 | } |
| 2967 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2968 | // consumeFloat wire decodes a float32 pointer as a Float. |
| 2969 | func consumeFloat(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 2970 | if wtyp != wire.Fixed32Type { |
| 2971 | return 0, errUnknown |
| 2972 | } |
| 2973 | v, n := wire.ConsumeFixed32(b) |
| 2974 | if n < 0 { |
| 2975 | return 0, wire.ParseError(n) |
| 2976 | } |
| 2977 | *p.Float32() = math.Float32frombits(v) |
| 2978 | return n, nil |
| 2979 | } |
| 2980 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2981 | var coderFloat = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 2982 | size: sizeFloat, |
| 2983 | marshal: appendFloat, |
| 2984 | unmarshal: consumeFloat, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 2987 | // sizeFloatNoZero returns the size of wire encoding a float32 pointer as a Float. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2988 | // The zero value is not encoded. |
| 2989 | func sizeFloatNoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 2990 | v := *p.Float32() |
| 2991 | if v == 0 && !math.Signbit(float64(v)) { |
| 2992 | return 0 |
| 2993 | } |
| 2994 | return tagsize + wire.SizeFixed32() |
| 2995 | } |
| 2996 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 2997 | // appendFloatNoZero wire encodes a float32 pointer as a Float. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 2998 | // The zero value is not encoded. |
| 2999 | func appendFloatNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3000 | v := *p.Float32() |
| 3001 | if v == 0 && !math.Signbit(float64(v)) { |
| 3002 | return b, nil |
| 3003 | } |
| 3004 | b = wire.AppendVarint(b, wiretag) |
| 3005 | b = wire.AppendFixed32(b, math.Float32bits(v)) |
| 3006 | return b, nil |
| 3007 | } |
| 3008 | |
| 3009 | var coderFloatNoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3010 | size: sizeFloatNoZero, |
| 3011 | marshal: appendFloatNoZero, |
| 3012 | unmarshal: consumeFloat, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | // sizeFloatPtr returns the size of wire encoding a *float32 pointer as a Float. |
| 3016 | // It panics if the pointer is nil. |
| 3017 | func sizeFloatPtr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3018 | return tagsize + wire.SizeFixed32() |
| 3019 | } |
| 3020 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3021 | // appendFloatPtr wire encodes a *float32 pointer as a Float. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3022 | // It panics if the pointer is nil. |
| 3023 | func appendFloatPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3024 | v := **p.Float32Ptr() |
| 3025 | b = wire.AppendVarint(b, wiretag) |
| 3026 | b = wire.AppendFixed32(b, math.Float32bits(v)) |
| 3027 | return b, nil |
| 3028 | } |
| 3029 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3030 | // consumeFloatPtr wire decodes a *float32 pointer as a Float. |
| 3031 | func consumeFloatPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3032 | if wtyp != wire.Fixed32Type { |
| 3033 | return 0, errUnknown |
| 3034 | } |
| 3035 | v, n := wire.ConsumeFixed32(b) |
| 3036 | if n < 0 { |
| 3037 | return 0, wire.ParseError(n) |
| 3038 | } |
| 3039 | vp := p.Float32Ptr() |
| 3040 | if *vp == nil { |
| 3041 | *vp = new(float32) |
| 3042 | } |
| 3043 | **vp = math.Float32frombits(v) |
| 3044 | return n, nil |
| 3045 | } |
| 3046 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3047 | var coderFloatPtr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3048 | size: sizeFloatPtr, |
| 3049 | marshal: appendFloatPtr, |
| 3050 | unmarshal: consumeFloatPtr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3051 | } |
| 3052 | |
| 3053 | // sizeFloatSlice returns the size of wire encoding a []float32 pointer as a repeated Float. |
| 3054 | func sizeFloatSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3055 | s := *p.Float32Slice() |
| 3056 | size = len(s) * (tagsize + wire.SizeFixed32()) |
| 3057 | return size |
| 3058 | } |
| 3059 | |
| 3060 | // appendFloatSlice encodes a []float32 pointer as a repeated Float. |
| 3061 | func appendFloatSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3062 | s := *p.Float32Slice() |
| 3063 | for _, v := range s { |
| 3064 | b = wire.AppendVarint(b, wiretag) |
| 3065 | b = wire.AppendFixed32(b, math.Float32bits(v)) |
| 3066 | } |
| 3067 | return b, nil |
| 3068 | } |
| 3069 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3070 | // consumeFloatSlice wire decodes a []float32 pointer as a repeated Float. |
| 3071 | func consumeFloatSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3072 | sp := p.Float32Slice() |
| 3073 | if wtyp == wire.BytesType { |
| 3074 | s := *sp |
| 3075 | b, n = wire.ConsumeBytes(b) |
| 3076 | if n < 0 { |
| 3077 | return 0, wire.ParseError(n) |
| 3078 | } |
| 3079 | for len(b) > 0 { |
| 3080 | v, n := wire.ConsumeFixed32(b) |
| 3081 | if n < 0 { |
| 3082 | return 0, wire.ParseError(n) |
| 3083 | } |
| 3084 | s = append(s, math.Float32frombits(v)) |
| 3085 | b = b[n:] |
| 3086 | } |
| 3087 | *sp = s |
| 3088 | return n, nil |
| 3089 | } |
| 3090 | if wtyp != wire.Fixed32Type { |
| 3091 | return 0, errUnknown |
| 3092 | } |
| 3093 | v, n := wire.ConsumeFixed32(b) |
| 3094 | if n < 0 { |
| 3095 | return 0, wire.ParseError(n) |
| 3096 | } |
| 3097 | *sp = append(*sp, math.Float32frombits(v)) |
| 3098 | return n, nil |
| 3099 | } |
| 3100 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3101 | var coderFloatSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3102 | size: sizeFloatSlice, |
| 3103 | marshal: appendFloatSlice, |
| 3104 | unmarshal: consumeFloatSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | // sizeFloatPackedSlice returns the size of wire encoding a []float32 pointer as a packed repeated Float. |
| 3108 | func sizeFloatPackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3109 | s := *p.Float32Slice() |
| 3110 | if len(s) == 0 { |
| 3111 | return 0 |
| 3112 | } |
| 3113 | n := len(s) * wire.SizeFixed32() |
| 3114 | return tagsize + wire.SizeBytes(n) |
| 3115 | } |
| 3116 | |
| 3117 | // appendFloatPackedSlice encodes a []float32 pointer as a packed repeated Float. |
| 3118 | func appendFloatPackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3119 | s := *p.Float32Slice() |
| 3120 | if len(s) == 0 { |
| 3121 | return b, nil |
| 3122 | } |
| 3123 | b = wire.AppendVarint(b, wiretag) |
| 3124 | n := len(s) * wire.SizeFixed32() |
| 3125 | b = wire.AppendVarint(b, uint64(n)) |
| 3126 | for _, v := range s { |
| 3127 | b = wire.AppendFixed32(b, math.Float32bits(v)) |
| 3128 | } |
| 3129 | return b, nil |
| 3130 | } |
| 3131 | |
| 3132 | var coderFloatPackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3133 | size: sizeFloatPackedSlice, |
| 3134 | marshal: appendFloatPackedSlice, |
| 3135 | unmarshal: consumeFloatSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3136 | } |
| 3137 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3138 | // sizeFloatValue returns the size of wire encoding a float32 value as a Float. |
| 3139 | func sizeFloatValue(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3140 | return tagsize + wire.SizeFixed32() |
| 3141 | } |
| 3142 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3143 | // appendFloatValue encodes a float32 value as a Float. |
| 3144 | func appendFloatValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3145 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3146 | b = wire.AppendFixed32(b, math.Float32bits(float32(v.Float()))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3147 | return b, nil |
| 3148 | } |
| 3149 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3150 | // consumeFloatValue decodes a float32 value as a Float. |
| 3151 | func consumeFloatValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3152 | if wtyp != wire.Fixed32Type { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3153 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3154 | } |
| 3155 | v, n := wire.ConsumeFixed32(b) |
| 3156 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3157 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3158 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3159 | return protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v))), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3160 | } |
| 3161 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3162 | var coderFloatValue = valueCoderFuncs{ |
| 3163 | size: sizeFloatValue, |
| 3164 | marshal: appendFloatValue, |
| 3165 | unmarshal: consumeFloatValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3166 | } |
| 3167 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3168 | // sizeFloatSliceValue returns the size of wire encoding a []float32 value as a repeated Float. |
| 3169 | func sizeFloatSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 3170 | list := listv.List() |
| 3171 | size = list.Len() * (tagsize + wire.SizeFixed32()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3172 | return size |
| 3173 | } |
| 3174 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3175 | // appendFloatSliceValue encodes a []float32 value as a repeated Float. |
| 3176 | func appendFloatSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3177 | list := listv.List() |
| 3178 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 3179 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3180 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3181 | b = wire.AppendFixed32(b, math.Float32bits(float32(v.Float()))) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3182 | } |
| 3183 | return b, nil |
| 3184 | } |
| 3185 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3186 | // consumeFloatSliceValue wire decodes a []float32 value as a repeated Float. |
| 3187 | func consumeFloatSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 3188 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3189 | if wtyp == wire.BytesType { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3190 | b, n = wire.ConsumeBytes(b) |
| 3191 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3192 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3193 | } |
| 3194 | for len(b) > 0 { |
| 3195 | v, n := wire.ConsumeFixed32(b) |
| 3196 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3197 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3198 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3199 | list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v)))) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3200 | b = b[n:] |
| 3201 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3202 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3203 | } |
| 3204 | if wtyp != wire.Fixed32Type { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3205 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3206 | } |
| 3207 | v, n := wire.ConsumeFixed32(b) |
| 3208 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3209 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3210 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3211 | list.Append(protoreflect.ValueOfFloat32(math.Float32frombits(uint32(v)))) |
| 3212 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3213 | } |
| 3214 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3215 | var coderFloatSliceValue = valueCoderFuncs{ |
| 3216 | size: sizeFloatSliceValue, |
| 3217 | marshal: appendFloatSliceValue, |
| 3218 | unmarshal: consumeFloatSliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3219 | } |
| 3220 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3221 | // sizeFloatPackedSliceValue returns the size of wire encoding a []float32 value as a packed repeated Float. |
| 3222 | func sizeFloatPackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 3223 | list := listv.List() |
| 3224 | n := list.Len() * wire.SizeFixed32() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3225 | return tagsize + wire.SizeBytes(n) |
| 3226 | } |
| 3227 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3228 | // appendFloatPackedSliceValue encodes a []float32 value as a packed repeated Float. |
| 3229 | func appendFloatPackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3230 | list := listv.List() |
| 3231 | llen := list.Len() |
| 3232 | if llen == 0 { |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3233 | return b, nil |
| 3234 | } |
| 3235 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3236 | n := llen * wire.SizeFixed32() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3237 | b = wire.AppendVarint(b, uint64(n)) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3238 | for i := 0; i < llen; i++ { |
| 3239 | v := list.Get(i) |
| 3240 | b = wire.AppendFixed32(b, math.Float32bits(float32(v.Float()))) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3241 | } |
| 3242 | return b, nil |
| 3243 | } |
| 3244 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3245 | var coderFloatPackedSliceValue = valueCoderFuncs{ |
| 3246 | size: sizeFloatPackedSliceValue, |
| 3247 | marshal: appendFloatPackedSliceValue, |
| 3248 | unmarshal: consumeFloatSliceValue, |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3251 | // sizeSfixed64 returns the size of wire encoding a int64 pointer as a Sfixed64. |
| 3252 | func sizeSfixed64(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3253 | |
| 3254 | return tagsize + wire.SizeFixed64() |
| 3255 | } |
| 3256 | |
| 3257 | // appendSfixed64 wire encodes a int64 pointer as a Sfixed64. |
| 3258 | func appendSfixed64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3259 | v := *p.Int64() |
| 3260 | b = wire.AppendVarint(b, wiretag) |
| 3261 | b = wire.AppendFixed64(b, uint64(v)) |
| 3262 | return b, nil |
| 3263 | } |
| 3264 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3265 | // consumeSfixed64 wire decodes a int64 pointer as a Sfixed64. |
| 3266 | func consumeSfixed64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3267 | if wtyp != wire.Fixed64Type { |
| 3268 | return 0, errUnknown |
| 3269 | } |
| 3270 | v, n := wire.ConsumeFixed64(b) |
| 3271 | if n < 0 { |
| 3272 | return 0, wire.ParseError(n) |
| 3273 | } |
| 3274 | *p.Int64() = int64(v) |
| 3275 | return n, nil |
| 3276 | } |
| 3277 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3278 | var coderSfixed64 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3279 | size: sizeSfixed64, |
| 3280 | marshal: appendSfixed64, |
| 3281 | unmarshal: consumeSfixed64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3282 | } |
| 3283 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 3284 | // sizeSfixed64NoZero returns the size of wire encoding a int64 pointer as a Sfixed64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3285 | // The zero value is not encoded. |
| 3286 | func sizeSfixed64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3287 | v := *p.Int64() |
| 3288 | if v == 0 { |
| 3289 | return 0 |
| 3290 | } |
| 3291 | return tagsize + wire.SizeFixed64() |
| 3292 | } |
| 3293 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 3294 | // appendSfixed64NoZero wire encodes a int64 pointer as a Sfixed64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3295 | // The zero value is not encoded. |
| 3296 | func appendSfixed64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3297 | v := *p.Int64() |
| 3298 | if v == 0 { |
| 3299 | return b, nil |
| 3300 | } |
| 3301 | b = wire.AppendVarint(b, wiretag) |
| 3302 | b = wire.AppendFixed64(b, uint64(v)) |
| 3303 | return b, nil |
| 3304 | } |
| 3305 | |
| 3306 | var coderSfixed64NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3307 | size: sizeSfixed64NoZero, |
| 3308 | marshal: appendSfixed64NoZero, |
| 3309 | unmarshal: consumeSfixed64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | // sizeSfixed64Ptr returns the size of wire encoding a *int64 pointer as a Sfixed64. |
| 3313 | // It panics if the pointer is nil. |
| 3314 | func sizeSfixed64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3315 | return tagsize + wire.SizeFixed64() |
| 3316 | } |
| 3317 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3318 | // appendSfixed64Ptr wire encodes a *int64 pointer as a Sfixed64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3319 | // It panics if the pointer is nil. |
| 3320 | func appendSfixed64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3321 | v := **p.Int64Ptr() |
| 3322 | b = wire.AppendVarint(b, wiretag) |
| 3323 | b = wire.AppendFixed64(b, uint64(v)) |
| 3324 | return b, nil |
| 3325 | } |
| 3326 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3327 | // consumeSfixed64Ptr wire decodes a *int64 pointer as a Sfixed64. |
| 3328 | func consumeSfixed64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3329 | if wtyp != wire.Fixed64Type { |
| 3330 | return 0, errUnknown |
| 3331 | } |
| 3332 | v, n := wire.ConsumeFixed64(b) |
| 3333 | if n < 0 { |
| 3334 | return 0, wire.ParseError(n) |
| 3335 | } |
| 3336 | vp := p.Int64Ptr() |
| 3337 | if *vp == nil { |
| 3338 | *vp = new(int64) |
| 3339 | } |
| 3340 | **vp = int64(v) |
| 3341 | return n, nil |
| 3342 | } |
| 3343 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3344 | var coderSfixed64Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3345 | size: sizeSfixed64Ptr, |
| 3346 | marshal: appendSfixed64Ptr, |
| 3347 | unmarshal: consumeSfixed64Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | // sizeSfixed64Slice returns the size of wire encoding a []int64 pointer as a repeated Sfixed64. |
| 3351 | func sizeSfixed64Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3352 | s := *p.Int64Slice() |
| 3353 | size = len(s) * (tagsize + wire.SizeFixed64()) |
| 3354 | return size |
| 3355 | } |
| 3356 | |
| 3357 | // appendSfixed64Slice encodes a []int64 pointer as a repeated Sfixed64. |
| 3358 | func appendSfixed64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3359 | s := *p.Int64Slice() |
| 3360 | for _, v := range s { |
| 3361 | b = wire.AppendVarint(b, wiretag) |
| 3362 | b = wire.AppendFixed64(b, uint64(v)) |
| 3363 | } |
| 3364 | return b, nil |
| 3365 | } |
| 3366 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3367 | // consumeSfixed64Slice wire decodes a []int64 pointer as a repeated Sfixed64. |
| 3368 | func consumeSfixed64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3369 | sp := p.Int64Slice() |
| 3370 | if wtyp == wire.BytesType { |
| 3371 | s := *sp |
| 3372 | b, n = wire.ConsumeBytes(b) |
| 3373 | if n < 0 { |
| 3374 | return 0, wire.ParseError(n) |
| 3375 | } |
| 3376 | for len(b) > 0 { |
| 3377 | v, n := wire.ConsumeFixed64(b) |
| 3378 | if n < 0 { |
| 3379 | return 0, wire.ParseError(n) |
| 3380 | } |
| 3381 | s = append(s, int64(v)) |
| 3382 | b = b[n:] |
| 3383 | } |
| 3384 | *sp = s |
| 3385 | return n, nil |
| 3386 | } |
| 3387 | if wtyp != wire.Fixed64Type { |
| 3388 | return 0, errUnknown |
| 3389 | } |
| 3390 | v, n := wire.ConsumeFixed64(b) |
| 3391 | if n < 0 { |
| 3392 | return 0, wire.ParseError(n) |
| 3393 | } |
| 3394 | *sp = append(*sp, int64(v)) |
| 3395 | return n, nil |
| 3396 | } |
| 3397 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3398 | var coderSfixed64Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3399 | size: sizeSfixed64Slice, |
| 3400 | marshal: appendSfixed64Slice, |
| 3401 | unmarshal: consumeSfixed64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | // sizeSfixed64PackedSlice returns the size of wire encoding a []int64 pointer as a packed repeated Sfixed64. |
| 3405 | func sizeSfixed64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3406 | s := *p.Int64Slice() |
| 3407 | if len(s) == 0 { |
| 3408 | return 0 |
| 3409 | } |
| 3410 | n := len(s) * wire.SizeFixed64() |
| 3411 | return tagsize + wire.SizeBytes(n) |
| 3412 | } |
| 3413 | |
| 3414 | // appendSfixed64PackedSlice encodes a []int64 pointer as a packed repeated Sfixed64. |
| 3415 | func appendSfixed64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3416 | s := *p.Int64Slice() |
| 3417 | if len(s) == 0 { |
| 3418 | return b, nil |
| 3419 | } |
| 3420 | b = wire.AppendVarint(b, wiretag) |
| 3421 | n := len(s) * wire.SizeFixed64() |
| 3422 | b = wire.AppendVarint(b, uint64(n)) |
| 3423 | for _, v := range s { |
| 3424 | b = wire.AppendFixed64(b, uint64(v)) |
| 3425 | } |
| 3426 | return b, nil |
| 3427 | } |
| 3428 | |
| 3429 | var coderSfixed64PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3430 | size: sizeSfixed64PackedSlice, |
| 3431 | marshal: appendSfixed64PackedSlice, |
| 3432 | unmarshal: consumeSfixed64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3433 | } |
| 3434 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3435 | // sizeSfixed64Value returns the size of wire encoding a int64 value as a Sfixed64. |
| 3436 | func sizeSfixed64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3437 | return tagsize + wire.SizeFixed64() |
| 3438 | } |
| 3439 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3440 | // appendSfixed64Value encodes a int64 value as a Sfixed64. |
| 3441 | func appendSfixed64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3442 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3443 | b = wire.AppendFixed64(b, uint64(v.Int())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3444 | return b, nil |
| 3445 | } |
| 3446 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3447 | // consumeSfixed64Value decodes a int64 value as a Sfixed64. |
| 3448 | func consumeSfixed64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3449 | if wtyp != wire.Fixed64Type { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3450 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3451 | } |
| 3452 | v, n := wire.ConsumeFixed64(b) |
| 3453 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3454 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3455 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3456 | return protoreflect.ValueOfInt64(int64(v)), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3457 | } |
| 3458 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3459 | var coderSfixed64Value = valueCoderFuncs{ |
| 3460 | size: sizeSfixed64Value, |
| 3461 | marshal: appendSfixed64Value, |
| 3462 | unmarshal: consumeSfixed64Value, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3463 | } |
| 3464 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3465 | // sizeSfixed64SliceValue returns the size of wire encoding a []int64 value as a repeated Sfixed64. |
| 3466 | func sizeSfixed64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 3467 | list := listv.List() |
| 3468 | size = list.Len() * (tagsize + wire.SizeFixed64()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3469 | return size |
| 3470 | } |
| 3471 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3472 | // appendSfixed64SliceValue encodes a []int64 value as a repeated Sfixed64. |
| 3473 | func appendSfixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3474 | list := listv.List() |
| 3475 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 3476 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3477 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3478 | b = wire.AppendFixed64(b, uint64(v.Int())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3479 | } |
| 3480 | return b, nil |
| 3481 | } |
| 3482 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3483 | // consumeSfixed64SliceValue wire decodes a []int64 value as a repeated Sfixed64. |
| 3484 | func consumeSfixed64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 3485 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3486 | if wtyp == wire.BytesType { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3487 | b, n = wire.ConsumeBytes(b) |
| 3488 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3489 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3490 | } |
| 3491 | for len(b) > 0 { |
| 3492 | v, n := wire.ConsumeFixed64(b) |
| 3493 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3494 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3495 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3496 | list.Append(protoreflect.ValueOfInt64(int64(v))) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3497 | b = b[n:] |
| 3498 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3499 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3500 | } |
| 3501 | if wtyp != wire.Fixed64Type { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3502 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3503 | } |
| 3504 | v, n := wire.ConsumeFixed64(b) |
| 3505 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3506 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3507 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3508 | list.Append(protoreflect.ValueOfInt64(int64(v))) |
| 3509 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3510 | } |
| 3511 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3512 | var coderSfixed64SliceValue = valueCoderFuncs{ |
| 3513 | size: sizeSfixed64SliceValue, |
| 3514 | marshal: appendSfixed64SliceValue, |
| 3515 | unmarshal: consumeSfixed64SliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3516 | } |
| 3517 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3518 | // sizeSfixed64PackedSliceValue returns the size of wire encoding a []int64 value as a packed repeated Sfixed64. |
| 3519 | func sizeSfixed64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 3520 | list := listv.List() |
| 3521 | n := list.Len() * wire.SizeFixed64() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3522 | return tagsize + wire.SizeBytes(n) |
| 3523 | } |
| 3524 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3525 | // appendSfixed64PackedSliceValue encodes a []int64 value as a packed repeated Sfixed64. |
| 3526 | func appendSfixed64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3527 | list := listv.List() |
| 3528 | llen := list.Len() |
| 3529 | if llen == 0 { |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3530 | return b, nil |
| 3531 | } |
| 3532 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3533 | n := llen * wire.SizeFixed64() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3534 | b = wire.AppendVarint(b, uint64(n)) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3535 | for i := 0; i < llen; i++ { |
| 3536 | v := list.Get(i) |
| 3537 | b = wire.AppendFixed64(b, uint64(v.Int())) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3538 | } |
| 3539 | return b, nil |
| 3540 | } |
| 3541 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3542 | var coderSfixed64PackedSliceValue = valueCoderFuncs{ |
| 3543 | size: sizeSfixed64PackedSliceValue, |
| 3544 | marshal: appendSfixed64PackedSliceValue, |
| 3545 | unmarshal: consumeSfixed64SliceValue, |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3546 | } |
| 3547 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3548 | // sizeFixed64 returns the size of wire encoding a uint64 pointer as a Fixed64. |
| 3549 | func sizeFixed64(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3550 | |
| 3551 | return tagsize + wire.SizeFixed64() |
| 3552 | } |
| 3553 | |
| 3554 | // appendFixed64 wire encodes a uint64 pointer as a Fixed64. |
| 3555 | func appendFixed64(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3556 | v := *p.Uint64() |
| 3557 | b = wire.AppendVarint(b, wiretag) |
| 3558 | b = wire.AppendFixed64(b, v) |
| 3559 | return b, nil |
| 3560 | } |
| 3561 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3562 | // consumeFixed64 wire decodes a uint64 pointer as a Fixed64. |
| 3563 | func consumeFixed64(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3564 | if wtyp != wire.Fixed64Type { |
| 3565 | return 0, errUnknown |
| 3566 | } |
| 3567 | v, n := wire.ConsumeFixed64(b) |
| 3568 | if n < 0 { |
| 3569 | return 0, wire.ParseError(n) |
| 3570 | } |
| 3571 | *p.Uint64() = v |
| 3572 | return n, nil |
| 3573 | } |
| 3574 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3575 | var coderFixed64 = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3576 | size: sizeFixed64, |
| 3577 | marshal: appendFixed64, |
| 3578 | unmarshal: consumeFixed64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 3581 | // sizeFixed64NoZero returns the size of wire encoding a uint64 pointer as a Fixed64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3582 | // The zero value is not encoded. |
| 3583 | func sizeFixed64NoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3584 | v := *p.Uint64() |
| 3585 | if v == 0 { |
| 3586 | return 0 |
| 3587 | } |
| 3588 | return tagsize + wire.SizeFixed64() |
| 3589 | } |
| 3590 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 3591 | // appendFixed64NoZero wire encodes a uint64 pointer as a Fixed64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3592 | // The zero value is not encoded. |
| 3593 | func appendFixed64NoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3594 | v := *p.Uint64() |
| 3595 | if v == 0 { |
| 3596 | return b, nil |
| 3597 | } |
| 3598 | b = wire.AppendVarint(b, wiretag) |
| 3599 | b = wire.AppendFixed64(b, v) |
| 3600 | return b, nil |
| 3601 | } |
| 3602 | |
| 3603 | var coderFixed64NoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3604 | size: sizeFixed64NoZero, |
| 3605 | marshal: appendFixed64NoZero, |
| 3606 | unmarshal: consumeFixed64, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3607 | } |
| 3608 | |
| 3609 | // sizeFixed64Ptr returns the size of wire encoding a *uint64 pointer as a Fixed64. |
| 3610 | // It panics if the pointer is nil. |
| 3611 | func sizeFixed64Ptr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3612 | return tagsize + wire.SizeFixed64() |
| 3613 | } |
| 3614 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3615 | // appendFixed64Ptr wire encodes a *uint64 pointer as a Fixed64. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3616 | // It panics if the pointer is nil. |
| 3617 | func appendFixed64Ptr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3618 | v := **p.Uint64Ptr() |
| 3619 | b = wire.AppendVarint(b, wiretag) |
| 3620 | b = wire.AppendFixed64(b, v) |
| 3621 | return b, nil |
| 3622 | } |
| 3623 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3624 | // consumeFixed64Ptr wire decodes a *uint64 pointer as a Fixed64. |
| 3625 | func consumeFixed64Ptr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3626 | if wtyp != wire.Fixed64Type { |
| 3627 | return 0, errUnknown |
| 3628 | } |
| 3629 | v, n := wire.ConsumeFixed64(b) |
| 3630 | if n < 0 { |
| 3631 | return 0, wire.ParseError(n) |
| 3632 | } |
| 3633 | vp := p.Uint64Ptr() |
| 3634 | if *vp == nil { |
| 3635 | *vp = new(uint64) |
| 3636 | } |
| 3637 | **vp = v |
| 3638 | return n, nil |
| 3639 | } |
| 3640 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3641 | var coderFixed64Ptr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3642 | size: sizeFixed64Ptr, |
| 3643 | marshal: appendFixed64Ptr, |
| 3644 | unmarshal: consumeFixed64Ptr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | // sizeFixed64Slice returns the size of wire encoding a []uint64 pointer as a repeated Fixed64. |
| 3648 | func sizeFixed64Slice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3649 | s := *p.Uint64Slice() |
| 3650 | size = len(s) * (tagsize + wire.SizeFixed64()) |
| 3651 | return size |
| 3652 | } |
| 3653 | |
| 3654 | // appendFixed64Slice encodes a []uint64 pointer as a repeated Fixed64. |
| 3655 | func appendFixed64Slice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3656 | s := *p.Uint64Slice() |
| 3657 | for _, v := range s { |
| 3658 | b = wire.AppendVarint(b, wiretag) |
| 3659 | b = wire.AppendFixed64(b, v) |
| 3660 | } |
| 3661 | return b, nil |
| 3662 | } |
| 3663 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3664 | // consumeFixed64Slice wire decodes a []uint64 pointer as a repeated Fixed64. |
| 3665 | func consumeFixed64Slice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3666 | sp := p.Uint64Slice() |
| 3667 | if wtyp == wire.BytesType { |
| 3668 | s := *sp |
| 3669 | b, n = wire.ConsumeBytes(b) |
| 3670 | if n < 0 { |
| 3671 | return 0, wire.ParseError(n) |
| 3672 | } |
| 3673 | for len(b) > 0 { |
| 3674 | v, n := wire.ConsumeFixed64(b) |
| 3675 | if n < 0 { |
| 3676 | return 0, wire.ParseError(n) |
| 3677 | } |
| 3678 | s = append(s, v) |
| 3679 | b = b[n:] |
| 3680 | } |
| 3681 | *sp = s |
| 3682 | return n, nil |
| 3683 | } |
| 3684 | if wtyp != wire.Fixed64Type { |
| 3685 | return 0, errUnknown |
| 3686 | } |
| 3687 | v, n := wire.ConsumeFixed64(b) |
| 3688 | if n < 0 { |
| 3689 | return 0, wire.ParseError(n) |
| 3690 | } |
| 3691 | *sp = append(*sp, v) |
| 3692 | return n, nil |
| 3693 | } |
| 3694 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3695 | var coderFixed64Slice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3696 | size: sizeFixed64Slice, |
| 3697 | marshal: appendFixed64Slice, |
| 3698 | unmarshal: consumeFixed64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3699 | } |
| 3700 | |
| 3701 | // sizeFixed64PackedSlice returns the size of wire encoding a []uint64 pointer as a packed repeated Fixed64. |
| 3702 | func sizeFixed64PackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3703 | s := *p.Uint64Slice() |
| 3704 | if len(s) == 0 { |
| 3705 | return 0 |
| 3706 | } |
| 3707 | n := len(s) * wire.SizeFixed64() |
| 3708 | return tagsize + wire.SizeBytes(n) |
| 3709 | } |
| 3710 | |
| 3711 | // appendFixed64PackedSlice encodes a []uint64 pointer as a packed repeated Fixed64. |
| 3712 | func appendFixed64PackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3713 | s := *p.Uint64Slice() |
| 3714 | if len(s) == 0 { |
| 3715 | return b, nil |
| 3716 | } |
| 3717 | b = wire.AppendVarint(b, wiretag) |
| 3718 | n := len(s) * wire.SizeFixed64() |
| 3719 | b = wire.AppendVarint(b, uint64(n)) |
| 3720 | for _, v := range s { |
| 3721 | b = wire.AppendFixed64(b, v) |
| 3722 | } |
| 3723 | return b, nil |
| 3724 | } |
| 3725 | |
| 3726 | var coderFixed64PackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3727 | size: sizeFixed64PackedSlice, |
| 3728 | marshal: appendFixed64PackedSlice, |
| 3729 | unmarshal: consumeFixed64Slice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3730 | } |
| 3731 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3732 | // sizeFixed64Value returns the size of wire encoding a uint64 value as a Fixed64. |
| 3733 | func sizeFixed64Value(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3734 | return tagsize + wire.SizeFixed64() |
| 3735 | } |
| 3736 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3737 | // appendFixed64Value encodes a uint64 value as a Fixed64. |
| 3738 | func appendFixed64Value(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3739 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3740 | b = wire.AppendFixed64(b, v.Uint()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3741 | return b, nil |
| 3742 | } |
| 3743 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3744 | // consumeFixed64Value decodes a uint64 value as a Fixed64. |
| 3745 | func consumeFixed64Value(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3746 | if wtyp != wire.Fixed64Type { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3747 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3748 | } |
| 3749 | v, n := wire.ConsumeFixed64(b) |
| 3750 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3751 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3752 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3753 | return protoreflect.ValueOfUint64(v), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3754 | } |
| 3755 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3756 | var coderFixed64Value = valueCoderFuncs{ |
| 3757 | size: sizeFixed64Value, |
| 3758 | marshal: appendFixed64Value, |
| 3759 | unmarshal: consumeFixed64Value, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3760 | } |
| 3761 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3762 | // sizeFixed64SliceValue returns the size of wire encoding a []uint64 value as a repeated Fixed64. |
| 3763 | func sizeFixed64SliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 3764 | list := listv.List() |
| 3765 | size = list.Len() * (tagsize + wire.SizeFixed64()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3766 | return size |
| 3767 | } |
| 3768 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3769 | // appendFixed64SliceValue encodes a []uint64 value as a repeated Fixed64. |
| 3770 | func appendFixed64SliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3771 | list := listv.List() |
| 3772 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 3773 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3774 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3775 | b = wire.AppendFixed64(b, v.Uint()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3776 | } |
| 3777 | return b, nil |
| 3778 | } |
| 3779 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3780 | // consumeFixed64SliceValue wire decodes a []uint64 value as a repeated Fixed64. |
| 3781 | func consumeFixed64SliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 3782 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3783 | if wtyp == wire.BytesType { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3784 | b, n = wire.ConsumeBytes(b) |
| 3785 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3786 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3787 | } |
| 3788 | for len(b) > 0 { |
| 3789 | v, n := wire.ConsumeFixed64(b) |
| 3790 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3791 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3792 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3793 | list.Append(protoreflect.ValueOfUint64(v)) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3794 | b = b[n:] |
| 3795 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3796 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3797 | } |
| 3798 | if wtyp != wire.Fixed64Type { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3799 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3800 | } |
| 3801 | v, n := wire.ConsumeFixed64(b) |
| 3802 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3803 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3804 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3805 | list.Append(protoreflect.ValueOfUint64(v)) |
| 3806 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3807 | } |
| 3808 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3809 | var coderFixed64SliceValue = valueCoderFuncs{ |
| 3810 | size: sizeFixed64SliceValue, |
| 3811 | marshal: appendFixed64SliceValue, |
| 3812 | unmarshal: consumeFixed64SliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3813 | } |
| 3814 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3815 | // sizeFixed64PackedSliceValue returns the size of wire encoding a []uint64 value as a packed repeated Fixed64. |
| 3816 | func sizeFixed64PackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 3817 | list := listv.List() |
| 3818 | n := list.Len() * wire.SizeFixed64() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3819 | return tagsize + wire.SizeBytes(n) |
| 3820 | } |
| 3821 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3822 | // appendFixed64PackedSliceValue encodes a []uint64 value as a packed repeated Fixed64. |
| 3823 | func appendFixed64PackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3824 | list := listv.List() |
| 3825 | llen := list.Len() |
| 3826 | if llen == 0 { |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3827 | return b, nil |
| 3828 | } |
| 3829 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3830 | n := llen * wire.SizeFixed64() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3831 | b = wire.AppendVarint(b, uint64(n)) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3832 | for i := 0; i < llen; i++ { |
| 3833 | v := list.Get(i) |
| 3834 | b = wire.AppendFixed64(b, v.Uint()) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3835 | } |
| 3836 | return b, nil |
| 3837 | } |
| 3838 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 3839 | var coderFixed64PackedSliceValue = valueCoderFuncs{ |
| 3840 | size: sizeFixed64PackedSliceValue, |
| 3841 | marshal: appendFixed64PackedSliceValue, |
| 3842 | unmarshal: consumeFixed64SliceValue, |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 3843 | } |
| 3844 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3845 | // sizeDouble returns the size of wire encoding a float64 pointer as a Double. |
| 3846 | func sizeDouble(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3847 | |
| 3848 | return tagsize + wire.SizeFixed64() |
| 3849 | } |
| 3850 | |
| 3851 | // appendDouble wire encodes a float64 pointer as a Double. |
| 3852 | func appendDouble(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3853 | v := *p.Float64() |
| 3854 | b = wire.AppendVarint(b, wiretag) |
| 3855 | b = wire.AppendFixed64(b, math.Float64bits(v)) |
| 3856 | return b, nil |
| 3857 | } |
| 3858 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3859 | // consumeDouble wire decodes a float64 pointer as a Double. |
| 3860 | func consumeDouble(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3861 | if wtyp != wire.Fixed64Type { |
| 3862 | return 0, errUnknown |
| 3863 | } |
| 3864 | v, n := wire.ConsumeFixed64(b) |
| 3865 | if n < 0 { |
| 3866 | return 0, wire.ParseError(n) |
| 3867 | } |
| 3868 | *p.Float64() = math.Float64frombits(v) |
| 3869 | return n, nil |
| 3870 | } |
| 3871 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3872 | var coderDouble = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3873 | size: sizeDouble, |
| 3874 | marshal: appendDouble, |
| 3875 | unmarshal: consumeDouble, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3876 | } |
| 3877 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 3878 | // sizeDoubleNoZero returns the size of wire encoding a float64 pointer as a Double. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3879 | // The zero value is not encoded. |
| 3880 | func sizeDoubleNoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3881 | v := *p.Float64() |
| 3882 | if v == 0 && !math.Signbit(float64(v)) { |
| 3883 | return 0 |
| 3884 | } |
| 3885 | return tagsize + wire.SizeFixed64() |
| 3886 | } |
| 3887 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 3888 | // appendDoubleNoZero wire encodes a float64 pointer as a Double. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3889 | // The zero value is not encoded. |
| 3890 | func appendDoubleNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3891 | v := *p.Float64() |
| 3892 | if v == 0 && !math.Signbit(float64(v)) { |
| 3893 | return b, nil |
| 3894 | } |
| 3895 | b = wire.AppendVarint(b, wiretag) |
| 3896 | b = wire.AppendFixed64(b, math.Float64bits(v)) |
| 3897 | return b, nil |
| 3898 | } |
| 3899 | |
| 3900 | var coderDoubleNoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3901 | size: sizeDoubleNoZero, |
| 3902 | marshal: appendDoubleNoZero, |
| 3903 | unmarshal: consumeDouble, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3904 | } |
| 3905 | |
| 3906 | // sizeDoublePtr returns the size of wire encoding a *float64 pointer as a Double. |
| 3907 | // It panics if the pointer is nil. |
| 3908 | func sizeDoublePtr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3909 | return tagsize + wire.SizeFixed64() |
| 3910 | } |
| 3911 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3912 | // appendDoublePtr wire encodes a *float64 pointer as a Double. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3913 | // It panics if the pointer is nil. |
| 3914 | func appendDoublePtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3915 | v := **p.Float64Ptr() |
| 3916 | b = wire.AppendVarint(b, wiretag) |
| 3917 | b = wire.AppendFixed64(b, math.Float64bits(v)) |
| 3918 | return b, nil |
| 3919 | } |
| 3920 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3921 | // consumeDoublePtr wire decodes a *float64 pointer as a Double. |
| 3922 | func consumeDoublePtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3923 | if wtyp != wire.Fixed64Type { |
| 3924 | return 0, errUnknown |
| 3925 | } |
| 3926 | v, n := wire.ConsumeFixed64(b) |
| 3927 | if n < 0 { |
| 3928 | return 0, wire.ParseError(n) |
| 3929 | } |
| 3930 | vp := p.Float64Ptr() |
| 3931 | if *vp == nil { |
| 3932 | *vp = new(float64) |
| 3933 | } |
| 3934 | **vp = math.Float64frombits(v) |
| 3935 | return n, nil |
| 3936 | } |
| 3937 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3938 | var coderDoublePtr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3939 | size: sizeDoublePtr, |
| 3940 | marshal: appendDoublePtr, |
| 3941 | unmarshal: consumeDoublePtr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3942 | } |
| 3943 | |
| 3944 | // sizeDoubleSlice returns the size of wire encoding a []float64 pointer as a repeated Double. |
| 3945 | func sizeDoubleSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 3946 | s := *p.Float64Slice() |
| 3947 | size = len(s) * (tagsize + wire.SizeFixed64()) |
| 3948 | return size |
| 3949 | } |
| 3950 | |
| 3951 | // appendDoubleSlice encodes a []float64 pointer as a repeated Double. |
| 3952 | func appendDoubleSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 3953 | s := *p.Float64Slice() |
| 3954 | for _, v := range s { |
| 3955 | b = wire.AppendVarint(b, wiretag) |
| 3956 | b = wire.AppendFixed64(b, math.Float64bits(v)) |
| 3957 | } |
| 3958 | return b, nil |
| 3959 | } |
| 3960 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3961 | // consumeDoubleSlice wire decodes a []float64 pointer as a repeated Double. |
| 3962 | func consumeDoubleSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 3963 | sp := p.Float64Slice() |
| 3964 | if wtyp == wire.BytesType { |
| 3965 | s := *sp |
| 3966 | b, n = wire.ConsumeBytes(b) |
| 3967 | if n < 0 { |
| 3968 | return 0, wire.ParseError(n) |
| 3969 | } |
| 3970 | for len(b) > 0 { |
| 3971 | v, n := wire.ConsumeFixed64(b) |
| 3972 | if n < 0 { |
| 3973 | return 0, wire.ParseError(n) |
| 3974 | } |
| 3975 | s = append(s, math.Float64frombits(v)) |
| 3976 | b = b[n:] |
| 3977 | } |
| 3978 | *sp = s |
| 3979 | return n, nil |
| 3980 | } |
| 3981 | if wtyp != wire.Fixed64Type { |
| 3982 | return 0, errUnknown |
| 3983 | } |
| 3984 | v, n := wire.ConsumeFixed64(b) |
| 3985 | if n < 0 { |
| 3986 | return 0, wire.ParseError(n) |
| 3987 | } |
| 3988 | *sp = append(*sp, math.Float64frombits(v)) |
| 3989 | return n, nil |
| 3990 | } |
| 3991 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3992 | var coderDoubleSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 3993 | size: sizeDoubleSlice, |
| 3994 | marshal: appendDoubleSlice, |
| 3995 | unmarshal: consumeDoubleSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | // sizeDoublePackedSlice returns the size of wire encoding a []float64 pointer as a packed repeated Double. |
| 3999 | func sizeDoublePackedSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4000 | s := *p.Float64Slice() |
| 4001 | if len(s) == 0 { |
| 4002 | return 0 |
| 4003 | } |
| 4004 | n := len(s) * wire.SizeFixed64() |
| 4005 | return tagsize + wire.SizeBytes(n) |
| 4006 | } |
| 4007 | |
| 4008 | // appendDoublePackedSlice encodes a []float64 pointer as a packed repeated Double. |
| 4009 | func appendDoublePackedSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4010 | s := *p.Float64Slice() |
| 4011 | if len(s) == 0 { |
| 4012 | return b, nil |
| 4013 | } |
| 4014 | b = wire.AppendVarint(b, wiretag) |
| 4015 | n := len(s) * wire.SizeFixed64() |
| 4016 | b = wire.AppendVarint(b, uint64(n)) |
| 4017 | for _, v := range s { |
| 4018 | b = wire.AppendFixed64(b, math.Float64bits(v)) |
| 4019 | } |
| 4020 | return b, nil |
| 4021 | } |
| 4022 | |
| 4023 | var coderDoublePackedSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4024 | size: sizeDoublePackedSlice, |
| 4025 | marshal: appendDoublePackedSlice, |
| 4026 | unmarshal: consumeDoubleSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4029 | // sizeDoubleValue returns the size of wire encoding a float64 value as a Double. |
| 4030 | func sizeDoubleValue(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4031 | return tagsize + wire.SizeFixed64() |
| 4032 | } |
| 4033 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4034 | // appendDoubleValue encodes a float64 value as a Double. |
| 4035 | func appendDoubleValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4036 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4037 | b = wire.AppendFixed64(b, math.Float64bits(v.Float())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4038 | return b, nil |
| 4039 | } |
| 4040 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4041 | // consumeDoubleValue decodes a float64 value as a Double. |
| 4042 | func consumeDoubleValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4043 | if wtyp != wire.Fixed64Type { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4044 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4045 | } |
| 4046 | v, n := wire.ConsumeFixed64(b) |
| 4047 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4048 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4049 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4050 | return protoreflect.ValueOfFloat64(math.Float64frombits(v)), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4051 | } |
| 4052 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4053 | var coderDoubleValue = valueCoderFuncs{ |
| 4054 | size: sizeDoubleValue, |
| 4055 | marshal: appendDoubleValue, |
| 4056 | unmarshal: consumeDoubleValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4057 | } |
| 4058 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4059 | // sizeDoubleSliceValue returns the size of wire encoding a []float64 value as a repeated Double. |
| 4060 | func sizeDoubleSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 4061 | list := listv.List() |
| 4062 | size = list.Len() * (tagsize + wire.SizeFixed64()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4063 | return size |
| 4064 | } |
| 4065 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4066 | // appendDoubleSliceValue encodes a []float64 value as a repeated Double. |
| 4067 | func appendDoubleSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4068 | list := listv.List() |
| 4069 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 4070 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4071 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4072 | b = wire.AppendFixed64(b, math.Float64bits(v.Float())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4073 | } |
| 4074 | return b, nil |
| 4075 | } |
| 4076 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4077 | // consumeDoubleSliceValue wire decodes a []float64 value as a repeated Double. |
| 4078 | func consumeDoubleSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 4079 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4080 | if wtyp == wire.BytesType { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4081 | b, n = wire.ConsumeBytes(b) |
| 4082 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4083 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4084 | } |
| 4085 | for len(b) > 0 { |
| 4086 | v, n := wire.ConsumeFixed64(b) |
| 4087 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4088 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4089 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4090 | list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v))) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4091 | b = b[n:] |
| 4092 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4093 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4094 | } |
| 4095 | if wtyp != wire.Fixed64Type { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4096 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4097 | } |
| 4098 | v, n := wire.ConsumeFixed64(b) |
| 4099 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4100 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4101 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4102 | list.Append(protoreflect.ValueOfFloat64(math.Float64frombits(v))) |
| 4103 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4104 | } |
| 4105 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4106 | var coderDoubleSliceValue = valueCoderFuncs{ |
| 4107 | size: sizeDoubleSliceValue, |
| 4108 | marshal: appendDoubleSliceValue, |
| 4109 | unmarshal: consumeDoubleSliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4110 | } |
| 4111 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4112 | // sizeDoublePackedSliceValue returns the size of wire encoding a []float64 value as a packed repeated Double. |
| 4113 | func sizeDoublePackedSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 4114 | list := listv.List() |
| 4115 | n := list.Len() * wire.SizeFixed64() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 4116 | return tagsize + wire.SizeBytes(n) |
| 4117 | } |
| 4118 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4119 | // appendDoublePackedSliceValue encodes a []float64 value as a packed repeated Double. |
| 4120 | func appendDoublePackedSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4121 | list := listv.List() |
| 4122 | llen := list.Len() |
| 4123 | if llen == 0 { |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 4124 | return b, nil |
| 4125 | } |
| 4126 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4127 | n := llen * wire.SizeFixed64() |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 4128 | b = wire.AppendVarint(b, uint64(n)) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4129 | for i := 0; i < llen; i++ { |
| 4130 | v := list.Get(i) |
| 4131 | b = wire.AppendFixed64(b, math.Float64bits(v.Float())) |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 4132 | } |
| 4133 | return b, nil |
| 4134 | } |
| 4135 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4136 | var coderDoublePackedSliceValue = valueCoderFuncs{ |
| 4137 | size: sizeDoublePackedSliceValue, |
| 4138 | marshal: appendDoublePackedSliceValue, |
| 4139 | unmarshal: consumeDoubleSliceValue, |
Damien Neil | 7492a09 | 2019-07-10 15:23:29 -0700 | [diff] [blame] | 4140 | } |
| 4141 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4142 | // sizeString returns the size of wire encoding a string pointer as a String. |
| 4143 | func sizeString(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4144 | v := *p.String() |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4145 | return tagsize + wire.SizeBytes(len(v)) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4146 | } |
| 4147 | |
| 4148 | // appendString wire encodes a string pointer as a String. |
| 4149 | func appendString(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4150 | v := *p.String() |
| 4151 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4152 | b = wire.AppendString(b, v) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4153 | return b, nil |
| 4154 | } |
| 4155 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4156 | // consumeString wire decodes a string pointer as a String. |
| 4157 | func consumeString(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4158 | if wtyp != wire.BytesType { |
| 4159 | return 0, errUnknown |
| 4160 | } |
| 4161 | v, n := wire.ConsumeString(b) |
| 4162 | if n < 0 { |
| 4163 | return 0, wire.ParseError(n) |
| 4164 | } |
| 4165 | *p.String() = v |
| 4166 | return n, nil |
| 4167 | } |
| 4168 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4169 | var coderString = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4170 | size: sizeString, |
| 4171 | marshal: appendString, |
| 4172 | unmarshal: consumeString, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4173 | } |
| 4174 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4175 | // appendStringValidateUTF8 wire encodes a string pointer as a String. |
| 4176 | func appendStringValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4177 | v := *p.String() |
| 4178 | b = wire.AppendVarint(b, wiretag) |
| 4179 | b = wire.AppendString(b, v) |
| 4180 | if !utf8.ValidString(v) { |
| 4181 | return b, errInvalidUTF8{} |
| 4182 | } |
| 4183 | return b, nil |
| 4184 | } |
| 4185 | |
| 4186 | // consumeStringValidateUTF8 wire decodes a string pointer as a String. |
| 4187 | func consumeStringValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4188 | if wtyp != wire.BytesType { |
| 4189 | return 0, errUnknown |
| 4190 | } |
| 4191 | v, n := wire.ConsumeString(b) |
| 4192 | if n < 0 { |
| 4193 | return 0, wire.ParseError(n) |
| 4194 | } |
| 4195 | if !utf8.ValidString(v) { |
| 4196 | return 0, errInvalidUTF8{} |
| 4197 | } |
| 4198 | *p.String() = v |
| 4199 | return n, nil |
| 4200 | } |
| 4201 | |
| 4202 | var coderStringValidateUTF8 = pointerCoderFuncs{ |
| 4203 | size: sizeString, |
| 4204 | marshal: appendStringValidateUTF8, |
| 4205 | unmarshal: consumeStringValidateUTF8, |
| 4206 | } |
| 4207 | |
| 4208 | // sizeStringNoZero returns the size of wire encoding a string pointer as a String. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4209 | // The zero value is not encoded. |
| 4210 | func sizeStringNoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4211 | v := *p.String() |
| 4212 | if len(v) == 0 { |
| 4213 | return 0 |
| 4214 | } |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4215 | return tagsize + wire.SizeBytes(len(v)) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4216 | } |
| 4217 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4218 | // appendStringNoZero wire encodes a string pointer as a String. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4219 | // The zero value is not encoded. |
| 4220 | func appendStringNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4221 | v := *p.String() |
| 4222 | if len(v) == 0 { |
| 4223 | return b, nil |
| 4224 | } |
| 4225 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4226 | b = wire.AppendString(b, v) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4227 | return b, nil |
| 4228 | } |
| 4229 | |
| 4230 | var coderStringNoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4231 | size: sizeStringNoZero, |
| 4232 | marshal: appendStringNoZero, |
| 4233 | unmarshal: consumeString, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4234 | } |
| 4235 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4236 | // appendStringNoZeroValidateUTF8 wire encodes a string pointer as a String. |
| 4237 | // The zero value is not encoded. |
| 4238 | func appendStringNoZeroValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4239 | v := *p.String() |
| 4240 | if len(v) == 0 { |
| 4241 | return b, nil |
| 4242 | } |
| 4243 | b = wire.AppendVarint(b, wiretag) |
| 4244 | b = wire.AppendString(b, v) |
| 4245 | if !utf8.ValidString(v) { |
| 4246 | return b, errInvalidUTF8{} |
| 4247 | } |
| 4248 | return b, nil |
| 4249 | } |
| 4250 | |
| 4251 | var coderStringNoZeroValidateUTF8 = pointerCoderFuncs{ |
| 4252 | size: sizeStringNoZero, |
| 4253 | marshal: appendStringNoZeroValidateUTF8, |
| 4254 | unmarshal: consumeStringValidateUTF8, |
| 4255 | } |
| 4256 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4257 | // sizeStringPtr returns the size of wire encoding a *string pointer as a String. |
| 4258 | // It panics if the pointer is nil. |
| 4259 | func sizeStringPtr(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4260 | v := **p.StringPtr() |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4261 | return tagsize + wire.SizeBytes(len(v)) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4262 | } |
| 4263 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4264 | // appendStringPtr wire encodes a *string pointer as a String. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4265 | // It panics if the pointer is nil. |
| 4266 | func appendStringPtr(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4267 | v := **p.StringPtr() |
| 4268 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4269 | b = wire.AppendString(b, v) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4270 | return b, nil |
| 4271 | } |
| 4272 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4273 | // consumeStringPtr wire decodes a *string pointer as a String. |
| 4274 | func consumeStringPtr(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4275 | if wtyp != wire.BytesType { |
| 4276 | return 0, errUnknown |
| 4277 | } |
| 4278 | v, n := wire.ConsumeString(b) |
| 4279 | if n < 0 { |
| 4280 | return 0, wire.ParseError(n) |
| 4281 | } |
| 4282 | vp := p.StringPtr() |
| 4283 | if *vp == nil { |
| 4284 | *vp = new(string) |
| 4285 | } |
| 4286 | **vp = v |
| 4287 | return n, nil |
| 4288 | } |
| 4289 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4290 | var coderStringPtr = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4291 | size: sizeStringPtr, |
| 4292 | marshal: appendStringPtr, |
| 4293 | unmarshal: consumeStringPtr, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4294 | } |
| 4295 | |
| 4296 | // sizeStringSlice returns the size of wire encoding a []string pointer as a repeated String. |
| 4297 | func sizeStringSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4298 | s := *p.StringSlice() |
| 4299 | for _, v := range s { |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4300 | size += tagsize + wire.SizeBytes(len(v)) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4301 | } |
| 4302 | return size |
| 4303 | } |
| 4304 | |
| 4305 | // appendStringSlice encodes a []string pointer as a repeated String. |
| 4306 | func appendStringSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4307 | s := *p.StringSlice() |
| 4308 | for _, v := range s { |
| 4309 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | cedb595 | 2019-06-21 12:04:07 -0700 | [diff] [blame] | 4310 | b = wire.AppendString(b, v) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4311 | } |
| 4312 | return b, nil |
| 4313 | } |
| 4314 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4315 | // consumeStringSlice wire decodes a []string pointer as a repeated String. |
| 4316 | func consumeStringSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4317 | sp := p.StringSlice() |
| 4318 | if wtyp != wire.BytesType { |
| 4319 | return 0, errUnknown |
| 4320 | } |
| 4321 | v, n := wire.ConsumeString(b) |
| 4322 | if n < 0 { |
| 4323 | return 0, wire.ParseError(n) |
| 4324 | } |
| 4325 | *sp = append(*sp, v) |
| 4326 | return n, nil |
| 4327 | } |
| 4328 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4329 | var coderStringSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4330 | size: sizeStringSlice, |
| 4331 | marshal: appendStringSlice, |
| 4332 | unmarshal: consumeStringSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4333 | } |
| 4334 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4335 | // appendStringSliceValidateUTF8 encodes a []string pointer as a repeated String. |
| 4336 | func appendStringSliceValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4337 | s := *p.StringSlice() |
| 4338 | for _, v := range s { |
| 4339 | b = wire.AppendVarint(b, wiretag) |
| 4340 | b = wire.AppendString(b, v) |
| 4341 | if !utf8.ValidString(v) { |
| 4342 | return b, errInvalidUTF8{} |
| 4343 | } |
| 4344 | } |
| 4345 | return b, nil |
| 4346 | } |
| 4347 | |
| 4348 | // consumeStringSliceValidateUTF8 wire decodes a []string pointer as a repeated String. |
| 4349 | func consumeStringSliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4350 | sp := p.StringSlice() |
| 4351 | if wtyp != wire.BytesType { |
| 4352 | return 0, errUnknown |
| 4353 | } |
| 4354 | v, n := wire.ConsumeString(b) |
| 4355 | if n < 0 { |
| 4356 | return 0, wire.ParseError(n) |
| 4357 | } |
| 4358 | if !utf8.ValidString(v) { |
| 4359 | return 0, errInvalidUTF8{} |
| 4360 | } |
| 4361 | *sp = append(*sp, v) |
| 4362 | return n, nil |
| 4363 | } |
| 4364 | |
| 4365 | var coderStringSliceValidateUTF8 = pointerCoderFuncs{ |
| 4366 | size: sizeStringSlice, |
| 4367 | marshal: appendStringSliceValidateUTF8, |
| 4368 | unmarshal: consumeStringSliceValidateUTF8, |
| 4369 | } |
| 4370 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4371 | // sizeStringValue returns the size of wire encoding a string value as a String. |
| 4372 | func sizeStringValue(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
| 4373 | return tagsize + wire.SizeBytes(len(v.String())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4374 | } |
| 4375 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4376 | // appendStringValue encodes a string value as a String. |
| 4377 | func appendStringValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4378 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4379 | b = wire.AppendString(b, v.String()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4380 | return b, nil |
| 4381 | } |
| 4382 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4383 | // consumeStringValue decodes a string value as a String. |
| 4384 | func consumeStringValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4385 | if wtyp != wire.BytesType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4386 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4387 | } |
| 4388 | v, n := wire.ConsumeString(b) |
| 4389 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4390 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4391 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4392 | return protoreflect.ValueOfString(string(v)), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4393 | } |
| 4394 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4395 | var coderStringValue = valueCoderFuncs{ |
| 4396 | size: sizeStringValue, |
| 4397 | marshal: appendStringValue, |
| 4398 | unmarshal: consumeStringValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4399 | } |
| 4400 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4401 | // appendStringValueValidateUTF8 encodes a string value as a String. |
| 4402 | func appendStringValueValidateUTF8(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4403 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4404 | b = wire.AppendString(b, v.String()) |
| 4405 | if !utf8.ValidString(v.String()) { |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4406 | return b, errInvalidUTF8{} |
| 4407 | } |
| 4408 | return b, nil |
| 4409 | } |
| 4410 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4411 | // consumeStringValueValidateUTF8 decodes a string value as a String. |
| 4412 | func consumeStringValueValidateUTF8(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4413 | if wtyp != wire.BytesType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4414 | return protoreflect.Value{}, 0, errUnknown |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4415 | } |
| 4416 | v, n := wire.ConsumeString(b) |
| 4417 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4418 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4419 | } |
| 4420 | if !utf8.ValidString(v) { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4421 | return protoreflect.Value{}, 0, errInvalidUTF8{} |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4422 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4423 | return protoreflect.ValueOfString(string(v)), n, nil |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4424 | } |
| 4425 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4426 | var coderStringValueValidateUTF8 = valueCoderFuncs{ |
| 4427 | size: sizeStringValue, |
| 4428 | marshal: appendStringValueValidateUTF8, |
| 4429 | unmarshal: consumeStringValueValidateUTF8, |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4430 | } |
| 4431 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4432 | // sizeStringSliceValue returns the size of wire encoding a []string value as a repeated String. |
| 4433 | func sizeStringSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 4434 | list := listv.List() |
| 4435 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 4436 | v := list.Get(i) |
| 4437 | size += tagsize + wire.SizeBytes(len(v.String())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4438 | } |
| 4439 | return size |
| 4440 | } |
| 4441 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4442 | // appendStringSliceValue encodes a []string value as a repeated String. |
| 4443 | func appendStringSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4444 | list := listv.List() |
| 4445 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 4446 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4447 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4448 | b = wire.AppendString(b, v.String()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4449 | } |
| 4450 | return b, nil |
| 4451 | } |
| 4452 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4453 | // consumeStringSliceValue wire decodes a []string value as a repeated String. |
| 4454 | func consumeStringSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 4455 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4456 | if wtyp != wire.BytesType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4457 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4458 | } |
| 4459 | v, n := wire.ConsumeString(b) |
| 4460 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4461 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4462 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4463 | list.Append(protoreflect.ValueOfString(string(v))) |
| 4464 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4465 | } |
| 4466 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4467 | var coderStringSliceValue = valueCoderFuncs{ |
| 4468 | size: sizeStringSliceValue, |
| 4469 | marshal: appendStringSliceValue, |
| 4470 | unmarshal: consumeStringSliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | // sizeBytes returns the size of wire encoding a []byte pointer as a Bytes. |
| 4474 | func sizeBytes(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4475 | v := *p.Bytes() |
| 4476 | return tagsize + wire.SizeBytes(len(v)) |
| 4477 | } |
| 4478 | |
| 4479 | // appendBytes wire encodes a []byte pointer as a Bytes. |
| 4480 | func appendBytes(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4481 | v := *p.Bytes() |
| 4482 | b = wire.AppendVarint(b, wiretag) |
| 4483 | b = wire.AppendBytes(b, v) |
| 4484 | return b, nil |
| 4485 | } |
| 4486 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4487 | // consumeBytes wire decodes a []byte pointer as a Bytes. |
| 4488 | func consumeBytes(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4489 | if wtyp != wire.BytesType { |
| 4490 | return 0, errUnknown |
| 4491 | } |
| 4492 | v, n := wire.ConsumeBytes(b) |
| 4493 | if n < 0 { |
| 4494 | return 0, wire.ParseError(n) |
| 4495 | } |
Damien Neil | 8003f08 | 2019-08-02 15:13:00 -0700 | [diff] [blame] | 4496 | *p.Bytes() = append(emptyBuf[:], v...) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4497 | return n, nil |
| 4498 | } |
| 4499 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4500 | var coderBytes = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4501 | size: sizeBytes, |
| 4502 | marshal: appendBytes, |
| 4503 | unmarshal: consumeBytes, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4504 | } |
| 4505 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4506 | // appendBytesValidateUTF8 wire encodes a []byte pointer as a Bytes. |
| 4507 | func appendBytesValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4508 | v := *p.Bytes() |
| 4509 | b = wire.AppendVarint(b, wiretag) |
| 4510 | b = wire.AppendBytes(b, v) |
| 4511 | if !utf8.Valid(v) { |
| 4512 | return b, errInvalidUTF8{} |
| 4513 | } |
| 4514 | return b, nil |
| 4515 | } |
| 4516 | |
| 4517 | // consumeBytesValidateUTF8 wire decodes a []byte pointer as a Bytes. |
| 4518 | func consumeBytesValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4519 | if wtyp != wire.BytesType { |
| 4520 | return 0, errUnknown |
| 4521 | } |
| 4522 | v, n := wire.ConsumeBytes(b) |
| 4523 | if n < 0 { |
| 4524 | return 0, wire.ParseError(n) |
| 4525 | } |
| 4526 | if !utf8.Valid(v) { |
| 4527 | return 0, errInvalidUTF8{} |
| 4528 | } |
Damien Neil | 8003f08 | 2019-08-02 15:13:00 -0700 | [diff] [blame] | 4529 | *p.Bytes() = append(emptyBuf[:], v...) |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4530 | return n, nil |
| 4531 | } |
| 4532 | |
| 4533 | var coderBytesValidateUTF8 = pointerCoderFuncs{ |
| 4534 | size: sizeBytes, |
| 4535 | marshal: appendBytesValidateUTF8, |
| 4536 | unmarshal: consumeBytesValidateUTF8, |
| 4537 | } |
| 4538 | |
| 4539 | // sizeBytesNoZero returns the size of wire encoding a []byte pointer as a Bytes. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4540 | // The zero value is not encoded. |
| 4541 | func sizeBytesNoZero(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4542 | v := *p.Bytes() |
| 4543 | if len(v) == 0 { |
| 4544 | return 0 |
| 4545 | } |
| 4546 | return tagsize + wire.SizeBytes(len(v)) |
| 4547 | } |
| 4548 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4549 | // appendBytesNoZero wire encodes a []byte pointer as a Bytes. |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4550 | // The zero value is not encoded. |
| 4551 | func appendBytesNoZero(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4552 | v := *p.Bytes() |
| 4553 | if len(v) == 0 { |
| 4554 | return b, nil |
| 4555 | } |
| 4556 | b = wire.AppendVarint(b, wiretag) |
| 4557 | b = wire.AppendBytes(b, v) |
| 4558 | return b, nil |
| 4559 | } |
| 4560 | |
Damien Neil | 8003f08 | 2019-08-02 15:13:00 -0700 | [diff] [blame] | 4561 | // consumeBytesNoZero wire decodes a []byte pointer as a Bytes. |
| 4562 | // The zero value is not decoded. |
| 4563 | func consumeBytesNoZero(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4564 | if wtyp != wire.BytesType { |
| 4565 | return 0, errUnknown |
| 4566 | } |
| 4567 | v, n := wire.ConsumeBytes(b) |
| 4568 | if n < 0 { |
| 4569 | return 0, wire.ParseError(n) |
| 4570 | } |
| 4571 | *p.Bytes() = append(([]byte)(nil), v...) |
| 4572 | return n, nil |
| 4573 | } |
| 4574 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4575 | var coderBytesNoZero = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4576 | size: sizeBytesNoZero, |
| 4577 | marshal: appendBytesNoZero, |
Damien Neil | 8003f08 | 2019-08-02 15:13:00 -0700 | [diff] [blame] | 4578 | unmarshal: consumeBytesNoZero, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4579 | } |
| 4580 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4581 | // appendBytesNoZeroValidateUTF8 wire encodes a []byte pointer as a Bytes. |
| 4582 | // The zero value is not encoded. |
| 4583 | func appendBytesNoZeroValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4584 | v := *p.Bytes() |
| 4585 | if len(v) == 0 { |
| 4586 | return b, nil |
| 4587 | } |
| 4588 | b = wire.AppendVarint(b, wiretag) |
| 4589 | b = wire.AppendBytes(b, v) |
| 4590 | if !utf8.Valid(v) { |
| 4591 | return b, errInvalidUTF8{} |
| 4592 | } |
| 4593 | return b, nil |
| 4594 | } |
| 4595 | |
Damien Neil | 8003f08 | 2019-08-02 15:13:00 -0700 | [diff] [blame] | 4596 | // consumeBytesNoZeroValidateUTF8 wire decodes a []byte pointer as a Bytes. |
| 4597 | func consumeBytesNoZeroValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4598 | if wtyp != wire.BytesType { |
| 4599 | return 0, errUnknown |
| 4600 | } |
| 4601 | v, n := wire.ConsumeBytes(b) |
| 4602 | if n < 0 { |
| 4603 | return 0, wire.ParseError(n) |
| 4604 | } |
| 4605 | if !utf8.Valid(v) { |
| 4606 | return 0, errInvalidUTF8{} |
| 4607 | } |
| 4608 | *p.Bytes() = append(([]byte)(nil), v...) |
| 4609 | return n, nil |
| 4610 | } |
| 4611 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4612 | var coderBytesNoZeroValidateUTF8 = pointerCoderFuncs{ |
| 4613 | size: sizeBytesNoZero, |
| 4614 | marshal: appendBytesNoZeroValidateUTF8, |
Damien Neil | 8003f08 | 2019-08-02 15:13:00 -0700 | [diff] [blame] | 4615 | unmarshal: consumeBytesNoZeroValidateUTF8, |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4616 | } |
| 4617 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4618 | // sizeBytesSlice returns the size of wire encoding a [][]byte pointer as a repeated Bytes. |
| 4619 | func sizeBytesSlice(p pointer, tagsize int, _ marshalOptions) (size int) { |
| 4620 | s := *p.BytesSlice() |
| 4621 | for _, v := range s { |
| 4622 | size += tagsize + wire.SizeBytes(len(v)) |
| 4623 | } |
| 4624 | return size |
| 4625 | } |
| 4626 | |
| 4627 | // appendBytesSlice encodes a [][]byte pointer as a repeated Bytes. |
| 4628 | func appendBytesSlice(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4629 | s := *p.BytesSlice() |
| 4630 | for _, v := range s { |
| 4631 | b = wire.AppendVarint(b, wiretag) |
| 4632 | b = wire.AppendBytes(b, v) |
| 4633 | } |
| 4634 | return b, nil |
| 4635 | } |
| 4636 | |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4637 | // consumeBytesSlice wire decodes a [][]byte pointer as a repeated Bytes. |
| 4638 | func consumeBytesSlice(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4639 | sp := p.BytesSlice() |
| 4640 | if wtyp != wire.BytesType { |
| 4641 | return 0, errUnknown |
| 4642 | } |
| 4643 | v, n := wire.ConsumeBytes(b) |
| 4644 | if n < 0 { |
| 4645 | return 0, wire.ParseError(n) |
| 4646 | } |
Damien Neil | 8003f08 | 2019-08-02 15:13:00 -0700 | [diff] [blame] | 4647 | *sp = append(*sp, append(emptyBuf[:], v...)) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4648 | return n, nil |
| 4649 | } |
| 4650 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4651 | var coderBytesSlice = pointerCoderFuncs{ |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4652 | size: sizeBytesSlice, |
| 4653 | marshal: appendBytesSlice, |
| 4654 | unmarshal: consumeBytesSlice, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4655 | } |
| 4656 | |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4657 | // appendBytesSliceValidateUTF8 encodes a [][]byte pointer as a repeated Bytes. |
| 4658 | func appendBytesSliceValidateUTF8(b []byte, p pointer, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4659 | s := *p.BytesSlice() |
| 4660 | for _, v := range s { |
| 4661 | b = wire.AppendVarint(b, wiretag) |
| 4662 | b = wire.AppendBytes(b, v) |
| 4663 | if !utf8.Valid(v) { |
| 4664 | return b, errInvalidUTF8{} |
| 4665 | } |
| 4666 | } |
| 4667 | return b, nil |
| 4668 | } |
| 4669 | |
| 4670 | // consumeBytesSliceValidateUTF8 wire decodes a [][]byte pointer as a repeated Bytes. |
| 4671 | func consumeBytesSliceValidateUTF8(b []byte, p pointer, wtyp wire.Type, _ unmarshalOptions) (n int, err error) { |
| 4672 | sp := p.BytesSlice() |
| 4673 | if wtyp != wire.BytesType { |
| 4674 | return 0, errUnknown |
| 4675 | } |
| 4676 | v, n := wire.ConsumeBytes(b) |
| 4677 | if n < 0 { |
| 4678 | return 0, wire.ParseError(n) |
| 4679 | } |
| 4680 | if !utf8.Valid(v) { |
| 4681 | return 0, errInvalidUTF8{} |
| 4682 | } |
Damien Neil | 8003f08 | 2019-08-02 15:13:00 -0700 | [diff] [blame] | 4683 | *sp = append(*sp, append(emptyBuf[:], v...)) |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4684 | return n, nil |
| 4685 | } |
| 4686 | |
| 4687 | var coderBytesSliceValidateUTF8 = pointerCoderFuncs{ |
| 4688 | size: sizeBytesSlice, |
| 4689 | marshal: appendBytesSliceValidateUTF8, |
| 4690 | unmarshal: consumeBytesSliceValidateUTF8, |
| 4691 | } |
| 4692 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4693 | // sizeBytesValue returns the size of wire encoding a []byte value as a Bytes. |
| 4694 | func sizeBytesValue(v protoreflect.Value, tagsize int, _ marshalOptions) int { |
| 4695 | return tagsize + wire.SizeBytes(len(v.Bytes())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4696 | } |
| 4697 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4698 | // appendBytesValue encodes a []byte value as a Bytes. |
| 4699 | func appendBytesValue(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4700 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4701 | b = wire.AppendBytes(b, v.Bytes()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4702 | return b, nil |
| 4703 | } |
| 4704 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4705 | // consumeBytesValue decodes a []byte value as a Bytes. |
| 4706 | func consumeBytesValue(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4707 | if wtyp != wire.BytesType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4708 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4709 | } |
| 4710 | v, n := wire.ConsumeBytes(b) |
| 4711 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4712 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4713 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4714 | return protoreflect.ValueOfBytes(append(([]byte)(nil), v...)), n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4715 | } |
| 4716 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4717 | var coderBytesValue = valueCoderFuncs{ |
| 4718 | size: sizeBytesValue, |
| 4719 | marshal: appendBytesValue, |
| 4720 | unmarshal: consumeBytesValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4721 | } |
| 4722 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4723 | // appendBytesValueValidateUTF8 encodes a []byte value as a Bytes. |
| 4724 | func appendBytesValueValidateUTF8(b []byte, v protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4725 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4726 | b = wire.AppendBytes(b, v.Bytes()) |
| 4727 | if !utf8.Valid(v.Bytes()) { |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4728 | return b, errInvalidUTF8{} |
| 4729 | } |
| 4730 | return b, nil |
| 4731 | } |
| 4732 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4733 | // consumeBytesValueValidateUTF8 decodes a []byte value as a Bytes. |
| 4734 | func consumeBytesValueValidateUTF8(b []byte, _ protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (protoreflect.Value, int, error) { |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4735 | if wtyp != wire.BytesType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4736 | return protoreflect.Value{}, 0, errUnknown |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4737 | } |
| 4738 | v, n := wire.ConsumeBytes(b) |
| 4739 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4740 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4741 | } |
| 4742 | if !utf8.Valid(v) { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4743 | return protoreflect.Value{}, 0, errInvalidUTF8{} |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4744 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4745 | return protoreflect.ValueOfBytes(append(([]byte)(nil), v...)), n, nil |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4746 | } |
| 4747 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4748 | var coderBytesValueValidateUTF8 = valueCoderFuncs{ |
| 4749 | size: sizeBytesValue, |
| 4750 | marshal: appendBytesValueValidateUTF8, |
| 4751 | unmarshal: consumeBytesValueValidateUTF8, |
Joe Tsai | c51e2e0 | 2019-07-13 00:44:41 -0700 | [diff] [blame] | 4752 | } |
| 4753 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4754 | // sizeBytesSliceValue returns the size of wire encoding a [][]byte value as a repeated Bytes. |
| 4755 | func sizeBytesSliceValue(listv protoreflect.Value, tagsize int, _ marshalOptions) (size int) { |
| 4756 | list := listv.List() |
| 4757 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 4758 | v := list.Get(i) |
| 4759 | size += tagsize + wire.SizeBytes(len(v.Bytes())) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4760 | } |
| 4761 | return size |
| 4762 | } |
| 4763 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4764 | // appendBytesSliceValue encodes a [][]byte value as a repeated Bytes. |
| 4765 | func appendBytesSliceValue(b []byte, listv protoreflect.Value, wiretag uint64, _ marshalOptions) ([]byte, error) { |
| 4766 | list := listv.List() |
| 4767 | for i, llen := 0, list.Len(); i < llen; i++ { |
| 4768 | v := list.Get(i) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4769 | b = wire.AppendVarint(b, wiretag) |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4770 | b = wire.AppendBytes(b, v.Bytes()) |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4771 | } |
| 4772 | return b, nil |
| 4773 | } |
| 4774 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4775 | // consumeBytesSliceValue wire decodes a [][]byte value as a repeated Bytes. |
| 4776 | func consumeBytesSliceValue(b []byte, listv protoreflect.Value, _ wire.Number, wtyp wire.Type, _ unmarshalOptions) (_ protoreflect.Value, n int, err error) { |
| 4777 | list := listv.List() |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4778 | if wtyp != wire.BytesType { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4779 | return protoreflect.Value{}, 0, errUnknown |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4780 | } |
| 4781 | v, n := wire.ConsumeBytes(b) |
| 4782 | if n < 0 { |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4783 | return protoreflect.Value{}, 0, wire.ParseError(n) |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4784 | } |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4785 | list.Append(protoreflect.ValueOfBytes(append(([]byte)(nil), v...))) |
| 4786 | return listv, n, nil |
Damien Neil | e91877d | 2019-06-27 10:54:42 -0700 | [diff] [blame] | 4787 | } |
| 4788 | |
Damien Neil | 68b81c3 | 2019-08-22 11:41:32 -0700 | [diff] [blame^] | 4789 | var coderBytesSliceValue = valueCoderFuncs{ |
| 4790 | size: sizeBytesSliceValue, |
| 4791 | marshal: appendBytesSliceValue, |
| 4792 | unmarshal: consumeBytesSliceValue, |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4793 | } |
| 4794 | |
Damien Neil | 8003f08 | 2019-08-02 15:13:00 -0700 | [diff] [blame] | 4795 | // We append to an empty array rather than a nil []byte to get non-nil zero-length byte slices. |
| 4796 | var emptyBuf [0]byte |
| 4797 | |
Damien Neil | c37adef | 2019-04-01 13:49:56 -0700 | [diff] [blame] | 4798 | var wireTypes = map[protoreflect.Kind]wire.Type{ |
| 4799 | protoreflect.BoolKind: wire.VarintType, |
| 4800 | protoreflect.EnumKind: wire.VarintType, |
| 4801 | protoreflect.Int32Kind: wire.VarintType, |
| 4802 | protoreflect.Sint32Kind: wire.VarintType, |
| 4803 | protoreflect.Uint32Kind: wire.VarintType, |
| 4804 | protoreflect.Int64Kind: wire.VarintType, |
| 4805 | protoreflect.Sint64Kind: wire.VarintType, |
| 4806 | protoreflect.Uint64Kind: wire.VarintType, |
| 4807 | protoreflect.Sfixed32Kind: wire.Fixed32Type, |
| 4808 | protoreflect.Fixed32Kind: wire.Fixed32Type, |
| 4809 | protoreflect.FloatKind: wire.Fixed32Type, |
| 4810 | protoreflect.Sfixed64Kind: wire.Fixed64Type, |
| 4811 | protoreflect.Fixed64Kind: wire.Fixed64Type, |
| 4812 | protoreflect.DoubleKind: wire.Fixed64Type, |
| 4813 | protoreflect.StringKind: wire.BytesType, |
| 4814 | protoreflect.BytesKind: wire.BytesType, |
| 4815 | protoreflect.MessageKind: wire.BytesType, |
| 4816 | protoreflect.GroupKind: wire.StartGroupType, |
| 4817 | } |