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