marshalMessage marshals the given protoreflect.Message.
(m protoreflect.Message, inclDelims bool)
| 160 | |
| 161 | // marshalMessage marshals the given protoreflect.Message. |
| 162 | func (e encoder) marshalMessage(m protoreflect.Message, inclDelims bool) error { |
| 163 | messageDesc := m.Descriptor() |
| 164 | if !flags.ProtoLegacy && messageset.IsMessageSet(messageDesc) { |
| 165 | return errors.New("no support for proto1 MessageSets") |
| 166 | } |
| 167 | |
| 168 | if inclDelims { |
| 169 | e.StartMessage() |
| 170 | defer e.EndMessage() |
| 171 | } |
| 172 | |
| 173 | // Handle Any expansion. |
| 174 | if messageDesc.FullName() == genid.Any_message_fullname { |
| 175 | if e.marshalAny(m) { |
| 176 | return nil |
| 177 | } |
| 178 | // If unable to expand, continue on to marshal Any as a regular message. |
| 179 | } |
| 180 | |
| 181 | // Marshal fields. |
| 182 | var err error |
| 183 | order.RangeFields(m, order.IndexNameFieldOrder, func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool { |
| 184 | if err = e.marshalField(fd.TextName(), v, fd); err != nil { |
| 185 | return false |
| 186 | } |
| 187 | return true |
| 188 | }) |
| 189 | if err != nil { |
| 190 | return err |
| 191 | } |
| 192 | |
| 193 | // Marshal unknown fields. |
| 194 | if e.opts.EmitUnknown { |
| 195 | e.marshalUnknown(m.GetUnknown()) |
| 196 | } |
| 197 | |
| 198 | return nil |
| 199 | } |
| 200 | |
| 201 | // marshalField marshals the given field with protoreflect.Value. |
| 202 | func (e encoder) marshalField(name string, val protoreflect.Value, fd protoreflect.FieldDescriptor) error { |
no test coverage detected