writeProto3Any writes an expanded google.protobuf.Any message. It returns (false, nil) if sv value can't be unmarshaled (e.g. because required messages are not linked in). It returns (true, error) when sv was written in expanded format or an error was encountered.
(m protoreflect.Message)
| 219 | // It returns (true, error) when sv was written in expanded format or an error |
| 220 | // was encountered. |
| 221 | func (w *textWriter) writeProto3Any(m protoreflect.Message) (bool, error) { |
| 222 | md := m.Descriptor() |
| 223 | fdURL := md.Fields().ByName("type_url") |
| 224 | fdVal := md.Fields().ByName("value") |
| 225 | |
| 226 | url := m.Get(fdURL).String() |
| 227 | mt, err := protoregistry.GlobalTypes.FindMessageByURL(url) |
| 228 | if err != nil { |
| 229 | return false, nil |
| 230 | } |
| 231 | |
| 232 | b := m.Get(fdVal).Bytes() |
| 233 | m2 := mt.New() |
| 234 | if err := proto.Unmarshal(b, m2.Interface()); err != nil { |
| 235 | return false, nil |
| 236 | } |
| 237 | w.Write([]byte("[")) |
| 238 | if requiresQuotes(url) { |
| 239 | w.writeQuotedString(url) |
| 240 | } else { |
| 241 | w.Write([]byte(url)) |
| 242 | } |
| 243 | if w.compact { |
| 244 | w.Write([]byte("]:<")) |
| 245 | } else { |
| 246 | w.Write([]byte("]: <\n")) |
| 247 | w.indent++ |
| 248 | } |
| 249 | if err := w.writeMessage(m2); err != nil { |
| 250 | return true, err |
| 251 | } |
| 252 | if w.compact { |
| 253 | w.Write([]byte("> ")) |
| 254 | } else { |
| 255 | w.indent-- |
| 256 | w.Write([]byte(">\n")) |
| 257 | } |
| 258 | return true, nil |
| 259 | } |
| 260 | |
| 261 | func (w *textWriter) writeMessage(m protoreflect.Message) error { |
| 262 | md := m.Descriptor() |
no test coverage detected