Package protocmp provides protobuf specific options for the github.com/google/go-cmp/cmp package.
The primary feature is the Transform option, which transform proto.Message types into a Message map that is suitable for cmp to introspect upon. All other options in this package must be used in conjunction with Transform.
This section is empty.
This section is empty.
FilterEnum filters opt to only be applicable on a standalone Enum, singular fields of enums, list fields of enums, or map fields of enum values, where the enum is the same type as the specified enum.
The Go type of the last path step may be an:
This must be used in conjunction with Transform.
FilterField filters opt to only be applicable on the specified field in the message. It panics if a field of the given name does not exist.
The Go type of the last path step may be an:
This must be used in conjunction with Transform.
FilterMessage filters opt to only be applicable on a standalone Message values, singular fields of messages, list fields of messages, or map fields of message values, where the message is the same type as the specified message.
The Go type of the last path step may be an:
This must be used in conjunction with Transform.
FilterOneof filters opt to only be applicable on all fields within the specified oneof in the message. It panics if a oneof of the given name does not exist.
The Go type of the last path step may be an:
This must be used in conjunction with Transform.
IgnoreDefaultScalars ignores singular scalars that are unpopulated or explicitly set to the default value. This option does not effect elements in a list or entries in a map.
This must be used in conjunction with Transform.
IgnoreDescriptors ignores the specified set of descriptors. It is equivalent to FilterDescriptor(desc, cmp.Ignore()) for each descriptor.
This must be used in conjunction with Transform.
IgnoreEmptyMessages ignores messages that are empty or unpopulated. It applies to standalone Message values, singular message fields, list fields of messages, and map fields of message values.
This must be used in conjunction with Transform.
IgnoreEnums ignores all enums of the specified types. It is equivalent to FilterEnum(enum, cmp.Ignore()) for each enum.
This must be used in conjunction with Transform.
IgnoreFields ignores the specified fields in the specified message. It is equivalent to FilterField(message, name, cmp.Ignore()) for each field in the message.
This must be used in conjunction with Transform.
IgnoreMessages ignores all messages of the specified types. It is equivalent to FilterMessage(message, cmp.Ignore()) for each message.
This must be used in conjunction with Transform.
IgnoreOneofs ignores fields of the specified oneofs in the specified message. It is equivalent to FilterOneof(message, name, cmp.Ignore()) for each oneof in the message.
This must be used in conjunction with Transform.
IgnoreUnknown ignores unknown fields in all messages.
This must be used in conjunction with Transform.
MessageTypeResolver overrides the resolver used for messages packed inside Any. The default is protoregistry.GlobalTypes, which is sufficient for all compiled-in Protobuf messages. Overriding the resolver is useful in tests that dynamically create Protobuf descriptors and messages, e.g. in proxies using dynamicpb.
SortRepeated sorts repeated fields of the specified element type. The less function must be of the form "func(T, T) bool" where T is the Go element type for the repeated field kind.
The element type T can be one of the following:
This option only applies to repeated fields within a protobuf message. It does not operate on higher-order Go types that seem like a repeated field. For example, a []T outside the context of a protobuf message will not be handled by this option. To sort Go slices that are not repeated fields, consider using github.com/google/go-cmp/cmp/cmpopts.SortSlices instead.
The sorting of messages does not take into account ignored fields or oneofs as a result of IgnoreFields or IgnoreOneofs.
This must be used in conjunction with Transform.
SortRepeatedFields sorts the specified repeated fields. Sorting a repeated field is useful for treating the list as a multiset (i.e., a set where each value can appear multiple times). It panics if the field does not exist or is not a repeated field.
The sort ordering is as follows:
The ordering chosen for repeated messages is unlikely to be aesthetically preferred by humans. Consider using a custom sort function:
FilterField(m, "foo_field", SortRepeated(func(x, y *foopb.MyMessage) bool { ... // user-provided definition for less }))
The sorting of messages does not take into account ignored fields or oneofs as a result of IgnoreFields or IgnoreOneofs.
This must be used in conjunction with Transform.
Transform returns a cmp.Option that converts each proto.Message to a Message. The transformation does not mutate nor alias any converted messages.
The google.protobuf.Any message is automatically unmarshaled such that the "value" field is a Message representing the underlying message value assuming it could be resolved and properly unmarshaled.
This does not directly transform higher-order composite Go types. For example, []*foopb.Message is not transformed into []Message, but rather the individual message elements of the slice are transformed.
Enum is a dynamic representation of a protocol buffer enum that is suitable for cmp.Equal and cmp.Diff to compare upon.
Descriptor returns the enum descriptor. It returns nil for a zero Enum value.
Equal reports whether e1 and e2 represent the same enum value.
Number returns the enum value as an integer.
String returns the name of the enum value if known (e.g., "ENUM_VALUE"), otherwise it returns the formatted decimal enum number (e.g., "14").
Message is a dynamic representation of a protocol buffer message that is suitable for cmp.Equal and cmp.Diff to directly operate upon.
Every populated known field (excluding extension fields) is stored in the map with the key being the short name of the field (e.g., "field_name") and the value determined by the kind and cardinality of the field.
Singular scalars are represented by the same Go type as protoreflect.Value, singular messages are represented by the Message type, singular enums are represented by the Enum type, list fields are represented as a Go slice, and map fields are represented as a Go map.
Every populated extension field is stored in the map with the key being the full name of the field surrounded by brackets (e.g., "[extension.full.name]") and the value determined according to the same rules as known fields.
Every unknown field is stored in the map with the key being the field number encoded as a decimal string (e.g., "132") and the value being the raw bytes of the encoded field (as the protoreflect.RawFields type).
Message values must not be created by or mutated by users.
Descriptor return the message descriptor. It returns nil for a zero Message value.
ProtoMessage is a marker method from the legacy message interface.
ProtoReflect returns a reflective view of m. It only implements the read-only operations of protoreflect.Message. Calling any mutating operations on m panics.
Reset is the required Reset method from the legacy message interface.
String returns a formatted string for the message. It is intended for human debugging and has no guarantees about its exact format or the stability of its output.
Unwrap returns the original message value. It returns nil if this Message was not constructed from another message.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4