protobuf

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_crypto_proto protoreflect.FileDescriptor

Functions

func Marshal

func Marshal[M any, P Pointer[M], T Marshaler[P]](v T) ([]byte, error)

Marshal returns v's protobuf binary data by first converting v into its protobuf representation type M and then marshaling M into the protobuf wire format.

func Time

func Time(t time.Time) *pbt.Timestamp

Time returns a new protobuf timestamp from the given t.

func Unmarshal

func Unmarshal[M any, P Pointer[M], T Unmarshaler[P]](b []byte, v T) error

Unmarshal unmarshales v from b by first decoding b into v's protobuf representation M before converting M to v. It returns an error if b is not a valid protobuf representation of v.

Types

type HMACKey

type HMACKey struct {
	Key  []byte `protobuf:"bytes,1,opt,name=Key,json=key,proto3" json:"Key,omitempty"`
	Hash uint32 `protobuf:"varint,2,opt,name=Hash,json=hash,proto3" json:"Hash,omitempty"`
	// contains filtered or unexported fields
}

func (*HMACKey) Descriptor deprecated

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

Deprecated: Use HMACKey.ProtoReflect.Descriptor instead.

func (*HMACKey) GetHash

func (x *HMACKey) GetHash() uint32

func (*HMACKey) GetKey

func (x *HMACKey) GetKey() []byte

func (*HMACKey) ProtoMessage

func (*HMACKey) ProtoMessage()

func (*HMACKey) ProtoReflect

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

func (*HMACKey) Reset

func (x *HMACKey) Reset()

func (*HMACKey) String

func (x *HMACKey) String() string

type KeyVersion

type KeyVersion struct {
	Key       *SecretKey             `protobuf:"bytes,1,opt,name=Key,json=key,proto3" json:"Key,omitempty"`
	HMACKey   *HMACKey               `protobuf:"bytes,2,opt,name=HMACKey,json=hmac_key,proto3" json:"HMACKey,omitempty"`
	CreatedAt *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=CreatedAt,json=created_at,proto3" json:"CreatedAt,omitempty"`
	CreatedBy string                 `protobuf:"bytes,4,opt,name=CreatedBy,json=created_by,proto3" json:"CreatedBy,omitempty"`
	// contains filtered or unexported fields
}

func (*KeyVersion) Descriptor deprecated

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

Deprecated: Use KeyVersion.ProtoReflect.Descriptor instead.

func (*KeyVersion) GetCreatedAt

func (x *KeyVersion) GetCreatedAt() *timestamppb.Timestamp

func (*KeyVersion) GetCreatedBy

func (x *KeyVersion) GetCreatedBy() string

func (*KeyVersion) GetHMACKey

func (x *KeyVersion) GetHMACKey() *HMACKey

func (*KeyVersion) GetKey

func (x *KeyVersion) GetKey() *SecretKey

func (*KeyVersion) ProtoMessage

func (*KeyVersion) ProtoMessage()

func (*KeyVersion) ProtoReflect

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

func (*KeyVersion) Reset

func (x *KeyVersion) Reset()

func (*KeyVersion) String

func (x *KeyVersion) String() string

type Marshaler

type Marshaler[T proto.Message] interface {
	MarshalPB(T) error
}

Marshaler is an interface implemented by types that know how to marshal themselves into their protobuf representation T.

type Pointer

type Pointer[M any] interface {
	proto.Message
	*M // Anything implementing Pointer must also be a pointer type of M
}

Pointer is a type constraint used to express that some type P is a pointer of some other type T such that:

var t T
var p P = &t

This proposition is useful when unmarshalling data into types without additional dynamic dispatch or heap allocations.

A generic function that wants to use the default value of some type T but also wants to call pointer receiver methods on instances of T has to have two type parameters:

func foo[T any, P pointer[T]]() {
    var t T
    var p P = &t
}

This functionality cannot be achieved with a single type parameter because:

func foo[T proto.Message]() {
    var t T             // compiles but t is nil if T is a pointer type
    var t2 T = *new(T)  // compiles but t2 is nil if T is a pointer type
    var t3 = T{}        // compiler error - e.g. T may be a pointer type
}

type SecretKey

type SecretKey struct {
	Key  []byte `protobuf:"bytes,1,opt,name=Key,json=key,proto3" json:"Key,omitempty"`
	Type uint32 `protobuf:"varint,2,opt,name=Type,json=type,proto3" json:"Type,omitempty"`
	// contains filtered or unexported fields
}

func (*SecretKey) Descriptor deprecated

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

Deprecated: Use SecretKey.ProtoReflect.Descriptor instead.

func (*SecretKey) GetKey

func (x *SecretKey) GetKey() []byte

func (*SecretKey) GetType

func (x *SecretKey) GetType() uint32

func (*SecretKey) ProtoMessage

func (*SecretKey) ProtoMessage()

func (*SecretKey) ProtoReflect

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

func (*SecretKey) Reset

func (x *SecretKey) Reset()

func (*SecretKey) String

func (x *SecretKey) String() string

type Unmarshaler

type Unmarshaler[T proto.Message] interface {
	UnmarshalPB(T) error
}

Unmarshaler is an interface implemented by types that know how to unmarshal themselves from their protobuf representation T.

Jump to

Keyboard shortcuts

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