| 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 |
"encoding/binary" |
| 11 |
"fmt" |
| 12 |
"sync" |
| 13 |
|
| 14 |
"go.opentelemetry.io/collector/pdata/internal/json" |
| 15 |
"go.opentelemetry.io/collector/pdata/internal/proto" |
| 16 |
) |
| 17 |
|
| 18 |
type LogsRequest struct { |
| 19 |
RequestContext *RequestContext |
| 20 |
LogsData LogsData |
| 21 |
FormatVersion uint32 |
| 22 |
} |
| 23 |
|
| 24 |
var ( |
| 25 |
protoPoolLogsRequest = sync.Pool{ |
| 26 |
New: func() any { |
| 27 |
return &LogsRequest{} |
| 28 |
}, |
| 29 |
} |
| 30 |
) |
| 31 |
|
| 32 |
func NewLogsRequest() *LogsRequest { |
| 33 |
if !UseProtoPooling.IsEnabled() { |
| 34 |
return &LogsRequest{} |
| 35 |
} |
| 36 |
return protoPoolLogsRequest.Get().(*LogsRequest) |
| 37 |
} |
| 38 |
|
| 39 |
func DeleteLogsRequest(orig *LogsRequest, nullable bool) { |
| 40 |
if orig == nil { |
| 41 |
return |
| 42 |
} |
| 43 |
|
| 44 |
if !UseProtoPooling.IsEnabled() { |
| 45 |
orig.Reset() |
| 46 |
return |
| 47 |
} |
| 48 |
|
| 49 |
DeleteRequestContext(orig.RequestContext, true) |
| 50 |
DeleteLogsData(&orig.LogsData, false) |
| 51 |
|
| 52 |
orig.Reset() |
| 53 |
if nullable { |
| 54 |
protoPoolLogsRequest.Put(orig) |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
func CopyLogsRequest(dest, src *LogsRequest) *LogsRequest { |
| 59 |
// If copying to same object, just return. |
| 60 |
if src == dest { |
| 61 |
return dest |
| 62 |
} |
| 63 |
|
| 64 |
if src == nil { |
| 65 |
return nil |
| 66 |
} |
| 67 |
|
| 68 |
if dest == nil { |
| 69 |
dest = NewLogsRequest() |
| 70 |
} |
| 71 |
dest.RequestContext = CopyRequestContext(dest.RequestContext, src.RequestContext) |
| 72 |
|
| 73 |
CopyLogsData(&dest.LogsData, &src.LogsData) |
| 74 |
|
| 75 |
dest.FormatVersion = src.FormatVersion |
| 76 |
|
| 77 |
return dest |
| 78 |
} |
| 79 |
|
| 80 |
func CopyLogsRequestSlice(dest, src []LogsRequest) []LogsRequest { |
| 81 |
var newDest []LogsRequest |
| 82 |
if cap(dest) < len(src) { |
| 83 |
newDest = make([]LogsRequest, len(src)) |
| 84 |
} else { |
| 85 |
newDest = dest[:len(src)] |
| 86 |
// Cleanup the rest of the elements so GC can free the memory. |
| 87 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 88 |
for i := len(src); i < len(dest); i++ { |
| 89 |
DeleteLogsRequest(&dest[i], false) |
| 90 |
} |
| 91 |
} |
| 92 |
for i := range src { |
| 93 |
CopyLogsRequest(&newDest[i], &src[i]) |
| 94 |
} |
| 95 |
return newDest |
| 96 |
} |
| 97 |
|
| 98 |
func CopyLogsRequestPtrSlice(dest, src []*LogsRequest) []*LogsRequest { |
| 99 |
var newDest []*LogsRequest |
| 100 |
if cap(dest) < len(src) { |
| 101 |
newDest = make([]*LogsRequest, len(src)) |
| 102 |
// Copy old pointers to re-use. |
| 103 |
copy(newDest, dest) |
| 104 |
// Add new pointers for missing elements from len(dest) to len(srt). |
| 105 |
for i := len(dest); i < len(src); i++ { |
| 106 |
newDest[i] = NewLogsRequest() |
| 107 |
} |
| 108 |
} else { |
| 109 |
newDest = dest[:len(src)] |
| 110 |
// Cleanup the rest of the elements so GC can free the memory. |
| 111 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 112 |
for i := len(src); i < len(dest); i++ { |
| 113 |
DeleteLogsRequest(dest[i], true) |
| 114 |
dest[i] = nil |
| 115 |
} |
| 116 |
// Add new pointers for missing elements. |
| 117 |
// This can happen when len(dest) < len(src) < cap(dest). |
| 118 |
for i := len(dest); i < len(src); i++ { |
| 119 |
newDest[i] = NewLogsRequest() |
| 120 |
} |
| 121 |
} |
| 122 |
for i := range src { |
| 123 |
CopyLogsRequest(newDest[i], src[i]) |
| 124 |
} |
| 125 |
return newDest |
| 126 |
} |
| 127 |
|
| 128 |
func (orig *LogsRequest) Reset() { |
| 129 |
*orig = LogsRequest{} |
| 130 |
} |
| 131 |
|
| 132 |
// MarshalJSON marshals all properties from the current struct to the destination stream. |
| 133 |
func (orig *LogsRequest) MarshalJSON(dest *json.Stream) { |
| 134 |
dest.WriteObjectStart() |
| 135 |
if orig.RequestContext != nil { |
| 136 |
dest.WriteObjectField("requestContext") |
| 137 |
orig.RequestContext.MarshalJSON(dest) |
| 138 |
} |
| 139 |
dest.WriteObjectField("logsData") |
| 140 |
orig.LogsData.MarshalJSON(dest) |
| 141 |
if orig.FormatVersion != uint32(0) { |
| 142 |
dest.WriteObjectField("formatVersion") |
| 143 |
dest.WriteUint32(orig.FormatVersion) |
| 144 |
} |
| 145 |
dest.WriteObjectEnd() |
| 146 |
} |
| 147 |
|
| 148 |
// UnmarshalJSON unmarshals all properties from the current struct from the source iterator. |
| 149 |
func (orig *LogsRequest) UnmarshalJSON(iter *json.Iterator) { |
| 150 |
for f := iter.ReadObject(); f != ""; f = iter.ReadObject() { |
| 151 |
switch f { |
| 152 |
case "requestContext", "request_context": |
| 153 |
orig.RequestContext = NewRequestContext() |
| 154 |
orig.RequestContext.UnmarshalJSON(iter) |
| 155 |
case "logsData", "logs_data": |
| 156 |
|
| 157 |
orig.LogsData.UnmarshalJSON(iter) |
| 158 |
case "formatVersion", "format_version": |
| 159 |
orig.FormatVersion = iter.ReadUint32() |
| 160 |
default: |
| 161 |
iter.Skip() |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
func (orig *LogsRequest) SizeProto() int { |
| 167 |
var n int |
| 168 |
var l int |
| 169 |
_ = l |
| 170 |
if orig.RequestContext != nil { |
| 171 |
l = orig.RequestContext.SizeProto() |
| 172 |
n += 1 + proto.Sov(uint64(l)) + l |
| 173 |
} |
| 174 |
l = orig.LogsData.SizeProto() |
| 175 |
n += 1 + proto.Sov(uint64(l)) + l |
| 176 |
if orig.FormatVersion != 0 { |
| 177 |
n += 5 |
| 178 |
} |
| 179 |
return n |
| 180 |
} |
| 181 |
|
| 182 |
func (orig *LogsRequest) MarshalProto(buf []byte) int { |
| 183 |
pos := len(buf) |
| 184 |
var l int |
| 185 |
_ = l |
| 186 |
if orig.RequestContext != nil { |
| 187 |
l = orig.RequestContext.MarshalProto(buf[:pos]) |
| 188 |
pos -= l |
| 189 |
pos = proto.EncodeVarint(buf, pos, uint64(l)) |
| 190 |
pos-- |
| 191 |
buf[pos] = 0x12 |
| 192 |
} |
| 193 |
l = orig.LogsData.MarshalProto(buf[:pos]) |
| 194 |
pos -= l |
| 195 |
pos = proto.EncodeVarint(buf, pos, uint64(l)) |
| 196 |
pos-- |
| 197 |
buf[pos] = 0x1a |
| 198 |
|
| 199 |
if orig.FormatVersion != 0 { |
| 200 |
pos -= 4 |
| 201 |
binary.LittleEndian.PutUint32(buf[pos:], uint32(orig.FormatVersion)) |
| 202 |
pos-- |
| 203 |
buf[pos] = 0xd |
| 204 |
} |
| 205 |
return len(buf) - pos |
| 206 |
} |
| 207 |
|
| 208 |
func (orig *LogsRequest) UnmarshalProto(buf []byte) error { |
| 209 |
var err error |
| 210 |
var fieldNum int32 |
| 211 |
var wireType proto.WireType |
| 212 |
|
| 213 |
l := len(buf) |
| 214 |
pos := 0 |
| 215 |
for pos < l { |
| 216 |
// If in a group parsing, move to the next tag. |
| 217 |
fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos) |
| 218 |
if err != nil { |
| 219 |
return err |
| 220 |
} |
| 221 |
switch fieldNum { |
| 222 |
|
| 223 |
case 2: |
| 224 |
if wireType != proto.WireTypeLen { |
| 225 |
return fmt.Errorf("proto: wrong wireType = %d for field RequestContext", wireType) |
| 226 |
} |
| 227 |
var length int |
| 228 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 229 |
if err != nil { |
| 230 |
return err |
| 231 |
} |
| 232 |
startPos := pos - length |
| 233 |
|
| 234 |
orig.RequestContext = NewRequestContext() |
| 235 |
err = orig.RequestContext.UnmarshalProto(buf[startPos:pos]) |
| 236 |
if err != nil { |
| 237 |
return err |
| 238 |
} |
| 239 |
|
| 240 |
case 3: |
| 241 |
if wireType != proto.WireTypeLen { |
| 242 |
return fmt.Errorf("proto: wrong wireType = %d for field LogsData", wireType) |
| 243 |
} |
| 244 |
var length int |
| 245 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 246 |
if err != nil { |
| 247 |
return err |
| 248 |
} |
| 249 |
startPos := pos - length |
| 250 |
|
| 251 |
err = orig.LogsData.UnmarshalProto(buf[startPos:pos]) |
| 252 |
if err != nil { |
| 253 |
return err |
| 254 |
} |
| 255 |
|
| 256 |
case 1: |
| 257 |
if wireType != proto.WireTypeI32 { |
| 258 |
return fmt.Errorf("proto: wrong wireType = %d for field FormatVersion", wireType) |
| 259 |
} |
| 260 |
var num uint32 |
| 261 |
num, pos, err = proto.ConsumeI32(buf, pos) |
| 262 |
if err != nil { |
| 263 |
return err |
| 264 |
} |
| 265 |
|
| 266 |
orig.FormatVersion = uint32(num) |
| 267 |
default: |
| 268 |
pos, err = proto.ConsumeUnknown(buf, pos, wireType) |
| 269 |
if err != nil { |
| 270 |
return err |
| 271 |
} |
| 272 |
} |
| 273 |
} |
| 274 |
return nil |
| 275 |
} |
| 276 |
|
| 277 |
func GenTestLogsRequest() *LogsRequest { |
| 278 |
orig := NewLogsRequest() |
| 279 |
orig.RequestContext = GenTestRequestContext() |
| 280 |
orig.LogsData = *GenTestLogsData() |
| 281 |
orig.FormatVersion = uint32(13) |
| 282 |
return orig |
| 283 |
} |
| 284 |
|
| 285 |
func GenTestLogsRequestPtrSlice() []*LogsRequest { |
| 286 |
orig := make([]*LogsRequest, 5) |
| 287 |
orig[0] = NewLogsRequest() |
| 288 |
orig[1] = GenTestLogsRequest() |
| 289 |
orig[2] = NewLogsRequest() |
| 290 |
orig[3] = GenTestLogsRequest() |
| 291 |
orig[4] = NewLogsRequest() |
| 292 |
return orig |
| 293 |
} |
| 294 |
|
| 295 |
func GenTestLogsRequestSlice() []LogsRequest { |
| 296 |
orig := make([]LogsRequest, 5) |
| 297 |
orig[1] = *GenTestLogsRequest() |
| 298 |
orig[3] = *GenTestLogsRequest() |
| 299 |
return orig |
| 300 |
} |