bufimage

package
v1.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2023 License: Apache-2.0 Imports: 14 Imported by: 34

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImageToCodeGeneratorRequest

func ImageToCodeGeneratorRequest(
	image Image,
	parameter string,
	compilerVersion *pluginpb.Version,
	includeImports bool,
	includeWellKnownTypes bool,
) *pluginpb.CodeGeneratorRequest

ImageToCodeGeneratorRequest returns a new CodeGeneratorRequest for the Image.

All non-imports are added as files to generate. If includeImports is set, all non-well-known-type imports are also added as files to generate. If includeWellKnownTypes is set, well-known-type imports are also added as files to generate. includeWellKnownTypes has no effect if includeImports is not set.

func ImageToFileDescriptorProtos

func ImageToFileDescriptorProtos(image Image) []*descriptorpb.FileDescriptorProto

ImageToFileDescriptorProtos returns the FileDescriptorProtos for the Image.

func ImageToFileDescriptorSet

func ImageToFileDescriptorSet(image Image) *descriptorpb.FileDescriptorSet

ImageToFileDescriptorSet returns a new FileDescriptorSet for the Image.

func ImageToFileDescriptors

func ImageToFileDescriptors(image Image) []protodescriptor.FileDescriptor

ImageToFileDescriptors returns the FileDescriptors for the Image.

func ImageToProtoImage

func ImageToProtoImage(image Image) *imagev1.Image

ImageToProtoImage returns a new ProtoImage for the Image.

func ImagesToCodeGeneratorRequests

func ImagesToCodeGeneratorRequests(
	images []Image,
	parameter string,
	compilerVersion *pluginpb.Version,
	includeImports bool,
	includeWellKnownTypes bool,
) []*pluginpb.CodeGeneratorRequest

ImagesToCodeGeneratorRequests converts the Images to CodeGeneratorRequests.

All non-imports are added as files to generate. If includeImports is set, all non-well-known-type imports are also added as files to generate. If includeImports is set, only one CodeGeneratorRequest will contain any given file as a FileToGenerate. If includeWellKnownTypes is set, well-known-type imports are also added as files to generate. includeWellKnownTypes has no effect if includeImports is not set.

func ProtoImageToFileDescriptors

func ProtoImageToFileDescriptors(protoImage *imagev1.Image) []protodescriptor.FileDescriptor

ProtoImageToFileDescriptors returns the FileDescriptors for the proto Image.

Types

type Image

type Image interface {
	// Files are the files that comprise the image.
	//
	// This contains all files, including imports if available.
	// The returned files are in correct DAG order.
	Files() []ImageFile
	// GetFile gets the file for the root relative file path.
	//
	// If the file does not exist, nil is returned.
	// The path is expected to be normalized and validated.
	// Note that all values of GetDependency() can be used here.
	GetFile(path string) ImageFile
	// contains filtered or unexported methods
}

Image is a buf image.

func ImageByDir

func ImageByDir(image Image) ([]Image, error)

ImageByDir returns multiple images that have non-imports split by directory.

That is, each Image will only contain a single directory's files as it's non-imports, along with all required imports for the files in that directory.

func ImageWithOnlyPaths

func ImageWithOnlyPaths(
	image Image,
	paths []string,
	excludePaths []string,
) (Image, error)

ImageWithOnlyPaths returns a copy of the Image that only includes the files with the given root relative file paths or directories.

Note that paths can be either files or directories - whether or not a path is included is a result of normalpath.EqualsOrContainsPath.

If a root relative file path does not exist, this errors.

func ImageWithOnlyPathsAllowNotExist

func ImageWithOnlyPathsAllowNotExist(
	image Image,
	paths []string,
	excludePaths []string,
) (Image, error)

ImageWithOnlyPathsAllowNotExist returns a copy of the Image that only includes the files with the given root relative file paths.

Note that paths can be either files or directories - whether or not a path is included is a result of normalpath.EqualsOrContainsPath.

If a root relative file path does not exist, this skips this path.

func ImageWithoutImports

func ImageWithoutImports(image Image) Image

ImageWithoutImports returns a copy of the Image without imports.

The backing Files are not copied.

func MergeImages

func MergeImages(images ...Image) (Image, error)

MergeImages returns a new Image for the given Images. ImageFiles treated as non-imports in at least one of the given Images will be treated as non-imports in the returned Image. The first non-import version of a file will be used in the result.

Reorders the ImageFiles to be in DAG order. Duplicates can exist across the Images, but only if duplicates are non-imports.

func NewImage

func NewImage(imageFiles []ImageFile) (Image, error)

NewImage returns a new Image for the given ImageFiles.

The input ImageFiles are expected to be in correct DAG order! TODO: Consider checking the above, and if not, reordering the Files. If imageFiles is empty, returns error

func NewImageForCodeGeneratorRequest

func NewImageForCodeGeneratorRequest(request *pluginpb.CodeGeneratorRequest, options ...NewImageForProtoOption) (Image, error)

NewImageForCodeGeneratorRequest returns a new Image from a given CodeGeneratorRequest.

The input Files are expected to be in correct DAG order! TODO: Consider checking the above, and if not, reordering the Files.

func NewImageForProto

func NewImageForProto(protoImage *imagev1.Image, options ...NewImageForProtoOption) (Image, error)

NewImageForProto returns a new Image for the given proto Image.

The input Files are expected to be in correct DAG order! TODO: Consider checking the above, and if not, reordering the Files.

TODO: do we want to add the ability to do external path resolution here?

func NewMultiImage

func NewMultiImage(images ...Image) (Image, error)

NewMultiImage returns a new Image for the given Images.

Reorders the ImageFiles to be in DAG order. Duplicates cannot exist across the Images.

type ImageFile

type ImageFile interface {
	bufmoduleref.FileInfo
	// Proto is the backing *descriptorpb.FileDescriptorProto for this File.
	//
	// FileDescriptor should be preferred to Proto. We keep this method around
	// because we have code that does modification to the ImageFile via this.
	//
	// This will never be nil.
	// The value Path() is equal to Proto.GetName() .
	Proto() *descriptorpb.FileDescriptorProto
	// FileDescriptor is the backing FileDescriptor for this File.
	//
	// This will never be nil.
	// The value Path() is equal to FileDescriptor.GetName() .
	FileDescriptor() protodescriptor.FileDescriptor
	// IsSyntaxUnspecified will be true if the syntax was not explicitly specified.
	IsSyntaxUnspecified() bool
	// UnusedDependencyIndexes returns the indexes of the unused dependencies within
	// FileDescriptor.GetDependency().
	//
	// All indexes will be valid.
	// Will return nil if empty.
	UnusedDependencyIndexes() []int32
	// contains filtered or unexported methods
}

ImageFile is a Protobuf file within an image.

func NewImageFile

func NewImageFile(
	fileDescriptor protodescriptor.FileDescriptor,
	moduleIdentity bufmoduleref.ModuleIdentity,
	commit string,
	externalPath string,
	isImport bool,
	isSyntaxUnspecified bool,
	unusedDependencyIndexes []int32,
) (ImageFile, error)

NewImageFile returns a new ImageFile.

If externalPath is empty, path is used.

TODO: moduleIdentity and commit should be options since they are optional.

type NewImageForProtoOption added in v1.10.0

type NewImageForProtoOption func(*newImageForProtoOptions)

NewImageForProtoOption is an option for use with NewImageForProto.

func WithNoReparse added in v1.10.0

func WithNoReparse() NewImageForProtoOption

WithNoReparse instructs NewImageForProto to skip the reparse step. The reparse step is usually needed when unmarshalling the image from bytes. It reconstitutes custom options, from unrecognized bytes to known extension fields.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL