MCPcopy Create free account
hub / github.com/bufbuild/buf / NewMessage

Function NewMessage

private/bufpkg/bufreflect/bufreflect.go:28–41  ·  view source on GitHub ↗

NewMessage returns a new dynamic proto.Message for the fully qualified typeName in the bufimage.Image.

(
	ctx context.Context,
	image bufimage.Image,
	typeName string,
)

Source from the content-addressed store, hash-verified

26// NewMessage returns a new dynamic proto.Message for the fully qualified typeName
27// in the bufimage.Image.
28func NewMessage(
29 ctx context.Context,
30 image bufimage.Image,
31 typeName string,
32) (proto.Message, error) {
33 if err := ValidateTypeName(typeName); err != nil {
34 return nil, err
35 }
36 messageType, err := image.Resolver().FindMessageByName(protoreflect.FullName(typeName))
37 if err != nil {
38 return nil, err
39 }
40 return messageType.New().Interface(), nil
41}
42
43// ValidateTypeName validates that the typeName is well-formed, such that it has one or more
44// '.'-delimited package components and no '/' elements.

Callers 1

GetMessageMethod · 0.92

Calls 4

ValidateTypeNameFunction · 0.85
ResolverMethod · 0.65
FullNameMethod · 0.65
FindMessageByNameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…