MCPcopy
hub / github.com/golang/protobuf / marshalField

Method marshalField

jsonpb/encode.go:390–419  ·  view source on GitHub ↗

marshalField writes field description and value to the Writer.

(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string)

Source from the content-addressed store, hash-verified

388
389// marshalField writes field description and value to the Writer.
390func (w *jsonWriter) marshalField(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error {
391 if w.Indent != "" {
392 w.write(indent)
393 w.write(w.Indent)
394 }
395 w.write(`"`)
396 switch {
397 case fd.IsExtension():
398 // For message set, use the fname of the message as the extension name.
399 name := string(fd.FullName())
400 if isMessageSet(fd.ContainingMessage()) {
401 name = strings.TrimSuffix(name, ".message_set_extension")
402 }
403
404 w.write("[" + name + "]")
405 case w.OrigName:
406 name := string(fd.Name())
407 if fd.Kind() == protoreflect.GroupKind {
408 name = string(fd.Message().Name())
409 }
410 w.write(name)
411 default:
412 w.write(string(fd.JSONName()))
413 }
414 w.write(`":`)
415 if w.Indent != "" {
416 w.write(" ")
417 }
418 return w.marshalValue(fd, v, indent)
419}
420
421func (w *jsonWriter) marshalValue(fd protoreflect.FieldDescriptor, v protoreflect.Value, indent string) error {
422 switch {

Callers 1

marshalMessageMethod · 0.95

Calls 4

writeMethod · 0.95
marshalValueMethod · 0.95
isMessageSetFunction · 0.70
NameMethod · 0.65

Tested by

no test coverage detected