| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
// Code generated by "internal/cmd/pdatagen/main.go". DO NOT EDIT. |
| 5 |
// To regenerate this file run "make genpdata". |
| 6 |
|
| 7 |
package internal |
| 8 |
|
| 9 |
import ( |
| 10 |
"fmt" |
| 11 |
"sync" |
| 12 |
|
| 13 |
"go.opentelemetry.io/collector/pdata/internal/json" |
| 14 |
"go.opentelemetry.io/collector/pdata/internal/proto" |
| 15 |
) |
| 16 |
|
| 17 |
type IPAddr struct { |
| 18 |
IP []byte |
| 19 |
Zone string |
| 20 |
} |
| 21 |
|
| 22 |
var ( |
| 23 |
protoPoolIPAddr = sync.Pool{ |
| 24 |
New: func() any { |
| 25 |
return &IPAddr{} |
| 26 |
}, |
| 27 |
} |
| 28 |
) |
| 29 |
|
| 30 |
func NewIPAddr() *IPAddr { |
| 31 |
if !UseProtoPooling.IsEnabled() { |
| 32 |
return &IPAddr{} |
| 33 |
} |
| 34 |
return protoPoolIPAddr.Get().(*IPAddr) |
| 35 |
} |
| 36 |
|
| 37 |
func DeleteIPAddr(orig *IPAddr, nullable bool) { |
| 38 |
if orig == nil { |
| 39 |
return |
| 40 |
} |
| 41 |
|
| 42 |
if !UseProtoPooling.IsEnabled() { |
| 43 |
orig.Reset() |
| 44 |
return |
| 45 |
} |
| 46 |
|
| 47 |
orig.Reset() |
| 48 |
if nullable { |
| 49 |
protoPoolIPAddr.Put(orig) |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
func CopyIPAddr(dest, src *IPAddr) *IPAddr { |
| 54 |
// If copying to same object, just return. |
| 55 |
if src == dest { |
| 56 |
return dest |
| 57 |
} |
| 58 |
|
| 59 |
if src == nil { |
| 60 |
return nil |
| 61 |
} |
| 62 |
|
| 63 |
if dest == nil { |
| 64 |
dest = NewIPAddr() |
| 65 |
} |
| 66 |
dest.IP = src.IP |
| 67 |
|
| 68 |
dest.Zone = src.Zone |
| 69 |
|
| 70 |
return dest |
| 71 |
} |
| 72 |
|
| 73 |
func CopyIPAddrSlice(dest, src []IPAddr) []IPAddr { |
| 74 |
var newDest []IPAddr |
| 75 |
if cap(dest) < len(src) { |
| 76 |
newDest = make([]IPAddr, len(src)) |
| 77 |
} else { |
| 78 |
newDest = dest[:len(src)] |
| 79 |
// Cleanup the rest of the elements so GC can free the memory. |
| 80 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 81 |
for i := len(src); i < len(dest); i++ { |
| 82 |
DeleteIPAddr(&dest[i], false) |
| 83 |
} |
| 84 |
} |
| 85 |
for i := range src { |
| 86 |
CopyIPAddr(&newDest[i], &src[i]) |
| 87 |
} |
| 88 |
return newDest |
| 89 |
} |
| 90 |
|
| 91 |
func CopyIPAddrPtrSlice(dest, src []*IPAddr) []*IPAddr { |
| 92 |
var newDest []*IPAddr |
| 93 |
if cap(dest) < len(src) { |
| 94 |
newDest = make([]*IPAddr, len(src)) |
| 95 |
// Copy old pointers to re-use. |
| 96 |
copy(newDest, dest) |
| 97 |
// Add new pointers for missing elements from len(dest) to len(srt). |
| 98 |
for i := len(dest); i < len(src); i++ { |
| 99 |
newDest[i] = NewIPAddr() |
| 100 |
} |
| 101 |
} else { |
| 102 |
newDest = dest[:len(src)] |
| 103 |
// Cleanup the rest of the elements so GC can free the memory. |
| 104 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 105 |
for i := len(src); i < len(dest); i++ { |
| 106 |
DeleteIPAddr(dest[i], true) |
| 107 |
dest[i] = nil |
| 108 |
} |
| 109 |
// Add new pointers for missing elements. |
| 110 |
// This can happen when len(dest) < len(src) < cap(dest). |
| 111 |
for i := len(dest); i < len(src); i++ { |
| 112 |
newDest[i] = NewIPAddr() |
| 113 |
} |
| 114 |
} |
| 115 |
for i := range src { |
| 116 |
CopyIPAddr(newDest[i], src[i]) |
| 117 |
} |
| 118 |
return newDest |
| 119 |
} |
| 120 |
|
| 121 |
func (orig *IPAddr) Reset() { |
| 122 |
*orig = IPAddr{} |
| 123 |
} |
| 124 |
|
| 125 |
// MarshalJSON marshals all properties from the current struct to the destination stream. |
| 126 |
func (orig *IPAddr) MarshalJSON(dest *json.Stream) { |
| 127 |
dest.WriteObjectStart() |
| 128 |
|
| 129 |
if len(orig.IP) > 0 { |
| 130 |
dest.WriteObjectField("iP") |
| 131 |
dest.WriteBytes(orig.IP) |
| 132 |
} |
| 133 |
if orig.Zone != "" { |
| 134 |
dest.WriteObjectField("zone") |
| 135 |
dest.WriteString(orig.Zone) |
| 136 |
} |
| 137 |
dest.WriteObjectEnd() |
| 138 |
} |
| 139 |
|
| 140 |
// UnmarshalJSON unmarshals all properties from the current struct from the source iterator. |
| 141 |
func (orig *IPAddr) UnmarshalJSON(iter *json.Iterator) { |
| 142 |
for f := iter.ReadObject(); f != ""; f = iter.ReadObject() { |
| 143 |
switch f { |
| 144 |
case "iP": |
| 145 |
orig.IP = iter.ReadBytes() |
| 146 |
case "zone": |
| 147 |
orig.Zone = iter.ReadString() |
| 148 |
default: |
| 149 |
iter.Skip() |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
func (orig *IPAddr) SizeProto() int { |
| 155 |
var n int |
| 156 |
var l int |
| 157 |
_ = l |
| 158 |
l = len(orig.IP) |
| 159 |
if l > 0 { |
| 160 |
n += 1 + proto.Sov(uint64(l)) + l |
| 161 |
} |
| 162 |
l = len(orig.Zone) |
| 163 |
if l > 0 { |
| 164 |
n += 1 + proto.Sov(uint64(l)) + l |
| 165 |
} |
| 166 |
return n |
| 167 |
} |
| 168 |
|
| 169 |
func (orig *IPAddr) MarshalProto(buf []byte) int { |
| 170 |
pos := len(buf) |
| 171 |
var l int |
| 172 |
_ = l |
| 173 |
l = len(orig.IP) |
| 174 |
if l > 0 { |
| 175 |
pos -= l |
| 176 |
copy(buf[pos:], orig.IP) |
| 177 |
pos = proto.EncodeVarint(buf, pos, uint64(l)) |
| 178 |
pos-- |
| 179 |
buf[pos] = 0xa |
| 180 |
} |
| 181 |
l = len(orig.Zone) |
| 182 |
if l > 0 { |
| 183 |
pos -= l |
| 184 |
copy(buf[pos:], orig.Zone) |
| 185 |
pos = proto.EncodeVarint(buf, pos, uint64(l)) |
| 186 |
pos-- |
| 187 |
buf[pos] = 0x12 |
| 188 |
} |
| 189 |
return len(buf) - pos |
| 190 |
} |
| 191 |
|
| 192 |
func (orig *IPAddr) UnmarshalProto(buf []byte) error { |
| 193 |
var err error |
| 194 |
var fieldNum int32 |
| 195 |
var wireType proto.WireType |
| 196 |
|
| 197 |
l := len(buf) |
| 198 |
pos := 0 |
| 199 |
for pos < l { |
| 200 |
// If in a group parsing, move to the next tag. |
| 201 |
fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos) |
| 202 |
if err != nil { |
| 203 |
return err |
| 204 |
} |
| 205 |
switch fieldNum { |
| 206 |
|
| 207 |
case 1: |
| 208 |
if wireType != proto.WireTypeLen { |
| 209 |
return fmt.Errorf("proto: wrong wireType = %d for field IP", wireType) |
| 210 |
} |
| 211 |
var length int |
| 212 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 213 |
if err != nil { |
| 214 |
return err |
| 215 |
} |
| 216 |
startPos := pos - length |
| 217 |
if length != 0 { |
| 218 |
orig.IP = make([]byte, length) |
| 219 |
copy(orig.IP, buf[startPos:pos]) |
| 220 |
} |
| 221 |
|
| 222 |
case 2: |
| 223 |
if wireType != proto.WireTypeLen { |
| 224 |
return fmt.Errorf("proto: wrong wireType = %d for field Zone", wireType) |
| 225 |
} |
| 226 |
var length int |
| 227 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 228 |
if err != nil { |
| 229 |
return err |
| 230 |
} |
| 231 |
startPos := pos - length |
| 232 |
orig.Zone = string(buf[startPos:pos]) |
| 233 |
default: |
| 234 |
pos, err = proto.ConsumeUnknown(buf, pos, wireType) |
| 235 |
if err != nil { |
| 236 |
return err |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
return nil |
| 241 |
} |
| 242 |
|
| 243 |
func GenTestIPAddr() *IPAddr { |
| 244 |
orig := NewIPAddr() |
| 245 |
orig.IP = []byte{1, 2, 3} |
| 246 |
orig.Zone = "test_zone" |
| 247 |
return orig |
| 248 |
} |
| 249 |
|
| 250 |
func GenTestIPAddrPtrSlice() []*IPAddr { |
| 251 |
orig := make([]*IPAddr, 5) |
| 252 |
orig[0] = NewIPAddr() |
| 253 |
orig[1] = GenTestIPAddr() |
| 254 |
orig[2] = NewIPAddr() |
| 255 |
orig[3] = GenTestIPAddr() |
| 256 |
orig[4] = NewIPAddr() |
| 257 |
return orig |
| 258 |
} |
| 259 |
|
| 260 |
func GenTestIPAddrSlice() []IPAddr { |
| 261 |
orig := make([]IPAddr, 5) |
| 262 |
orig[1] = *GenTestIPAddr() |
| 263 |
orig[3] = *GenTestIPAddr() |
| 264 |
return orig |
| 265 |
} |