-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathresponse.go
88 lines (74 loc) · 2.5 KB
/
response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package ptraceotlp // import "go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp"
import (
"bytes"
jsoniter "github.com/json-iterator/go"
"go.opentelemetry.io/collector/pdata/internal"
otlpcollectortrace "go.opentelemetry.io/collector/pdata/internal/data/protogen/collector/trace/v1"
"go.opentelemetry.io/collector/pdata/internal/json"
)
// ExportResponse represents the response for gRPC/HTTP client/server.
type ExportResponse struct {
orig *otlpcollectortrace.ExportTraceServiceResponse
state *internal.State
}
// NewExportResponse returns an empty ExportResponse.
func NewExportResponse() ExportResponse {
state := internal.StateMutable
return ExportResponse{
orig: &otlpcollectortrace.ExportTraceServiceResponse{},
state: &state,
}
}
// MarshalProto marshals ExportResponse into proto bytes.
func (ms ExportResponse) MarshalProto() ([]byte, error) {
return ms.orig.Marshal()
}
// UnmarshalProto unmarshalls ExportResponse from proto bytes.
func (ms ExportResponse) UnmarshalProto(data []byte) error {
return ms.orig.Unmarshal(data)
}
// MarshalJSON marshals ExportResponse into JSON bytes.
func (ms ExportResponse) MarshalJSON() ([]byte, error) {
var buf bytes.Buffer
if err := json.Marshal(&buf, ms.orig); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
// UnmarshalJSON unmarshalls ExportResponse from JSON bytes.
func (ms ExportResponse) UnmarshalJSON(data []byte) error {
iter := jsoniter.ConfigFastest.BorrowIterator(data)
defer jsoniter.ConfigFastest.ReturnIterator(iter)
ms.unmarshalJsoniter(iter)
return iter.Error
}
func (ms ExportResponse) unmarshalJsoniter(iter *jsoniter.Iterator) {
iter.ReadObjectCB(func(iter *jsoniter.Iterator, f string) bool {
switch f {
case "partial_success", "partialSuccess":
ms.PartialSuccess().unmarshalJsoniter(iter)
default:
iter.Skip()
}
return true
})
}
// PartialSuccess returns the ExportLogsPartialSuccess associated with this ExportResponse.
func (ms ExportResponse) PartialSuccess() ExportPartialSuccess {
return newExportPartialSuccess(&ms.orig.PartialSuccess, ms.state)
}
func (ms ExportPartialSuccess) unmarshalJsoniter(iter *jsoniter.Iterator) {
iter.ReadObjectCB(func(iterator *jsoniter.Iterator, f string) bool {
switch f {
case "rejected_spans", "rejectedSpans":
ms.orig.RejectedSpans = json.ReadInt64(iter)
case "error_message", "errorMessage":
ms.orig.ErrorMessage = iter.ReadString()
default:
iter.Skip()
}
return true
})
}