protobuf

package
v0.11.5 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// optional hedwig.MessageOptions message_options = 51235;
	E_MessageOptions = &file_hedwig_protobuf_options_proto_extTypes[0]
)

Extension fields to descriptorpb.MessageOptions.

View Source
var File_hedwig_protobuf_container_proto protoreflect.FileDescriptor
View Source
var File_hedwig_protobuf_options_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type EncoderDecoder added in v0.8.0

type EncoderDecoder struct {
	// contains filtered or unexported fields
}

EncoderDecoder is an implementation of hedwig.Encoder and hedwig.Decoder that uses Protobuf

func NewMessageEncoderDecoder added in v0.8.0

func NewMessageEncoderDecoder(protoMessages []proto.Message) (*EncoderDecoder, error)

NewMessageEncoderDecoder creates a new encoder from given list of proto-messages Proto messages must declare [hedwig.message_options](https://github.com/cloudchacho/hedwig/blob/main/protobuf/options.proto) option. See [example proto file](../examples/schema.proto) for reference.

This method will try to read message type from message_options, and if not specified, assume that the messages are named as: `<MessageType>V<MajorVersion>`. If that doesn't work for your use case, use NewMessageEncoderDecoderFromMessageTypes and provide an explicit mapping.

func NewMessageEncoderDecoderFromMessageTypes added in v0.8.0

func NewMessageEncoderDecoderFromMessageTypes(protoMessages map[hedwig.MessageTypeMajorVersion]protoreflect.Message) (*EncoderDecoder, error)

NewMessageEncoderDecoderFromMessageTypes creates a new encoder from explicit message types mapping

func (*EncoderDecoder) DecodeData added in v0.8.0

func (ed *EncoderDecoder) DecodeData(messageType string, version *semver.Version, data interface{}) (interface{}, error)

DecodeData validates and decodes data Type of data must be *anypb.Any for containerized format or []byte for non-containerized format

func (*EncoderDecoder) DecodeMessageType added in v0.8.0

func (ed *EncoderDecoder) DecodeMessageType(schema string) (string, *semver.Version, error)

DecodeMessageType decodes message type from meta attributes

func (*EncoderDecoder) EncodeData added in v0.8.0

func (ed *EncoderDecoder) EncodeData(data interface{}, useMessageTransport bool, metaAttrs hedwig.MetaAttributes) ([]byte, error)

EncodeData encodes the message with appropriate format for transport over the wire Type of data must be proto.Message

func (*EncoderDecoder) EncodeMessageType added in v0.8.0

func (ed *EncoderDecoder) EncodeMessageType(messageType string, version *semver.Version) string

EncodeMessageType encodes the message type with appropriate format for transport over the wire

func (*EncoderDecoder) ExtractData added in v0.8.0

func (ed *EncoderDecoder) ExtractData(messagePayload []byte, attributes map[string]string) (hedwig.MetaAttributes, interface{}, error)

ExtractData extracts data from the on-the-wire payload Type of data will be *anypb.Any

func (*EncoderDecoder) IsBinary added in v0.11.0

func (ed *EncoderDecoder) IsBinary() bool

IsBinary states prtobuf is a binary format

func (*EncoderDecoder) VerifyKnownMinorVersion added in v0.8.0

func (ed *EncoderDecoder) VerifyKnownMinorVersion(messageType string, version *semver.Version) error

VerifyKnownMinorVersion checks that message version is known to us

type MessageOptions

type MessageOptions struct {

	// major version for this message type. this is required
	MajorVersion *uint32 `protobuf:"varint,1,opt,name=major_version,json=majorVersion" json:"major_version,omitempty"`
	// minor version for this message type. this is optional since 0 is a valid minor version
	MinorVersion *uint32 `protobuf:"varint,2,opt,name=minor_version,json=minorVersion" json:"minor_version,omitempty"`
	// message type explicit declaration. this is optional and will be automatically
	// inferred from message name assuming this format: `<MessageType>V<MajorVersion>`.
	MessageType *string `protobuf:"bytes,3,opt,name=message_type,json=messageType" json:"message_type,omitempty"`
	// contains filtered or unexported fields
}

func (*MessageOptions) Descriptor deprecated

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

Deprecated: Use MessageOptions.ProtoReflect.Descriptor instead.

func (*MessageOptions) GetMajorVersion

func (x *MessageOptions) GetMajorVersion() uint32

func (*MessageOptions) GetMessageType

func (x *MessageOptions) GetMessageType() string

func (*MessageOptions) GetMinorVersion

func (x *MessageOptions) GetMinorVersion() uint32

func (*MessageOptions) ProtoMessage

func (*MessageOptions) ProtoMessage()

func (*MessageOptions) ProtoReflect

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

func (*MessageOptions) Reset

func (x *MessageOptions) Reset()

func (*MessageOptions) String

func (x *MessageOptions) String() string

type MetadataV1

type MetadataV1 struct {

	// Message publisher service
	Publisher string `protobuf:"bytes,1,opt,name=publisher,proto3" json:"publisher,omitempty"`
	// Publish timestamp in epoch milliseconds (integer)
	Timestamp *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	// Custom headers associated with the message
	Headers map[string]string `` /* 155-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*MetadataV1) Descriptor deprecated

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

Deprecated: Use MetadataV1.ProtoReflect.Descriptor instead.

func (*MetadataV1) GetHeaders

func (x *MetadataV1) GetHeaders() map[string]string

func (*MetadataV1) GetPublisher

func (x *MetadataV1) GetPublisher() string

func (*MetadataV1) GetTimestamp

func (x *MetadataV1) GetTimestamp() *timestamppb.Timestamp

func (*MetadataV1) ProtoMessage

func (*MetadataV1) ProtoMessage()

func (*MetadataV1) ProtoReflect

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

func (*MetadataV1) Reset

func (x *MetadataV1) Reset()

func (*MetadataV1) String

func (x *MetadataV1) String() string

type PayloadV1

type PayloadV1 struct {

	// Format version for the message
	FormatVersion string `protobuf:"bytes,1,opt,name=format_version,json=formatVersion,proto3" json:"format_version,omitempty"`
	// Message identifier
	Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"`
	// Metadata associated with the message
	Metadata *MetadataV1 `protobuf:"bytes,3,opt,name=metadata,proto3" json:"metadata,omitempty"`
	// Schema to validate the data object with - format: <message type>/<message data version>, e.g. TripCreated/1.0
	Schema string `protobuf:"bytes,4,opt,name=schema,proto3" json:"schema,omitempty"`
	// Message data
	Data *anypb.Any `protobuf:"bytes,5,opt,name=data,proto3" json:"data,omitempty"`
	// contains filtered or unexported fields
}

func (*PayloadV1) Descriptor deprecated

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

Deprecated: Use PayloadV1.ProtoReflect.Descriptor instead.

func (*PayloadV1) GetData

func (x *PayloadV1) GetData() *anypb.Any

func (*PayloadV1) GetFormatVersion

func (x *PayloadV1) GetFormatVersion() string

func (*PayloadV1) GetId

func (x *PayloadV1) GetId() string

func (*PayloadV1) GetMetadata

func (x *PayloadV1) GetMetadata() *MetadataV1

func (*PayloadV1) GetSchema

func (x *PayloadV1) GetSchema() string

func (*PayloadV1) ProtoMessage

func (*PayloadV1) ProtoMessage()

func (*PayloadV1) ProtoReflect

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

func (*PayloadV1) Reset

func (x *PayloadV1) Reset()

func (*PayloadV1) String

func (x *PayloadV1) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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