An Image is a set of Protobuf files compiled into an Image binary. An Image represents everything inside a Protobuf project and can be used as the input to most commands.

Description

Images in Protobuf are encoded as Image Protobuf messages, with the mechanics of Buf images explained in detail on the Image explanation page. An image can be in either binary or JSON format.

Using images can greatly simplify working with Protobuf projects, as it allows for state to be saved, compared, and used as input for other commands. All Buf images are stored as files, which can be read from a local path, a remote HTTP/HTTPS location, or stdin (using '-').

The commands that take an image are:

Usage

When Using an image as an input the following options are available. Options are parsed to input parameters in the following form:

path#option_key1=option_value1,option_key2=option_value2

Options

#format=[bin|json]

This page contains image formats, to see all formats see the format page.

FormatDescriptionDerived extensionExample
binprotobuf binary.binimage.bin, image#format=bin
jsonjson image.jsonimage.json, image#format=json

#format=bin

Protobuf binary format. The path to this archive can be either a local file, a remote http/https location, or stdin. To use stdin use -, for example cat image.bin | buf build -#format=bin or just cat image.bin | buf build -.

When the format is bin the compression option is available.

Usage

#format=bin,compression=[gzip|zstd]

Options

OptionValueDescriptionExample
compressiongzip,zstdcompression to usebuf build image#format=bin,compression=gzip

Automatically derived formats and compressions

As well as using the format and compression options, the following file extensions can be used instead.

ExtensionDerived CompressionExample
.binnoneimage.bin
.bin.gzgzipimage.bin.gz
.bin.zstzstdimage.bin.zst

#format=json

Protobuf in JSON format. This creates files that use much more space and are slower to parse but result in diffs that show the actual differences between two Protobuf objects in a readable format. The path to this archive can be either a local file, a remote http/https location, or stdin. To use stdin use -, for example cat image.json | buf build -#format=bin.

When the format is json, the compression option is available.

Usage

#format=json,compression=[gzip|zstd]

Options

OptionValueDescriptionExample
compressiongzip,zstdcompression to usebuf build image#format=json,compression=gzip

Automatically derived formats and compressions

As well as using the format and compression options, the following file extensions can be used instead.

ExtensionDerived CompressionExample
.jsonnoneimage.json
.json.gzgzipimage.json.gz
.json.zstzstdimage.json.zst

Examples

Use buf breaking --against:

buf breaking image.bin --agaist image.bin

Use a binary as the input to buf curl --schema:

buf curl --data '{"sentence": "I feel happy."}' https://demo.connect.build/buf.connect.demo.eliza.v1.ElizaService/Say --schema=eliza.bin