Skip to content

Commit

Permalink
handling of dynamicpb.Map
Browse files Browse the repository at this point in the history
  • Loading branch information
billettc committed Feb 26, 2024
1 parent d474951 commit f3b1567
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions json/marshallers.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ func (m *Marshaller) dynamicpbMessage(encoder *jsontext.Encoder, msg *dynamicpb.
}

msg.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
if fd.IsMap() {
out := map[string]interface{}{}
v.Map().Range(func(k protoreflect.MapKey, v2 protoreflect.Value) bool {
key := k.String()
out[key] = v2.Interface()
return true
})
kvl = append(kvl, &kv{
key: string(fd.Name()),
value: out,
})
return true
}

if fd.IsList() {
out := make([]any, v.List().Len())
for i := 0; i < v.List().Len(); i++ {
Expand Down

0 comments on commit f3b1567

Please sign in to comment.