| 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 |
// ExportPartialSuccess represents the details of a partially successful export request. |
| 18 |
type ExportMetricsPartialSuccess struct { |
| 19 |
RejectedDataPoints int64 |
| 20 |
ErrorMessage string |
| 21 |
} |
| 22 |
|
| 23 |
var ( |
| 24 |
protoPoolExportMetricsPartialSuccess = sync.Pool{ |
| 25 |
New: func() any { |
| 26 |
return &ExportMetricsPartialSuccess{} |
| 27 |
}, |
| 28 |
} |
| 29 |
) |
| 30 |
|
| 31 |
func NewExportMetricsPartialSuccess() *ExportMetricsPartialSuccess { |
| 32 |
if !UseProtoPooling.IsEnabled() { |
| 33 |
return &ExportMetricsPartialSuccess{} |
| 34 |
} |
| 35 |
return protoPoolExportMetricsPartialSuccess.Get().(*ExportMetricsPartialSuccess) |
| 36 |
} |
| 37 |
|
| 38 |
func DeleteExportMetricsPartialSuccess(orig *ExportMetricsPartialSuccess, nullable bool) { |
| 39 |
if orig == nil { |
| 40 |
return |
| 41 |
} |
| 42 |
|
| 43 |
if !UseProtoPooling.IsEnabled() { |
| 44 |
orig.Reset() |
| 45 |
return |
| 46 |
} |
| 47 |
|
| 48 |
orig.Reset() |
| 49 |
if nullable { |
| 50 |
protoPoolExportMetricsPartialSuccess.Put(orig) |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
func CopyExportMetricsPartialSuccess(dest, src *ExportMetricsPartialSuccess) *ExportMetricsPartialSuccess { |
| 55 |
// If copying to same object, just return. |
| 56 |
if src == dest { |
| 57 |
return dest |
| 58 |
} |
| 59 |
|
| 60 |
if src == nil { |
| 61 |
return nil |
| 62 |
} |
| 63 |
|
| 64 |
if dest == nil { |
| 65 |
dest = NewExportMetricsPartialSuccess() |
| 66 |
} |
| 67 |
dest.RejectedDataPoints = src.RejectedDataPoints |
| 68 |
|
| 69 |
dest.ErrorMessage = src.ErrorMessage |
| 70 |
|
| 71 |
return dest |
| 72 |
} |
| 73 |
|
| 74 |
func CopyExportMetricsPartialSuccessSlice(dest, src []ExportMetricsPartialSuccess) []ExportMetricsPartialSuccess { |
| 75 |
var newDest []ExportMetricsPartialSuccess |
| 76 |
if cap(dest) < len(src) { |
| 77 |
newDest = make([]ExportMetricsPartialSuccess, len(src)) |
| 78 |
} else { |
| 79 |
newDest = dest[:len(src)] |
| 80 |
// Cleanup the rest of the elements so GC can free the memory. |
| 81 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 82 |
for i := len(src); i < len(dest); i++ { |
| 83 |
DeleteExportMetricsPartialSuccess(&dest[i], false) |
| 84 |
} |
| 85 |
} |
| 86 |
for i := range src { |
| 87 |
CopyExportMetricsPartialSuccess(&newDest[i], &src[i]) |
| 88 |
} |
| 89 |
return newDest |
| 90 |
} |
| 91 |
|
| 92 |
func CopyExportMetricsPartialSuccessPtrSlice(dest, src []*ExportMetricsPartialSuccess) []*ExportMetricsPartialSuccess { |
| 93 |
var newDest []*ExportMetricsPartialSuccess |
| 94 |
if cap(dest) < len(src) { |
| 95 |
newDest = make([]*ExportMetricsPartialSuccess, len(src)) |
| 96 |
// Copy old pointers to re-use. |
| 97 |
copy(newDest, dest) |
| 98 |
// Add new pointers for missing elements from len(dest) to len(srt). |
| 99 |
for i := len(dest); i < len(src); i++ { |
| 100 |
newDest[i] = NewExportMetricsPartialSuccess() |
| 101 |
} |
| 102 |
} else { |
| 103 |
newDest = dest[:len(src)] |
| 104 |
// Cleanup the rest of the elements so GC can free the memory. |
| 105 |
// This can happen when len(src) < len(dest) < cap(dest). |
| 106 |
for i := len(src); i < len(dest); i++ { |
| 107 |
DeleteExportMetricsPartialSuccess(dest[i], true) |
| 108 |
dest[i] = nil |
| 109 |
} |
| 110 |
// Add new pointers for missing elements. |
| 111 |
// This can happen when len(dest) < len(src) < cap(dest). |
| 112 |
for i := len(dest); i < len(src); i++ { |
| 113 |
newDest[i] = NewExportMetricsPartialSuccess() |
| 114 |
} |
| 115 |
} |
| 116 |
for i := range src { |
| 117 |
CopyExportMetricsPartialSuccess(newDest[i], src[i]) |
| 118 |
} |
| 119 |
return newDest |
| 120 |
} |
| 121 |
|
| 122 |
func (orig *ExportMetricsPartialSuccess) Reset() { |
| 123 |
*orig = ExportMetricsPartialSuccess{} |
| 124 |
} |
| 125 |
|
| 126 |
// MarshalJSON marshals all properties from the current struct to the destination stream. |
| 127 |
func (orig *ExportMetricsPartialSuccess) MarshalJSON(dest *json.Stream) { |
| 128 |
dest.WriteObjectStart() |
| 129 |
if orig.RejectedDataPoints != int64(0) { |
| 130 |
dest.WriteObjectField("rejectedDataPoints") |
| 131 |
dest.WriteInt64(orig.RejectedDataPoints) |
| 132 |
} |
| 133 |
if orig.ErrorMessage != "" { |
| 134 |
dest.WriteObjectField("errorMessage") |
| 135 |
dest.WriteString(orig.ErrorMessage) |
| 136 |
} |
| 137 |
dest.WriteObjectEnd() |
| 138 |
} |
| 139 |
|
| 140 |
// UnmarshalJSON unmarshals all properties from the current struct from the source iterator. |
| 141 |
func (orig *ExportMetricsPartialSuccess) UnmarshalJSON(iter *json.Iterator) { |
| 142 |
for f := iter.ReadObject(); f != ""; f = iter.ReadObject() { |
| 143 |
switch f { |
| 144 |
case "rejectedDataPoints", "rejected_data_points": |
| 145 |
orig.RejectedDataPoints = iter.ReadInt64() |
| 146 |
case "errorMessage", "error_message": |
| 147 |
orig.ErrorMessage = iter.ReadString() |
| 148 |
default: |
| 149 |
iter.Skip() |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
func (orig *ExportMetricsPartialSuccess) SizeProto() int { |
| 155 |
var n int |
| 156 |
var l int |
| 157 |
_ = l |
| 158 |
if orig.RejectedDataPoints != 0 { |
| 159 |
n += 1 + proto.Sov(uint64(orig.RejectedDataPoints)) |
| 160 |
} |
| 161 |
l = len(orig.ErrorMessage) |
| 162 |
if l > 0 { |
| 163 |
n += 1 + proto.Sov(uint64(l)) + l |
| 164 |
} |
| 165 |
return n |
| 166 |
} |
| 167 |
|
| 168 |
func (orig *ExportMetricsPartialSuccess) MarshalProto(buf []byte) int { |
| 169 |
pos := len(buf) |
| 170 |
var l int |
| 171 |
_ = l |
| 172 |
if orig.RejectedDataPoints != 0 { |
| 173 |
pos = proto.EncodeVarint(buf, pos, uint64(orig.RejectedDataPoints)) |
| 174 |
pos-- |
| 175 |
buf[pos] = 0x8 |
| 176 |
} |
| 177 |
l = len(orig.ErrorMessage) |
| 178 |
if l > 0 { |
| 179 |
pos -= l |
| 180 |
copy(buf[pos:], orig.ErrorMessage) |
| 181 |
pos = proto.EncodeVarint(buf, pos, uint64(l)) |
| 182 |
pos-- |
| 183 |
buf[pos] = 0x12 |
| 184 |
} |
| 185 |
return len(buf) - pos |
| 186 |
} |
| 187 |
|
| 188 |
func (orig *ExportMetricsPartialSuccess) UnmarshalProto(buf []byte) error { |
| 189 |
var err error |
| 190 |
var fieldNum int32 |
| 191 |
var wireType proto.WireType |
| 192 |
|
| 193 |
l := len(buf) |
| 194 |
pos := 0 |
| 195 |
for pos < l { |
| 196 |
// If in a group parsing, move to the next tag. |
| 197 |
fieldNum, wireType, pos, err = proto.ConsumeTag(buf, pos) |
| 198 |
if err != nil { |
| 199 |
return err |
| 200 |
} |
| 201 |
switch fieldNum { |
| 202 |
|
| 203 |
case 1: |
| 204 |
if wireType != proto.WireTypeVarint { |
| 205 |
return fmt.Errorf("proto: wrong wireType = %d for field RejectedDataPoints", wireType) |
| 206 |
} |
| 207 |
var num uint64 |
| 208 |
num, pos, err = proto.ConsumeVarint(buf, pos) |
| 209 |
if err != nil { |
| 210 |
return err |
| 211 |
} |
| 212 |
|
| 213 |
orig.RejectedDataPoints = int64(num) |
| 214 |
|
| 215 |
case 2: |
| 216 |
if wireType != proto.WireTypeLen { |
| 217 |
return fmt.Errorf("proto: wrong wireType = %d for field ErrorMessage", wireType) |
| 218 |
} |
| 219 |
var length int |
| 220 |
length, pos, err = proto.ConsumeLen(buf, pos) |
| 221 |
if err != nil { |
| 222 |
return err |
| 223 |
} |
| 224 |
startPos := pos - length |
| 225 |
orig.ErrorMessage = string(buf[startPos:pos]) |
| 226 |
default: |
| 227 |
pos, err = proto.ConsumeUnknown(buf, pos, wireType) |
| 228 |
if err != nil { |
| 229 |
return err |
| 230 |
} |
| 231 |
} |
| 232 |
} |
| 233 |
return nil |
| 234 |
} |
| 235 |
|
| 236 |
func GenTestExportMetricsPartialSuccess() *ExportMetricsPartialSuccess { |
| 237 |
orig := NewExportMetricsPartialSuccess() |
| 238 |
orig.RejectedDataPoints = int64(13) |
| 239 |
orig.ErrorMessage = "test_errormessage" |
| 240 |
return orig |
| 241 |
} |
| 242 |
|
| 243 |
func GenTestExportMetricsPartialSuccessPtrSlice() []*ExportMetricsPartialSuccess { |
| 244 |
orig := make([]*ExportMetricsPartialSuccess, 5) |
| 245 |
orig[0] = NewExportMetricsPartialSuccess() |
| 246 |
orig[1] = GenTestExportMetricsPartialSuccess() |
| 247 |
orig[2] = NewExportMetricsPartialSuccess() |
| 248 |
orig[3] = GenTestExportMetricsPartialSuccess() |
| 249 |
orig[4] = NewExportMetricsPartialSuccess() |
| 250 |
return orig |
| 251 |
} |
| 252 |
|
| 253 |
func GenTestExportMetricsPartialSuccessSlice() []ExportMetricsPartialSuccess { |
| 254 |
orig := make([]ExportMetricsPartialSuccess, 5) |
| 255 |
orig[1] = *GenTestExportMetricsPartialSuccess() |
| 256 |
orig[3] = *GenTestExportMetricsPartialSuccess() |
| 257 |
return orig |
| 258 |
} |