Documentation
¶
Overview ¶
Package bufext builds buf's SourceCodeInfo extension (buf.descriptor.v1.buf_source_code_info_extension) without importing buf's generated code, which lives in modules hosted on buf.build (#266).
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SourceCodeInfoExtension = sync.OnceValue(func() protoreflect.ExtensionType { file := &descriptorpb.FileDescriptorProto{ Name: proto.String("buf/descriptor/v1/source_code_info_extension.proto"), Package: proto.String("buf.descriptor.v1"), Dependency: []string{"google/protobuf/descriptor.proto"}, Syntax: proto.String("proto2"), MessageType: []*descriptorpb.DescriptorProto{{ Name: proto.String("SourceCodeInfoExtension"), Field: []*descriptorpb.FieldDescriptorProto{ { Name: proto.String("is_syntax_unspecified"), JsonName: proto.String("isSyntaxUnspecified"), Number: proto.Int32(2), Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(), Type: descriptorpb.FieldDescriptorProto_TYPE_BOOL.Enum(), }, { Name: proto.String("unused_dependency"), JsonName: proto.String("unusedDependency"), Number: proto.Int32(3), Label: descriptorpb.FieldDescriptorProto_LABEL_REPEATED.Enum(), Type: descriptorpb.FieldDescriptorProto_TYPE_INT32.Enum(), Options: &descriptorpb.FieldOptions{Packed: proto.Bool(true)}, }, }, }}, Extension: []*descriptorpb.FieldDescriptorProto{{ Name: proto.String("buf_source_code_info_extension"), JsonName: proto.String("bufSourceCodeInfoExtension"), Number: proto.Int32(536000000), Label: descriptorpb.FieldDescriptorProto_LABEL_OPTIONAL.Enum(), Type: descriptorpb.FieldDescriptorProto_TYPE_MESSAGE.Enum(), TypeName: proto.String(".buf.descriptor.v1.SourceCodeInfoExtension"), Extendee: proto.String(".google.protobuf.SourceCodeInfo"), }}, } fd, err := protodesc.NewFile(file, protoregistry.GlobalFiles) if err != nil { panic(err) } return dynamicpb.NewExtensionType(fd.Extensions().Get(0)) })
SourceCodeInfoExtension returns buf's buf.descriptor.v1.buf_source_code_info_extension (field 536000000 of SourceCodeInfo, a SourceCodeInfoExtension message), built from a descriptor written here rather than imported from buf's generated code. Resolve with it to read the extension back as fields (#266).
The generated code lives in modules hosted on buf.build, which every program linking fdp then downloaded at build time. This type is built with dynamicpb and never registered, so a program that also links buf's SDK does not register buf/descriptor/v1 twice.
It is an extension type rather than unknown-field bytes because Go marshals extension fields before a message's known fields and unknown fields after them: bytes would move the extension from the start of SourceCodeInfo to its end. TestBufSourceCodeInfoExtensionBytes pins the bytes and position the generated code produced (see fdp).
Functions ¶
func Set ¶
func Set(info *descriptorpb.SourceCodeInfo, syntaxUnspecified bool, unusedDependency []int32)
Set sets buf's SourceCodeInfoExtension on info, or leaves it unset when both of its fields are empty.
The extension's fields are encoded by hand, in field-number order, and carried as the dynamic message's unknown bytes: dynamicpb does not marshal set fields in a fixed order, and buf's generated code always wrote is_syntax_unspecified (2) before unused_dependency (3).
Types ¶
This section is empty.