proto

package
v0.0.0-...-9eda336 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 25 Imported by: 50

Documentation

Overview

Package proto contains protobuf-related utilities.

Index

Constants

This section is empty.

Variables

View Source
var (
	TextPBFieldFormat_name = map[int32]string{
		0: "DEFAULT",
		1: "JSON",
	}
	TextPBFieldFormat_value = map[string]int32{
		"DEFAULT": 0,
		"JSON":    1,
	}
)

Enum value maps for TextPBFieldFormat.

View Source
var (
	// Used by lucicfg and textpb package to pretty-print text protos.
	//
	// Usage:
	//
	//	import "go.chromium.org/luci/common/proto/options.proto";
	//
	//	message MyMessage {
	//	  string my_field = 1 [(luci.text_pb_format) = JSON];
	//	}
	//
	// optional luci.TextPBFieldFormat text_pb_format = 73701;
	E_TextPbFormat = &file_go_chromium_org_luci_common_proto_options_proto_extTypes[1]
	// Used by lucicfg to skip comparing fields when making semantic comparison.
	//
	// Usage:
	//
	//	import "go.chromium.org/luci/common/proto/options.proto";
	//
	//	message MyMessage {
	//	  string my_field = 1 [(luci.lucicfg_ignore) = true];
	//	}
	//
	// optional bool lucicfg_ignore = 73702;
	E_LucicfgIgnore = &file_go_chromium_org_luci_common_proto_options_proto_extTypes[2]
)

Extension fields to descriptorpb.FieldOptions.

View Source
var (
	// Used by lucicfg to populate headers of generated text proto files.
	//
	// Usage:
	//
	//	import "go.chromium.org/luci/common/proto/options.proto";
	//
	//	option (luci.file_metadata) = {
	//	  doc_url: "https://example.com/schema.md";
	//	};
	//
	// optional luci.Metadata file_metadata = 73700;
	E_FileMetadata = &file_go_chromium_org_luci_common_proto_options_proto_extTypes[0]
)

Extension fields to descriptorpb.FileOptions.

View Source
var File_go_chromium_org_luci_common_proto_options_proto protoreflect.FileDescriptor

Functions

func MatcherEqual

func MatcherEqual(m proto.Message) gomock.Matcher

MatcherEqual returns a matcher that matches on protobuf equality. Note: reflect.DeepEqual can't be used with protobuf messages as it may yield unexpected results.

func ParseMultilineStrings

func ParseMultilineStrings(text string) (string, error)

ParseMultilineStrings looks for bash-style heredocs and replaces them with single-line text-proto-escaped strings.

This looks line by line for /<<\s*([_a-zA-Z]+)\s*$/. If this is found, the scanner then looks until it finds /^\s*\1\s*$/. Every line between these is joined like "\n".join(lines), and then printed back as an escaped proto string. The scanner then loops back to its initial state.

Not that nothing special needs to be done for e.g.

some_key: "string with << angles"

Such a line would be left alone, because the trailing quote (which is mandatory in text proto) cause the starting regex to not match.

For convenience, the inner lines will be treated with the equivalent of python's `textwrap.dedent`; any common leading whitespace that occurs on every line will be removed. Although both tabs and spaces count as whitespace, they are not equivalent (i.e. only exactly-matching whitespace prefixes count)

The only error this may return is if there's an open heredoc without a matching close marker.

Example:

  this: <<EOF
	   would
	   turn \ninto
      a "single"
    line
  EOF

Turns into the same as:

this: "would\nturn \\ninto\n  a \"single\"\nline"

func StableHash

func StableHash(h hash.Hash, m proto.Message) error

StableHash does a deterministic and ordered walk over the proto message `m`, feeding each field into `h`.

This is useful to produce stable, deterministic hashes of proto messages where comparison of messages generated from different sources or runtimes is important.

Because of this, `m` may not contain any unknown fields, since there is no way to canonicalize them without the message definition. If the message has any unknown fields, this function returns an error. NOTE: - The hash value can ONLY be used for backward compatible protobuf change to determine if the protobuf message is different. If two protobuf specs are incompatible, their value MUST NOT be compared with each other and not promised to be different even their messages are clearly different. - google.protobuf.Any is supported via Any.UnmarshalNew: if the message is not registered, this returns an error. - 0-valued scalar fields are not distinguished from absent fields.

func UnmarshalJSONWithNonStandardFieldMasks

func UnmarshalJSONWithNonStandardFieldMasks(buf []byte, msg proto.Message) error

UnmarshalJSONWithNonStandardFieldMasks unmarshals a JSONPB message that has google.protobuf.FieldMask inside that either uses non-standard field mask semantics (like paths that contains `*`) or uses non-standard object encoding (e.g. `"mask": {"paths": ["a", "b"]}` instead of `"mask": "a,b"`), or both.

Such field masks are not supported by the standard JSONPB unmarshaller. If your message uses only standard field masks (i.e. only containing paths like `a.b.c` with not extra syntax, with the field mask serialized as a string), use the standard JSON unmarshaler from google.golang.org/protobuf/encoding/protojson package.

Using non-standard field masks is discouraged. Deserializing them has significant performance overhead. This function is also more likely to break in the future (since it uses deprecated libraries under the hood).

Giant name of this function is a hint that it should not be used.

func UnmarshalTextML

func UnmarshalTextML(s string, pb proto.Message) error

UnmarshalTextML behaves the same as proto.UnmarshalText, except that it allows for multiline strings in the manner of ParseMultilineStrings.

Types

type Metadata

type Metadata struct {

	// URL to a human-readable proto schema definition doc.
	DocUrl *string `protobuf:"bytes,1,opt,name=doc_url,json=docUrl" json:"doc_url,omitempty"`
	// contains filtered or unexported fields
}

func (*Metadata) Descriptor deprecated

func (*Metadata) Descriptor() ([]byte, []int)

Deprecated: Use Metadata.ProtoReflect.Descriptor instead.

func (*Metadata) GetDocUrl

func (x *Metadata) GetDocUrl() string

func (*Metadata) ProtoMessage

func (*Metadata) ProtoMessage()

func (*Metadata) ProtoReflect

func (x *Metadata) ProtoReflect() protoreflect.Message

func (*Metadata) Reset

func (x *Metadata) Reset()

func (*Metadata) String

func (x *Metadata) String() string

type TextPBFieldFormat

type TextPBFieldFormat int32

Type of formatting to apply to a primitive field when converting a message to TextPB

const (
	// The default formatting for TextPB for the field
	TextPBFieldFormat_DEFAULT TextPBFieldFormat = 0
	// Interpret the field's value as a JSON object and format it across multiple
	// lines, valid only for string fields
	TextPBFieldFormat_JSON TextPBFieldFormat = 1
)

func (TextPBFieldFormat) Descriptor

func (TextPBFieldFormat) Enum

func (TextPBFieldFormat) EnumDescriptor deprecated

func (TextPBFieldFormat) EnumDescriptor() ([]byte, []int)

Deprecated: Use TextPBFieldFormat.Descriptor instead.

func (TextPBFieldFormat) Number

func (TextPBFieldFormat) String

func (x TextPBFieldFormat) String() string

func (TextPBFieldFormat) Type

func (*TextPBFieldFormat) UnmarshalJSON deprecated

func (x *TextPBFieldFormat) UnmarshalJSON(b []byte) error

Deprecated: Do not use.

Directories

Path Synopsis
Package config contains luci-config protobuf definitions.
Package config contains luci-config protobuf definitions.
Package examples shows how to design protos which adhere to the Google Cloud API design guide.
Package examples shows how to design protos which adhere to the Google Cloud API design guide.
Package findings contains proto definitions for code findings.
Package findings contains proto definitions for code findings.
Package gerritpb contains Gerrit service definition.
Package gerritpb contains Gerrit service definition.
Package git contains Git-related protobuf definitions.
Package git contains Git-related protobuf definitions.
Package gitiles contains Gitiles service definition.
Package gitiles contains Gitiles service definition.
mock_gitiles
Package mock_gitiles is a generated GoMock package.
Package mock_gitiles is a generated GoMock package.
google
descutil
Package descutil contains utility functions for protobuf descriptor messages.
Package descutil contains utility functions for protobuf descriptor messages.
descutil/internal
Package internal is used exclusively for descutil own tests.
Package internal is used exclusively for descutil own tests.
internal
Package mask provides utility functions for google protobuf field masks.
Package mask provides utility functions for google protobuf field masks.
Package msgpackpb implements generic protobuf message serialization to msgpack.
Package msgpackpb implements generic protobuf message serialization to msgpack.
luagen
Package luagen implements a lua code generator for proto code.
Package luagen implements a lua code generator for proto code.
luagen/examplepb
Package examplepb serves as an example protobuf library which is structured similarly to how other protobuf libraries in this repo are structured, with the addition of a generated .lua file output.
Package examplepb serves as an example protobuf library which is structured similarly to how other protobuf libraries in this repo are structured, with the addition of a generated .lua file output.
Package paged implements a helper for making paginated Datastore queries.
Package paged implements a helper for making paginated Datastore queries.
Package protoc contains helpers for running `protoc` using protos files stored in the Go source tree.
Package protoc contains helpers for running `protoc` using protos files stored in the Go source tree.
Package protowalk contains routines for efficiently walking proto messages, focusing on the ability to react to field annotations.
Package protowalk contains routines for efficiently walking proto messages, focusing on the ability to react to field annotations.
Package realms contains LUCI Realms protobuf definitions.
Package realms contains LUCI Realms protobuf definitions.
Package reflectutil has an arbitrary assortment of helpers for dealing with protobuf reflection including:
Package reflectutil has an arbitrary assortment of helpers for dealing with protobuf reflection including:
Package sidecar contains APIs exposed by LUCI Sidecar server.
Package sidecar contains APIs exposed by LUCI Sidecar server.
Package srcman contains source manifest protobuf definitions.
Package srcman contains source manifest protobuf definitions.
Package structmask implements a functionality similar to google.protobuf.FieldMask, but which applies only to google.protobuf.Struct.
Package structmask implements a functionality similar to google.protobuf.FieldMask, but which applies only to google.protobuf.Struct.
Package textpb can reformat text protos to be prettier.
Package textpb can reformat text protos to be prettier.
internal
Package internal contains protos used internally in tests.
Package internal contains protos used internally in tests.

Jump to

Keyboard shortcuts

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