MCPcopy Create free account
hub / github.com/dagger/dagger / UnmarshalProtoJSONs

Function UnmarshalProtoJSONs

engine/clientdb/span.go:100–115  ·  view source on GitHub ↗
(pb []byte, base T, out *[]T)

Source from the content-addressed store, hash-verified

98}
99
100func UnmarshalProtoJSONs[T proto.Message](pb []byte, base T, out *[]T) error {
101 var msgs []json.RawMessage
102 if err := json.Unmarshal(pb, &msgs); err != nil {
103 return fmt.Errorf("failed to json unmarshal: %w", err)
104 }
105 protos := make([]T, len(msgs))
106 for i, msg := range msgs {
107 pl := proto.Clone(base).(T)
108 if err := protojson.Unmarshal(msg, pl); err != nil {
109 return fmt.Errorf("failed to protojson unmarshal %s into %T: %w", msg, pl, err)
110 }
111 protos[i] = pl
112 }
113 *out = protos
114 return nil
115}
116
117func MarshalProtoJSONs[T proto.Message](protos []T) ([]byte, error) {
118 msgs := make([]json.RawMessage, len(protos))

Callers 5

captureLogsMethod · 0.92
AttributesMethod · 0.85
LinksMethod · 0.85
EventsMethod · 0.85
LogsToPBFunction · 0.85

Calls 2

UnmarshalMethod · 0.65
CloneMethod · 0.65

Tested by

no test coverage detected