(pb []byte, base T, out *[]T)
| 98 | } |
| 99 | |
| 100 | func 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 | |
| 117 | func MarshalProtoJSONs[T proto.Message](protos []T) ([]byte, error) { |
| 118 | msgs := make([]json.RawMessage, len(protos)) |
no test coverage detected