From 83730f24921f12ee64d07e6a9534237976376bf4 Mon Sep 17 00:00:00 2001 From: Benjamin Bengfort Date: Fri, 25 Oct 2024 12:40:04 -0400 Subject: [PATCH] Tests Cleanup (#33) --- go.mod | 1 - go.sum | 6 - pkg/object/generate.go | 3 - pkg/object/generate.sh | 22 - pkg/object/v1/object.pb.go | 948 ----------------------------------- pkg/store/decode.go | 6 + pkg/store/decode_test.go | 370 ++++++++++++++ pkg/store/encode.go | 4 + pkg/store/encode_test.go | 205 ++++++++ pkg/store/mock.go | 32 ++ pkg/store/object_test.go | 207 +------- proto/object/v1/object.proto | 112 ----- 12 files changed, 635 insertions(+), 1281 deletions(-) delete mode 100644 pkg/object/generate.go delete mode 100755 pkg/object/generate.sh delete mode 100644 pkg/object/v1/object.pb.go create mode 100644 pkg/store/decode_test.go create mode 100644 pkg/store/mock.go delete mode 100644 proto/object/v1/object.proto diff --git a/go.mod b/go.mod index cbcdf03..1ad1560 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/rs/zerolog v1.33.0 github.com/stretchr/testify v1.9.0 github.com/urfave/cli/v2 v2.27.5 - google.golang.org/protobuf v1.35.1 ) require ( diff --git a/go.sum b/go.sum index 15f5b9b..cc29280 100644 --- a/go.sum +++ b/go.sum @@ -4,8 +4,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -35,10 +33,6 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/pkg/object/generate.go b/pkg/object/generate.go deleted file mode 100644 index 16281af..0000000 --- a/pkg/object/generate.go +++ /dev/null @@ -1,3 +0,0 @@ -package object - -//go:generate bash generate.sh diff --git a/pkg/object/generate.sh b/pkg/object/generate.sh deleted file mode 100755 index 2e1a1df..0000000 --- a/pkg/object/generate.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -PROTOS="${GOPATH}/src/github.com/rotationalio/honu/proto" - -if [[ ! -d $PROTOS ]]; then - echo "cannot find ${PROTOS}" - exit 1 -fi - -MODULE="github.com/rotationalio/honu/pkg/object/v1" -MOD="github.com/rotationalio/honu/pkg/object/v1;object" -OUT="./v1" - -if [[ ! -d $OUT ]]; then - mkdir $OUT -fi - -protoc -I=${PROTOS} \ - --go_out=${OUT} \ - --go_opt=module="${MODULE}" \ - --go_opt=Mobject/v1/object.proto="${MOD}" \ - object/v1/object.proto \ No newline at end of file diff --git a/pkg/object/v1/object.pb.go b/pkg/object/v1/object.pb.go deleted file mode 100644 index c903978..0000000 --- a/pkg/object/v1/object.pb.go +++ /dev/null @@ -1,948 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.34.2 -// protoc v5.28.2 -// source: object/v1/object.proto - -package object - -import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" - reflect "reflect" - sync "sync" -) - -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) - -type Encryption_Algorithm int32 - -const ( - // No cryptography is being used - Encryption_PLAINTEXT Encryption_Algorithm = 0 - // Encryption Algorithms - Encryption_AES256_GCM Encryption_Algorithm = 110 - Encryption_AES192_GCM Encryption_Algorithm = 120 - Encryption_AES128_GCM Encryption_Algorithm = 130 - // Signature Algorithms - Encryption_HMAC_SHA256 Encryption_Algorithm = 310 - // Sealing Algorithms (Asymmetric) - Encryption_RSA_OAEP_SHA512 Encryption_Algorithm = 510 -) - -// Enum value maps for Encryption_Algorithm. -var ( - Encryption_Algorithm_name = map[int32]string{ - 0: "PLAINTEXT", - 110: "AES256_GCM", - 120: "AES192_GCM", - 130: "AES128_GCM", - 310: "HMAC_SHA256", - 510: "RSA_OAEP_SHA512", - } - Encryption_Algorithm_value = map[string]int32{ - "PLAINTEXT": 0, - "AES256_GCM": 110, - "AES192_GCM": 120, - "AES128_GCM": 130, - "HMAC_SHA256": 310, - "RSA_OAEP_SHA512": 510, - } -) - -func (x Encryption_Algorithm) Enum() *Encryption_Algorithm { - p := new(Encryption_Algorithm) - *p = x - return p -} - -func (x Encryption_Algorithm) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (Encryption_Algorithm) Descriptor() protoreflect.EnumDescriptor { - return file_object_v1_object_proto_enumTypes[0].Descriptor() -} - -func (Encryption_Algorithm) Type() protoreflect.EnumType { - return &file_object_v1_object_proto_enumTypes[0] -} - -func (x Encryption_Algorithm) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use Encryption_Algorithm.Descriptor instead. -func (Encryption_Algorithm) EnumDescriptor() ([]byte, []int) { - return file_object_v1_object_proto_rawDescGZIP(), []int{4, 0} -} - -type Compression_Algorithm int32 - -const ( - Compression_NONE Compression_Algorithm = 0 - Compression_GZIP Compression_Algorithm = 1 - Compression_COMPRESS Compression_Algorithm = 2 - Compression_DEFLATE Compression_Algorithm = 3 - Compression_BROTLI Compression_Algorithm = 4 -) - -// Enum value maps for Compression_Algorithm. -var ( - Compression_Algorithm_name = map[int32]string{ - 0: "NONE", - 1: "GZIP", - 2: "COMPRESS", - 3: "DEFLATE", - 4: "BROTLI", - } - Compression_Algorithm_value = map[string]int32{ - "NONE": 0, - "GZIP": 1, - "COMPRESS": 2, - "DEFLATE": 3, - "BROTLI": 4, - } -) - -func (x Compression_Algorithm) Enum() *Compression_Algorithm { - p := new(Compression_Algorithm) - *p = x - return p -} - -func (x Compression_Algorithm) String() string { - return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) -} - -func (Compression_Algorithm) Descriptor() protoreflect.EnumDescriptor { - return file_object_v1_object_proto_enumTypes[1].Descriptor() -} - -func (Compression_Algorithm) Type() protoreflect.EnumType { - return &file_object_v1_object_proto_enumTypes[1] -} - -func (x Compression_Algorithm) Number() protoreflect.EnumNumber { - return protoreflect.EnumNumber(x) -} - -// Deprecated: Use Compression_Algorithm.Descriptor instead. -func (Compression_Algorithm) EnumDescriptor() ([]byte, []int) { - return file_object_v1_object_proto_rawDescGZIP(), []int{5, 0} -} - -type Object struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Version *Version `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` - Schema *SchemaVersion `protobuf:"bytes,2,opt,name=schema,proto3" json:"schema,omitempty"` - Mimetype string `protobuf:"bytes,3,opt,name=mimetype,proto3" json:"mimetype,omitempty"` - // Access Controls - Owner []byte `protobuf:"bytes,4,opt,name=owner,proto3" json:"owner,omitempty"` - Group []byte `protobuf:"bytes,5,opt,name=group,proto3" json:"group,omitempty"` - Permissions []byte `protobuf:"bytes,6,opt,name=permissions,proto3" json:"permissions,omitempty"` - Acl []*ACL `protobuf:"bytes,7,rep,name=acl,proto3" json:"acl,omitempty"` - // Provenance Information - WriteRegions []string `protobuf:"bytes,8,rep,name=WriteRegions,proto3" json:"WriteRegions,omitempty"` - Publisher *Publisher `protobuf:"bytes,9,opt,name=publisher,proto3" json:"publisher,omitempty"` - // Read Information - Encryption *Encryption `protobuf:"bytes,10,opt,name=encryption,proto3" json:"encryption,omitempty"` - Compression *Compression `protobuf:"bytes,11,opt,name=compression,proto3" json:"compression,omitempty"` - // Flags - Flags []byte `protobuf:"bytes,12,opt,name=flags,proto3" json:"flags,omitempty"` - // Modification Timestamps - Created *timestamppb.Timestamp `protobuf:"bytes,13,opt,name=created,proto3" json:"created,omitempty"` - Modified *timestamppb.Timestamp `protobuf:"bytes,14,opt,name=modified,proto3" json:"modified,omitempty"` - // The actual data of the object - Data []byte `protobuf:"bytes,15,opt,name=data,proto3" json:"data,omitempty"` -} - -func (x *Object) Reset() { - *x = Object{} - if protoimpl.UnsafeEnabled { - mi := &file_object_v1_object_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Object) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Object) ProtoMessage() {} - -func (x *Object) ProtoReflect() protoreflect.Message { - mi := &file_object_v1_object_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Object.ProtoReflect.Descriptor instead. -func (*Object) Descriptor() ([]byte, []int) { - return file_object_v1_object_proto_rawDescGZIP(), []int{0} -} - -func (x *Object) GetVersion() *Version { - if x != nil { - return x.Version - } - return nil -} - -func (x *Object) GetSchema() *SchemaVersion { - if x != nil { - return x.Schema - } - return nil -} - -func (x *Object) GetMimetype() string { - if x != nil { - return x.Mimetype - } - return "" -} - -func (x *Object) GetOwner() []byte { - if x != nil { - return x.Owner - } - return nil -} - -func (x *Object) GetGroup() []byte { - if x != nil { - return x.Group - } - return nil -} - -func (x *Object) GetPermissions() []byte { - if x != nil { - return x.Permissions - } - return nil -} - -func (x *Object) GetAcl() []*ACL { - if x != nil { - return x.Acl - } - return nil -} - -func (x *Object) GetWriteRegions() []string { - if x != nil { - return x.WriteRegions - } - return nil -} - -func (x *Object) GetPublisher() *Publisher { - if x != nil { - return x.Publisher - } - return nil -} - -func (x *Object) GetEncryption() *Encryption { - if x != nil { - return x.Encryption - } - return nil -} - -func (x *Object) GetCompression() *Compression { - if x != nil { - return x.Compression - } - return nil -} - -func (x *Object) GetFlags() []byte { - if x != nil { - return x.Flags - } - return nil -} - -func (x *Object) GetCreated() *timestamppb.Timestamp { - if x != nil { - return x.Created - } - return nil -} - -func (x *Object) GetModified() *timestamppb.Timestamp { - if x != nil { - return x.Modified - } - return nil -} - -func (x *Object) GetData() []byte { - if x != nil { - return x.Data - } - return nil -} - -// Implements a geo-distributed version as a Lamport Scalar -type Version struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Pid uint64 `protobuf:"varint,1,opt,name=pid,proto3" json:"pid,omitempty"` // Process ID - used to deconflict ties in the version number. - Version uint64 `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"` // Montonically increasing version number. - Region string `protobuf:"bytes,3,opt,name=region,proto3" json:"region,omitempty"` // The region where the change occurred to track multi-region handling. - Parent *Version `protobuf:"bytes,4,opt,name=parent,proto3" json:"parent,omitempty"` // In order to get a complete version history, identify the predessor; for compact data transfer parent should not be defined in parent version. - Tombstone bool `protobuf:"varint,5,opt,name=tombstone,proto3" json:"tombstone,omitempty"` // Set to true in order to mark the object as deleted - // The timestamp that the version was created (e.g. the last modified date). - Created *timestamppb.Timestamp `protobuf:"bytes,15,opt,name=created,proto3" json:"created,omitempty"` -} - -func (x *Version) Reset() { - *x = Version{} - if protoimpl.UnsafeEnabled { - mi := &file_object_v1_object_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Version) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Version) ProtoMessage() {} - -func (x *Version) ProtoReflect() protoreflect.Message { - mi := &file_object_v1_object_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Version.ProtoReflect.Descriptor instead. -func (*Version) Descriptor() ([]byte, []int) { - return file_object_v1_object_proto_rawDescGZIP(), []int{1} -} - -func (x *Version) GetPid() uint64 { - if x != nil { - return x.Pid - } - return 0 -} - -func (x *Version) GetVersion() uint64 { - if x != nil { - return x.Version - } - return 0 -} - -func (x *Version) GetRegion() string { - if x != nil { - return x.Region - } - return "" -} - -func (x *Version) GetParent() *Version { - if x != nil { - return x.Parent - } - return nil -} - -func (x *Version) GetTombstone() bool { - if x != nil { - return x.Tombstone - } - return false -} - -func (x *Version) GetCreated() *timestamppb.Timestamp { - if x != nil { - return x.Created - } - return nil -} - -// An event type is composed of a name and a version so that the type can be looked up -// in the schema registry. The schema can then be used to validate the data inside the -// event. Schemas are optional but types are not unless the mimetype requries a schema -// for deserialization (e.g. protobuf, parquet, avro, etc.). -type SchemaVersion struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - MajorVersion uint32 `protobuf:"varint,2,opt,name=major_version,json=majorVersion,proto3" json:"major_version,omitempty"` - MinorVersion uint32 `protobuf:"varint,3,opt,name=minor_version,json=minorVersion,proto3" json:"minor_version,omitempty"` - PatchVersion uint32 `protobuf:"varint,4,opt,name=patch_version,json=patchVersion,proto3" json:"patch_version,omitempty"` -} - -func (x *SchemaVersion) Reset() { - *x = SchemaVersion{} - if protoimpl.UnsafeEnabled { - mi := &file_object_v1_object_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *SchemaVersion) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*SchemaVersion) ProtoMessage() {} - -func (x *SchemaVersion) ProtoReflect() protoreflect.Message { - mi := &file_object_v1_object_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use SchemaVersion.ProtoReflect.Descriptor instead. -func (*SchemaVersion) Descriptor() ([]byte, []int) { - return file_object_v1_object_proto_rawDescGZIP(), []int{2} -} - -func (x *SchemaVersion) GetName() string { - if x != nil { - return x.Name - } - return "" -} - -func (x *SchemaVersion) GetMajorVersion() uint32 { - if x != nil { - return x.MajorVersion - } - return 0 -} - -func (x *SchemaVersion) GetMinorVersion() uint32 { - if x != nil { - return x.MinorVersion - } - return 0 -} - -func (x *SchemaVersion) GetPatchVersion() uint32 { - if x != nil { - return x.PatchVersion - } - return 0 -} - -type ACL struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - ClientId []byte `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` - Permissions []byte `protobuf:"bytes,2,opt,name=permissions,proto3" json:"permissions,omitempty"` -} - -func (x *ACL) Reset() { - *x = ACL{} - if protoimpl.UnsafeEnabled { - mi := &file_object_v1_object_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *ACL) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*ACL) ProtoMessage() {} - -func (x *ACL) ProtoReflect() protoreflect.Message { - mi := &file_object_v1_object_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use ACL.ProtoReflect.Descriptor instead. -func (*ACL) Descriptor() ([]byte, []int) { - return file_object_v1_object_proto_rawDescGZIP(), []int{3} -} - -func (x *ACL) GetClientId() []byte { - if x != nil { - return x.ClientId - } - return nil -} - -func (x *ACL) GetPermissions() []byte { - if x != nil { - return x.Permissions - } - return nil -} - -// Metadata about the cryptography used to secure the event. -type Encryption struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - PublicKeyId string `protobuf:"bytes,1,opt,name=public_key_id,json=publicKeyId,proto3" json:"public_key_id,omitempty"` - EncryptionKey []byte `protobuf:"bytes,2,opt,name=encryption_key,json=encryptionKey,proto3" json:"encryption_key,omitempty"` - HmacSecret []byte `protobuf:"bytes,3,opt,name=hmac_secret,json=hmacSecret,proto3" json:"hmac_secret,omitempty"` - Signature []byte `protobuf:"bytes,4,opt,name=signature,proto3" json:"signature,omitempty"` - SealingAlgorithm Encryption_Algorithm `protobuf:"varint,5,opt,name=sealing_algorithm,json=sealingAlgorithm,proto3,enum=object.v1.Encryption_Algorithm" json:"sealing_algorithm,omitempty"` - EncryptionAlgorithm Encryption_Algorithm `protobuf:"varint,6,opt,name=encryption_algorithm,json=encryptionAlgorithm,proto3,enum=object.v1.Encryption_Algorithm" json:"encryption_algorithm,omitempty"` - SignatureAlgorithm Encryption_Algorithm `protobuf:"varint,7,opt,name=signature_algorithm,json=signatureAlgorithm,proto3,enum=object.v1.Encryption_Algorithm" json:"signature_algorithm,omitempty"` -} - -func (x *Encryption) Reset() { - *x = Encryption{} - if protoimpl.UnsafeEnabled { - mi := &file_object_v1_object_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Encryption) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Encryption) ProtoMessage() {} - -func (x *Encryption) ProtoReflect() protoreflect.Message { - mi := &file_object_v1_object_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Encryption.ProtoReflect.Descriptor instead. -func (*Encryption) Descriptor() ([]byte, []int) { - return file_object_v1_object_proto_rawDescGZIP(), []int{4} -} - -func (x *Encryption) GetPublicKeyId() string { - if x != nil { - return x.PublicKeyId - } - return "" -} - -func (x *Encryption) GetEncryptionKey() []byte { - if x != nil { - return x.EncryptionKey - } - return nil -} - -func (x *Encryption) GetHmacSecret() []byte { - if x != nil { - return x.HmacSecret - } - return nil -} - -func (x *Encryption) GetSignature() []byte { - if x != nil { - return x.Signature - } - return nil -} - -func (x *Encryption) GetSealingAlgorithm() Encryption_Algorithm { - if x != nil { - return x.SealingAlgorithm - } - return Encryption_PLAINTEXT -} - -func (x *Encryption) GetEncryptionAlgorithm() Encryption_Algorithm { - if x != nil { - return x.EncryptionAlgorithm - } - return Encryption_PLAINTEXT -} - -func (x *Encryption) GetSignatureAlgorithm() Encryption_Algorithm { - if x != nil { - return x.SignatureAlgorithm - } - return Encryption_PLAINTEXT -} - -// Metadata about compression used to reduce the storage size of the event. -type Compression struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Algorithm Compression_Algorithm `protobuf:"varint,1,opt,name=algorithm,proto3,enum=object.v1.Compression_Algorithm" json:"algorithm,omitempty"` - Level int64 `protobuf:"varint,2,opt,name=level,proto3" json:"level,omitempty"` -} - -func (x *Compression) Reset() { - *x = Compression{} - if protoimpl.UnsafeEnabled { - mi := &file_object_v1_object_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Compression) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Compression) ProtoMessage() {} - -func (x *Compression) ProtoReflect() protoreflect.Message { - mi := &file_object_v1_object_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Compression.ProtoReflect.Descriptor instead. -func (*Compression) Descriptor() ([]byte, []int) { - return file_object_v1_object_proto_rawDescGZIP(), []int{5} -} - -func (x *Compression) GetAlgorithm() Compression_Algorithm { - if x != nil { - return x.Algorithm - } - return Compression_NONE -} - -func (x *Compression) GetLevel() int64 { - if x != nil { - return x.Level - } - return 0 -} - -// Information about the publisher of the event for provenance and auditing purposes. -type Publisher struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - PublisherId []byte `protobuf:"bytes,1,opt,name=publisher_id,json=publisherId,proto3" json:"publisher_id,omitempty"` - ClientId []byte `protobuf:"bytes,2,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"` - IpAddr string `protobuf:"bytes,3,opt,name=ip_addr,json=ipAddr,proto3" json:"ip_addr,omitempty"` - UserAgent string `protobuf:"bytes,4,opt,name=user_agent,json=userAgent,proto3" json:"user_agent,omitempty"` -} - -func (x *Publisher) Reset() { - *x = Publisher{} - if protoimpl.UnsafeEnabled { - mi := &file_object_v1_object_proto_msgTypes[6] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *Publisher) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*Publisher) ProtoMessage() {} - -func (x *Publisher) ProtoReflect() protoreflect.Message { - mi := &file_object_v1_object_proto_msgTypes[6] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) -} - -// Deprecated: Use Publisher.ProtoReflect.Descriptor instead. -func (*Publisher) Descriptor() ([]byte, []int) { - return file_object_v1_object_proto_rawDescGZIP(), []int{6} -} - -func (x *Publisher) GetPublisherId() []byte { - if x != nil { - return x.PublisherId - } - return nil -} - -func (x *Publisher) GetClientId() []byte { - if x != nil { - return x.ClientId - } - return nil -} - -func (x *Publisher) GetIpAddr() string { - if x != nil { - return x.IpAddr - } - return "" -} - -func (x *Publisher) GetUserAgent() string { - if x != nil { - return x.UserAgent - } - return "" -} - -var File_object_v1_object_proto protoreflect.FileDescriptor - -var file_object_v1_object_proto_rawDesc = []byte{ - 0x0a, 0x16, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2f, 0x76, 0x31, 0x2f, 0x6f, 0x62, 0x6a, 0x65, - 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, - 0x2e, 0x76, 0x31, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd5, 0x04, 0x0a, 0x06, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, - 0x2c, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x12, 0x2e, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x65, 0x72, - 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x30, 0x0a, - 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, - 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, - 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x12, - 0x1a, 0x0a, 0x08, 0x6d, 0x69, 0x6d, 0x65, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x6d, 0x69, 0x6d, 0x65, 0x74, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6f, - 0x77, 0x6e, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x6f, 0x77, 0x6e, 0x65, - 0x72, 0x12, 0x14, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x65, 0x72, 0x6d, 0x69, - 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x70, 0x65, - 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x20, 0x0a, 0x03, 0x61, 0x63, 0x6c, - 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2e, - 0x76, 0x31, 0x2e, 0x41, 0x43, 0x4c, 0x52, 0x03, 0x61, 0x63, 0x6c, 0x12, 0x22, 0x0a, 0x0c, 0x57, - 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, - 0x09, 0x52, 0x0c, 0x57, 0x72, 0x69, 0x74, 0x65, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x73, 0x12, - 0x32, 0x0a, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x72, 0x18, 0x09, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x50, - 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x72, 0x52, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, - 0x68, 0x65, 0x72, 0x12, 0x35, 0x0a, 0x0a, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, - 0x6e, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, - 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, - 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x38, 0x0a, 0x0b, 0x63, 0x6f, - 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x16, 0x2e, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x70, - 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x63, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, - 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x18, 0x0c, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x05, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x12, 0x34, 0x0a, 0x07, 0x63, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, - 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, - 0x12, 0x36, 0x0a, 0x08, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x18, 0x0e, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x08, - 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x69, 0x65, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, - 0x18, 0x0f, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0xcd, 0x01, 0x0a, - 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x70, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, 0x70, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, - 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x07, 0x76, 0x65, 0x72, - 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x12, 0x2a, 0x0a, 0x06, - 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x6f, - 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, - 0x52, 0x06, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x6f, 0x6d, 0x62, - 0x73, 0x74, 0x6f, 0x6e, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x74, 0x6f, 0x6d, - 0x62, 0x73, 0x74, 0x6f, 0x6e, 0x65, 0x12, 0x34, 0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x64, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, - 0x61, 0x6d, 0x70, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x22, 0x92, 0x01, 0x0a, - 0x0d, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x12, - 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x6d, 0x61, 0x6a, 0x6f, 0x72, 0x5f, 0x76, 0x65, 0x72, 0x73, - 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0c, 0x6d, 0x61, 0x6a, 0x6f, 0x72, - 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x23, 0x0a, 0x0d, 0x6d, 0x69, 0x6e, 0x6f, 0x72, - 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0c, - 0x6d, 0x69, 0x6e, 0x6f, 0x72, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x23, 0x0a, 0x0d, - 0x70, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x0d, 0x52, 0x0c, 0x70, 0x61, 0x74, 0x63, 0x68, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, - 0x6e, 0x22, 0x44, 0x0a, 0x03, 0x41, 0x43, 0x4c, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x6c, 0x69, 0x65, - 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x63, 0x6c, 0x69, - 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x20, 0x0a, 0x0b, 0x70, 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, - 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x70, 0x65, 0x72, 0x6d, - 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0xff, 0x03, 0x0a, 0x0a, 0x45, 0x6e, 0x63, 0x72, - 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x22, 0x0a, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, - 0x5f, 0x6b, 0x65, 0x79, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, - 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x49, 0x64, 0x12, 0x25, 0x0a, 0x0e, 0x65, 0x6e, - 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x0d, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x4b, 0x65, - 0x79, 0x12, 0x1f, 0x0a, 0x0b, 0x68, 0x6d, 0x61, 0x63, 0x5f, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x68, 0x6d, 0x61, 0x63, 0x53, 0x65, 0x63, 0x72, - 0x65, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, - 0x12, 0x4c, 0x0a, 0x11, 0x73, 0x65, 0x61, 0x6c, 0x69, 0x6e, 0x67, 0x5f, 0x61, 0x6c, 0x67, 0x6f, - 0x72, 0x69, 0x74, 0x68, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1f, 0x2e, 0x6f, 0x62, - 0x6a, 0x65, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, - 0x6f, 0x6e, 0x2e, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x52, 0x10, 0x73, 0x65, - 0x61, 0x6c, 0x69, 0x6e, 0x67, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x12, 0x52, - 0x0a, 0x14, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x61, 0x6c, 0x67, - 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1f, 0x2e, 0x6f, - 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x52, 0x13, 0x65, - 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, - 0x68, 0x6d, 0x12, 0x50, 0x0a, 0x13, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x5f, - 0x61, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0e, 0x32, - 0x1f, 0x2e, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6e, 0x63, 0x72, - 0x79, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, - 0x52, 0x12, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x41, 0x6c, 0x67, 0x6f, 0x72, - 0x69, 0x74, 0x68, 0x6d, 0x22, 0x73, 0x0a, 0x09, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, - 0x6d, 0x12, 0x0d, 0x0a, 0x09, 0x50, 0x4c, 0x41, 0x49, 0x4e, 0x54, 0x45, 0x58, 0x54, 0x10, 0x00, - 0x12, 0x0e, 0x0a, 0x0a, 0x41, 0x45, 0x53, 0x32, 0x35, 0x36, 0x5f, 0x47, 0x43, 0x4d, 0x10, 0x6e, - 0x12, 0x0e, 0x0a, 0x0a, 0x41, 0x45, 0x53, 0x31, 0x39, 0x32, 0x5f, 0x47, 0x43, 0x4d, 0x10, 0x78, - 0x12, 0x0f, 0x0a, 0x0a, 0x41, 0x45, 0x53, 0x31, 0x32, 0x38, 0x5f, 0x47, 0x43, 0x4d, 0x10, 0x82, - 0x01, 0x12, 0x10, 0x0a, 0x0b, 0x48, 0x4d, 0x41, 0x43, 0x5f, 0x53, 0x48, 0x41, 0x32, 0x35, 0x36, - 0x10, 0xb6, 0x02, 0x12, 0x14, 0x0a, 0x0f, 0x52, 0x53, 0x41, 0x5f, 0x4f, 0x41, 0x45, 0x50, 0x5f, - 0x53, 0x48, 0x41, 0x35, 0x31, 0x32, 0x10, 0xfe, 0x03, 0x22, 0xab, 0x01, 0x0a, 0x0b, 0x43, 0x6f, - 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x3e, 0x0a, 0x09, 0x61, 0x6c, 0x67, - 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x20, 0x2e, 0x6f, - 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, - 0x73, 0x69, 0x6f, 0x6e, 0x2e, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x52, 0x09, - 0x61, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x65, 0x76, - 0x65, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x22, - 0x46, 0x0a, 0x09, 0x41, 0x6c, 0x67, 0x6f, 0x72, 0x69, 0x74, 0x68, 0x6d, 0x12, 0x08, 0x0a, 0x04, - 0x4e, 0x4f, 0x4e, 0x45, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, 0x47, 0x5a, 0x49, 0x50, 0x10, 0x01, - 0x12, 0x0c, 0x0a, 0x08, 0x43, 0x4f, 0x4d, 0x50, 0x52, 0x45, 0x53, 0x53, 0x10, 0x02, 0x12, 0x0b, - 0x0a, 0x07, 0x44, 0x45, 0x46, 0x4c, 0x41, 0x54, 0x45, 0x10, 0x03, 0x12, 0x0a, 0x0a, 0x06, 0x42, - 0x52, 0x4f, 0x54, 0x4c, 0x49, 0x10, 0x04, 0x22, 0x83, 0x01, 0x0a, 0x09, 0x50, 0x75, 0x62, 0x6c, - 0x69, 0x73, 0x68, 0x65, 0x72, 0x12, 0x21, 0x0a, 0x0c, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, - 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x70, 0x75, 0x62, - 0x6c, 0x69, 0x73, 0x68, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x6c, 0x69, 0x65, - 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x08, 0x63, 0x6c, 0x69, - 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x70, 0x5f, 0x61, 0x64, 0x64, 0x72, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x69, 0x70, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1d, - 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x09, 0x75, 0x73, 0x65, 0x72, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, -} - -var ( - file_object_v1_object_proto_rawDescOnce sync.Once - file_object_v1_object_proto_rawDescData = file_object_v1_object_proto_rawDesc -) - -func file_object_v1_object_proto_rawDescGZIP() []byte { - file_object_v1_object_proto_rawDescOnce.Do(func() { - file_object_v1_object_proto_rawDescData = protoimpl.X.CompressGZIP(file_object_v1_object_proto_rawDescData) - }) - return file_object_v1_object_proto_rawDescData -} - -var file_object_v1_object_proto_enumTypes = make([]protoimpl.EnumInfo, 2) -var file_object_v1_object_proto_msgTypes = make([]protoimpl.MessageInfo, 7) -var file_object_v1_object_proto_goTypes = []any{ - (Encryption_Algorithm)(0), // 0: object.v1.Encryption.Algorithm - (Compression_Algorithm)(0), // 1: object.v1.Compression.Algorithm - (*Object)(nil), // 2: object.v1.Object - (*Version)(nil), // 3: object.v1.Version - (*SchemaVersion)(nil), // 4: object.v1.SchemaVersion - (*ACL)(nil), // 5: object.v1.ACL - (*Encryption)(nil), // 6: object.v1.Encryption - (*Compression)(nil), // 7: object.v1.Compression - (*Publisher)(nil), // 8: object.v1.Publisher - (*timestamppb.Timestamp)(nil), // 9: google.protobuf.Timestamp -} -var file_object_v1_object_proto_depIdxs = []int32{ - 3, // 0: object.v1.Object.version:type_name -> object.v1.Version - 4, // 1: object.v1.Object.schema:type_name -> object.v1.SchemaVersion - 5, // 2: object.v1.Object.acl:type_name -> object.v1.ACL - 8, // 3: object.v1.Object.publisher:type_name -> object.v1.Publisher - 6, // 4: object.v1.Object.encryption:type_name -> object.v1.Encryption - 7, // 5: object.v1.Object.compression:type_name -> object.v1.Compression - 9, // 6: object.v1.Object.created:type_name -> google.protobuf.Timestamp - 9, // 7: object.v1.Object.modified:type_name -> google.protobuf.Timestamp - 3, // 8: object.v1.Version.parent:type_name -> object.v1.Version - 9, // 9: object.v1.Version.created:type_name -> google.protobuf.Timestamp - 0, // 10: object.v1.Encryption.sealing_algorithm:type_name -> object.v1.Encryption.Algorithm - 0, // 11: object.v1.Encryption.encryption_algorithm:type_name -> object.v1.Encryption.Algorithm - 0, // 12: object.v1.Encryption.signature_algorithm:type_name -> object.v1.Encryption.Algorithm - 1, // 13: object.v1.Compression.algorithm:type_name -> object.v1.Compression.Algorithm - 14, // [14:14] is the sub-list for method output_type - 14, // [14:14] is the sub-list for method input_type - 14, // [14:14] is the sub-list for extension type_name - 14, // [14:14] is the sub-list for extension extendee - 0, // [0:14] is the sub-list for field type_name -} - -func init() { file_object_v1_object_proto_init() } -func file_object_v1_object_proto_init() { - if File_object_v1_object_proto != nil { - return - } - - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_object_v1_object_proto_rawDesc, - NumEnums: 2, - NumMessages: 7, - NumExtensions: 0, - NumServices: 0, - }, - GoTypes: file_object_v1_object_proto_goTypes, - DependencyIndexes: file_object_v1_object_proto_depIdxs, - EnumInfos: file_object_v1_object_proto_enumTypes, - MessageInfos: file_object_v1_object_proto_msgTypes, - }.Build() - File_object_v1_object_proto = out.File - file_object_v1_object_proto_rawDesc = nil - file_object_v1_object_proto_goTypes = nil - file_object_v1_object_proto_depIdxs = nil -} diff --git a/pkg/store/decode.go b/pkg/store/decode.go index 2f3fe90..5f44b3b 100644 --- a/pkg/store/decode.go +++ b/pkg/store/decode.go @@ -237,6 +237,12 @@ func (d *Decoder) DecodeTime() (_ time.Time, err error) { if ts, err = d.DecodeInt64(); err != nil { return time.Time{}, err } + + // Handle zero-valued time + if ts == 0 { + return time.Time{}, nil + } + return time.Unix(0, ts), nil } diff --git a/pkg/store/decode_test.go b/pkg/store/decode_test.go new file mode 100644 index 0000000..92aa3bb --- /dev/null +++ b/pkg/store/decode_test.go @@ -0,0 +1,370 @@ +package store_test + +import ( + "crypto/rand" + "errors" + "io" + "math" + "testing" + "time" + + "github.com/oklog/ulid" + . "github.com/rotationalio/honu/pkg/store" + "github.com/stretchr/testify/require" +) + +func TestUnmarshal(t *testing.T) { + mock := &Mock{[]byte("hello world"), nil} + data, err := Marshal(mock) + require.NoError(t, err, "could not marshall mock encodable") + + t.Run("Happy", func(t *testing.T) { + cmp := &Mock{} + err := Unmarshal(data, cmp) + require.NoError(t, err, "could not unmarshall mock encodable") + require.Equal(t, mock.Data, cmp.Data) + }) + + t.Run("Error", func(t *testing.T) { + cmp := &Mock{nil, errors.New("whoopsie")} + err := Unmarshal(data, cmp) + require.EqualError(t, err, "whoopsie") + require.Nil(t, cmp.Data) + }) +} + +func TestDecoder(t *testing.T) { + // Decoder tests essentially just ensure that the decoder can correctly deserialize + // the output of an encoder for the specified type. There are a couple of + // specialized tests and error checking here and there, but the tests attempt to + // keep things as simple as possible for future maintainability. + enc := &Encoder{} + + t.Run("Decode", func(t *testing.T) { + t.Run("Nil", func(t *testing.T) { + dec := NewDecoder(nil) + out, err := dec.Decode() + require.ErrorIs(t, err, io.EOF, "expected EOF when decoding nil") + require.Nil(t, out) + }) + + t.Run("InvalidLength", func(t *testing.T) { + dec := NewDecoder([]byte{0xff, 0xff}) + out, err := dec.Decode() + require.ErrorIs(t, err, ErrNoLength, "expected incorrect length error") + require.Nil(t, out) + }) + + t.Run("UnexpectedEOF", func(t *testing.T) { + dec := NewDecoder([]byte{0xff, 0x12, 0x23, 0x42, 0xf2, 0x21}) + out, err := dec.Decode() + require.ErrorIs(t, err, io.ErrUnexpectedEOF, "expected EOF before read complete") + require.Nil(t, out) + }) + + t.Run("NoData", func(t *testing.T) { + dec := NewDecoder([]byte{0x00}) + out, err := dec.Decode() + require.NoError(t, err, "expected no error for a nil bytes frame") + require.Nil(t, out) + }) + + t.Run("Bytes", func(t *testing.T) { + tests := []struct { + in []byte + err error + }{ + {nil, nil}, + {[]byte{0x42}, nil}, + {[]byte("hello world"), nil}, + } + + for i, tc := range tests { + _, err := enc.Encode(tc.in) + require.NoError(t, err, "could not encode input in test case %d", i) + + out, err := NewDecoder(enc.Bytes()).Decode() + CompareOrErr(t, i, tc.in, out, err, tc.err) + } + + }) + }) + + t.Run("String", func(t *testing.T) { + tests := []struct { + in string + err error + }{ + {"", nil}, + {"hello world", nil}, + } + + for i, tc := range tests { + _, err := enc.EncodeString(tc.in) + require.NoError(t, err, "could not encode input in test case %d", i) + + out, err := NewDecoder(enc.Bytes()).DecodeString() + CompareOrErr(t, i, tc.in, out, err, tc.err) + } + + }) + + t.Run("StringSlice", func(t *testing.T) { + tests := []struct { + in []string + err error + }{ + {nil, nil}, + {[]string{""}, nil}, + {[]string{"hello world"}, nil}, + {[]string{"", "", "", "", "", ""}, nil}, + {[]string{"", "hello", "", "", "world", ""}, nil}, + {[]string{"apples", "oranges", "pineapples", "pumpkins"}, nil}, + } + + for i, tc := range tests { + _, err := enc.EncodeStringSlice(tc.in) + require.NoError(t, err, "could not encode input in test case %d", i) + + out, err := NewDecoder(enc.Bytes()).DecodeStringSlice() + CompareOrErr(t, i, tc.in, out, err, tc.err) + } + + }) + + t.Run("Byte", func(t *testing.T) { + tests := []struct { + in byte + err error + }{ + {0x0, nil}, + {0xff, nil}, + {0x12, nil}, + {0xf0, nil}, + } + + for i, tc := range tests { + _, err := enc.EncodeByte(tc.in) + require.NoError(t, err, "could not encode input in test case %d", i) + + out, err := NewDecoder(enc.Bytes()).DecodeByte() + CompareOrErr(t, i, tc.in, out, err, tc.err) + } + + }) + + t.Run("Bool", func(t *testing.T) { + tests := []struct { + in bool + err error + }{ + {false, nil}, + {true, nil}, + } + + for i, tc := range tests { + _, err := enc.EncodeBool(tc.in) + require.NoError(t, err, "could not encode input in test case %d", i) + + out, err := NewDecoder(enc.Bytes()).DecodeBool() + CompareOrErr(t, i, tc.in, out, err, tc.err) + } + + }) + + t.Run("BadBool", func(t *testing.T) { + _, err := enc.EncodeByte(0xf2) + require.NoError(t, err, "could not encode input") + + out, err := NewDecoder(enc.Bytes()).DecodeBool() + require.ErrorIs(t, err, ErrParseBoolean) + require.False(t, out) + }) + + t.Run("Uint8", func(t *testing.T) { + tests := []struct { + in uint8 + err error + }{ + {0x0, nil}, + {0xff, nil}, + {0x12, nil}, + {0xf0, nil}, + } + + for i, tc := range tests { + _, err := enc.EncodeUint8(tc.in) + require.NoError(t, err, "could not encode input in test case %d", i) + + out, err := NewDecoder(enc.Bytes()).DecodeUint8() + CompareOrErr(t, i, tc.in, out, err, tc.err) + } + + }) + + t.Run("Uint32", func(t *testing.T) { + tests := []struct { + in uint32 + err error + }{ + {0x0, nil}, + {0xff, nil}, + {0xffff, nil}, + {0xffffff, nil}, + {0xffffffff, nil}, + {math.MaxUint32, nil}, + } + + for i, tc := range tests { + _, err := enc.EncodeUint32(tc.in) + require.NoError(t, err, "could not encode input in test case %d", i) + + out, err := NewDecoder(enc.Bytes()).DecodeUint32() + CompareOrErr(t, i, tc.in, out, err, tc.err) + } + + }) + + t.Run("Uint64", func(t *testing.T) { + tests := []struct { + in uint64 + err error + }{ + {0x0, nil}, + {0xff, nil}, + {0xffff, nil}, + {0xffffff, nil}, + {0xffffffff, nil}, + {0xffffffffff, nil}, + {0xffffffffffff, nil}, + {0xffffffffffffff, nil}, + {0xffffffffffffffff, nil}, + {math.MaxUint64, nil}, + } + + for i, tc := range tests { + _, err := enc.EncodeUint64(tc.in) + require.NoError(t, err, "could not encode input in test case %d", i) + + out, err := NewDecoder(enc.Bytes()).DecodeUint64() + CompareOrErr(t, i, tc.in, out, err, tc.err) + } + + }) + + t.Run("Int64", func(t *testing.T) { + tests := []struct { + in int64 + err error + }{ + {0x0, nil}, + {0xff, nil}, + {0xffff, nil}, + {0xffffff, nil}, + {0xffffffff, nil}, + {0xffffffffff, nil}, + {0xffffffffffff, nil}, + {0xffffffffffffff, nil}, + {-0xff, nil}, + {-0xffff, nil}, + {-0xffffff, nil}, + {-0xffffffff, nil}, + {-0xffffffffff, nil}, + {-0xffffffffffff, nil}, + {-0xffffffffffffff, nil}, + {math.MaxInt64, nil}, + } + + for i, tc := range tests { + _, err := enc.EncodeInt64(tc.in) + require.NoError(t, err, "could not encode input in test case %d", i) + + out, err := NewDecoder(enc.Bytes()).DecodeInt64() + CompareOrErr(t, i, tc.in, out, err, tc.err) + } + + }) + + t.Run("Fixed", func(t *testing.T) { + tests := []struct { + in []byte + err error + }{ + {nil, io.EOF}, + {[]byte{0x42}, nil}, + {[]byte("hello world"), nil}, + } + + for i, tc := range tests { + _, err := enc.EncodeFixed(tc.in) + require.NoError(t, err, "could not encode input in test case %d", i) + + out, err := NewDecoder(enc.Bytes()).DecodeFixed(len(tc.in)) + CompareOrErr(t, i, tc.in, out, err, tc.err) + } + + }) + + t.Run("ULID", func(t *testing.T) { + tests := []struct { + in ulid.ULID + err error + }{ + {ulid.ULID{}, nil}, + {ulid.MustParse("01JB24RGJ9FH1X04F9S5A26QAT"), nil}, + {ulid.MustNew(ulid.Now(), rand.Reader), nil}, + } + + for i, tc := range tests { + _, err := enc.EncodeULID(tc.in) + require.NoError(t, err, "could not encode input in test case %d", i) + + out, err := NewDecoder(enc.Bytes()).DecodeULID() + CompareOrErr(t, i, tc.in, out, err, tc.err) + } + + }) + + t.Run("Time", func(t *testing.T) { + tests := []time.Time{ + {}, + time.Date(2024, 04, 07, 12, 32, 41, 821, time.UTC), + time.Now(), + } + + for i, tc := range tests { + _, err := enc.EncodeTime(tc) + require.NoError(t, err, "could not encode input in test case %d", i) + + out, err := NewDecoder(enc.Bytes()).DecodeTime() + require.NoError(t, err, "could not decode timestamp") + require.True(t, tc.Equal(out), "timestamps are not equal in testcase %d", i) + } + }) + + t.Run("Struct", func(t *testing.T) { + t.Run("Nil", func(t *testing.T) { + var obj *Compression + + _, err := enc.EncodeStruct(obj) + require.NoError(t, err, "could not encode nil struct input") + + var cmp *Compression + isNil, err := NewDecoder(enc.Bytes()).DecodeStruct(cmp) + require.NoError(t, err, "could not decode nil struct") + require.True(t, isNil, "expected isNil to be true") + }) + + }) + +} + +func CompareOrErr(t *testing.T, i int, in, out any, err, target error) { + if target == nil { + require.NoError(t, err, "could not decode input in test case %d", i) + require.Equal(t, in, out, "original input did not match decoded output in test case %d", i) + } else { + require.ErrorIs(t, err, target, "expected error on test case %d", i) + require.Nil(t, out, "expected nil on an expected decode error for test case %d", i) + } +} diff --git a/pkg/store/encode.go b/pkg/store/encode.go index 60d7a5e..13a7ede 100644 --- a/pkg/store/encode.go +++ b/pkg/store/encode.go @@ -215,6 +215,9 @@ func (e *Encoder) EncodeULID(u ulid.ULID) (int, error) { // Encode a timestamp as a unix epoch int64 with nanoseconds resolution. // Shortcut for EncodeInt64(t.UnixNano()) func (e *Encoder) EncodeTime(t time.Time) (int, error) { + if t.IsZero() { + return e.EncodeInt64(0) + } return e.EncodeInt64(t.UnixNano()) } @@ -311,6 +314,7 @@ func (e *Encoder) grow(n int) int { c := cap(e.buf) if n <= c/2-m { // Try to slide data down instead of allocating a new slice + // TODO: is this case ever possible to reach? It is untested right now. copy(e.buf, e.buf[e.off:]) } else if c > maxInt-c-n { // If we can't grow the slice then we need to panic diff --git a/pkg/store/encode_test.go b/pkg/store/encode_test.go index a23e06c..a9ee970 100644 --- a/pkg/store/encode_test.go +++ b/pkg/store/encode_test.go @@ -1,12 +1,31 @@ package store_test import ( + "crypto/rand" + "encoding/binary" + "errors" "testing" + "time" + "github.com/oklog/ulid" . "github.com/rotationalio/honu/pkg/store" "github.com/stretchr/testify/require" ) +func TestMarshal(t *testing.T) { + mock := &Mock{[]byte("hello world"), nil} + data, err := Marshal(mock) + require.NoError(t, err, "could not marshall mock encodable") + require.GreaterOrEqual(t, mock.Size(), len(data), "data was not the expected size") +} + +func TestMarshalError(t *testing.T) { + mock := &Mock{nil, errors.New("whoopsie")} + data, err := Marshal(mock) + require.EqualError(t, err, "whoopsie") + require.Nil(t, data) +} + func TestEncoder(t *testing.T) { t.Run("Empty", func(t *testing.T) { enc := &Encoder{} @@ -177,6 +196,21 @@ func TestEncoder(t *testing.T) { require.LessOrEqual(t, enc.Cap(), 64, "capacity larger than expected") }) + t.Run("StringVsBytes", func(t *testing.T) { + e := &Encoder{} + s := "the brown bear jumps through the woods" + + _, err := e.EncodeString(s) + require.NoError(t, err, "could not encode string") + s1 := e.Bytes() + + _, err = e.Encode([]byte(s)) + require.NoError(t, err, "could not encode bytes") + s2 := e.Bytes() + + require.Equal(t, s1, s2, "encoding string and bytes did not match") + }) + t.Run("EncodeStringSlice", func(t *testing.T) { tests := []struct { n int @@ -199,4 +233,175 @@ func TestEncoder(t *testing.T) { } }) + t.Run("OneByteData", func(t *testing.T) { + // Use only one encoder that should only have one byte in it + e := &Encoder{} + + t.Run("Byte", func(t *testing.T) { + n, err := e.EncodeByte(0x42) + require.NoError(t, err, "could not encode byte") + require.Equal(t, 1, n, "expected only one byte written") + require.Equal(t, []byte{0x42}, e.Bytes()) + }) + + t.Run("Uint8", func(t *testing.T) { + n, err := e.EncodeUint8(42) + require.NoError(t, err, "could not encode uint8") + require.Equal(t, 1, n, "expected only one byte written") + require.Equal(t, []byte{0x2a}, e.Bytes()) + }) + + t.Run("True", func(t *testing.T) { + n, err := e.EncodeBool(true) + require.NoError(t, err, "could not encode true") + require.Equal(t, 1, n, "expected only one byte written") + require.Equal(t, []byte{0x01}, e.Bytes()) + }) + + t.Run("False", func(t *testing.T) { + n, err := e.EncodeBool(false) + require.NoError(t, err, "could not encode false") + require.Equal(t, 1, n, "expected only one byte written") + require.Equal(t, []byte{0x00}, e.Bytes()) + }) + + }) + + t.Run("Integers", func(t *testing.T) { + t.Run("Uint32", func(t *testing.T) { + tests := []struct { + i uint32 + size int + }{ + {127, 1}, + {16383, 2}, + {2097151, 3}, + {268435455, 4}, + {4294967295, 5}, + } + + enc := &Encoder{} + for i, tc := range tests { + n, err := enc.EncodeUint32(tc.i) + require.NoError(t, err, "could not encode uint32 in test case %d", i) + require.Equal(t, tc.size, n, "wrong number of bytes written in test case %d", i) + require.Equal(t, n, enc.Len(), "unexpected length of byte array in test case %d", i) + + // Clear the encoder + enc.Reset() + } + }) + + t.Run("Uint64", func(t *testing.T) { + tests := []struct { + i uint64 + size int + }{ + {127, 1}, + {16383, 2}, + {2097151, 3}, + {268435455, 4}, + {34359738367, 5}, + {4398046511103, 6}, + {562949953421311, 7}, + {72057594037927928, 8}, + {9223372036854775807, 9}, + {18446744073709551615, 10}, + } + + enc := &Encoder{} + for i, tc := range tests { + n, err := enc.EncodeUint64(tc.i) + require.NoError(t, err, "could not encode uint64 in test case %d", i) + require.Equal(t, tc.size, n, "wrong number of bytes written in test case %d", i) + require.Equal(t, n, enc.Len(), "unexpected length of byte array in test case %d", i) + + // Clear the encoder + enc.Reset() + } + }) + + t.Run("Int64", func(t *testing.T) { + tests := []struct { + i int64 + size int + }{ + {-9223372036854775807, 10}, + {-72057594037927928, 9}, + {-562949953421311, 8}, + {-4398046511103, 7}, + {-34359738367, 6}, + {-268435455, 5}, + {-2097151, 4}, + {-16383, 3}, + {-127, 2}, + {-32, 1}, + {0, 1}, + {32, 1}, + {127, 2}, + {16383, 3}, + {2097151, 4}, + {268435455, 5}, + {34359738367, 6}, + {4398046511103, 7}, + {562949953421311, 8}, + {72057594037927928, 9}, + {9223372036854775807, 10}, + } + + enc := &Encoder{} + for i, tc := range tests { + n, err := enc.EncodeInt64(tc.i) + require.NoError(t, err, "could not encode int64 in test case %d", i) + require.Equal(t, tc.size, n, "wrong number of bytes written in test case %d", i) + require.Equal(t, n, enc.Len(), "unexpected length of byte array in test case %d", i) + + // Clear the encoder + enc.Reset() + } + }) + }) + + t.Run("Fixed", func(t *testing.T) { + enc := &Encoder{} + data := []byte{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf} + n, err := enc.EncodeFixed(data) + require.NoError(t, err, "could not encode fixed") + require.Equal(t, len(data), n, "expected only the data to be written") + }) + + t.Run("ULID", func(t *testing.T) { + enc := &Encoder{} + data := ulid.MustNew(ulid.Now(), rand.Reader) + n, err := enc.EncodeULID(data) + require.NoError(t, err, "could not encode ulid") + require.Equal(t, len(data), n, "expected only the data to be written") + }) + + t.Run("Time", func(t *testing.T) { + enc := &Encoder{} + data := time.Now() + n, err := enc.EncodeTime(data) + require.NoError(t, err, "could not encode timestamp") + require.LessOrEqual(t, n, binary.MaxVarintLen64, "unexpected number of bytes written") + }) + + t.Run("ZeroTime", func(t *testing.T) { + enc := &Encoder{} + n, err := enc.EncodeTime(time.Time{}) + require.NoError(t, err, "could not encode timestamp") + require.Equal(t, n, 1, "unexpected number of bytes written") + require.Equal(t, []byte{0x00}, enc.Bytes(), "zero valud time not written as zero") + }) + + t.Run("Struct", func(t *testing.T) { + t.Run("Nil", func(t *testing.T) { + var obj *Compression + enc := &Encoder{} + n, err := enc.EncodeStruct(obj) + require.NoError(t, err, "could not encode nil struct") + require.Equal(t, 1, n, "expected 1 byte encoded for nil structs") + }) + }) + } diff --git a/pkg/store/mock.go b/pkg/store/mock.go new file mode 100644 index 0000000..1193bef --- /dev/null +++ b/pkg/store/mock.go @@ -0,0 +1,32 @@ +package store + +import "encoding/binary" + +// Used for testing this package, should not be used in external tests. +type Mock struct { + Data []byte + Err error +} + +func (t *Mock) Size() int { + return len(t.Data) + binary.MaxVarintLen64 +} + +func (t *Mock) Encode(e *Encoder) (int, error) { + if t.Err != nil { + return 0, t.Err + } + return e.Encode(t.Data) +} + +func (t *Mock) Decode(d *Decoder) (err error) { + if t.Err != nil { + return t.Err + } + + if t.Data, err = d.Decode(); err != nil { + return err + } + + return nil +} diff --git a/pkg/store/object_test.go b/pkg/store/object_test.go index d64a1fa..562c552 100644 --- a/pkg/store/object_test.go +++ b/pkg/store/object_test.go @@ -9,11 +9,8 @@ import ( "time" "github.com/oklog/ulid" - "github.com/rotationalio/honu/pkg/object/v1" "github.com/rotationalio/honu/pkg/store" "github.com/stretchr/testify/require" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/types/known/timestamppb" ) func TestObjectSerialization(t *testing.T) { @@ -28,6 +25,19 @@ func TestObjectSerialization(t *testing.T) { require.Equal(t, obj, cmp, "deserialized object does not match original") } +//=========================================================================== +// Benchmarks +//=========================================================================== + +type Size uint8 + +const ( + Small Size = iota + Medium + Large + XLarge +) + func BenchmarkSerialization(b *testing.B) { makeHonuEncode := func(objs []*store.Object) func(b *testing.B) { @@ -68,43 +78,6 @@ func BenchmarkSerialization(b *testing.B) { } } - makeProtobufEncode := func(opbs []*object.Object) func(b *testing.B) { - return func(b *testing.B) { - b.StopTimer() - for n := 0; n < b.N; n++ { - obj := opbs[n%len(opbs)] - - b.StartTimer() - data, err := proto.Marshal(obj) - b.StopTimer() - - if err != nil { - b.FailNow() - } - - b.ReportMetric(float64(len(data)), "bytes") - } - } - } - - makeProtobufDecode := func(pbs [][]byte) func(b *testing.B) { - return func(b *testing.B) { - b.StopTimer() - for n := 0; n < b.N; n++ { - data := pbs[n%len(pbs)] - obj := &object.Object{} - - b.StartTimer() - err := proto.Unmarshal(data, obj) - b.StopTimer() - - if err != nil { - b.FailNow() - } - } - } - } - makeSizeBenchmark := func(size Size) func(b *testing.B) { return func(b *testing.B) { // Generate objects for testing @@ -113,15 +86,7 @@ func BenchmarkSerialization(b *testing.B) { objs[i] = generateRandomObject(size) } - opbs := make([]*object.Object, len(objs)) - for i, obj := range objs { - opbs[i] = convertObject(obj) - } - - b.Run("Encode", func(b *testing.B) { - b.Run("Honu", makeHonuEncode(objs)) - b.Run("Protobuf", makeProtobufEncode(opbs)) - }) + b.Run("Encode", makeHonuEncode(objs)) hnd := make([][]byte, len(objs)) for i, obj := range objs { @@ -132,19 +97,7 @@ func BenchmarkSerialization(b *testing.B) { hnd[i] = data } - pbs := make([][]byte, len(opbs)) - for i, obj := range opbs { - var err error - pbs[i], err = proto.Marshal(obj) - if err != nil { - b.FailNow() - } - } - - b.Run("Decode", func(b *testing.B) { - b.Run("Honu", makeHonuDecode(hnd)) - b.Run("Protobuf", makeProtobufDecode(pbs)) - }) + b.Run("Decode", makeHonuDecode(hnd)) } } @@ -154,124 +107,9 @@ func BenchmarkSerialization(b *testing.B) { b.Run("XLarge", makeSizeBenchmark(XLarge)) } -func convertObject(o *store.Object) *object.Object { - p := &object.Object{ - Version: convertVersion(o.Version), - Schema: convertSchemaVersion(o.Schema), - Mimetype: o.MIME, - Owner: o.Owner[:], - Group: o.Group[:], - Permissions: []byte{o.Permissions}, - Acl: convertACL(o.ACL), - WriteRegions: o.WriteRegions, - Publisher: convertPublisher(o.Publisher), - Encryption: convertEncryption(o.Encryption), - Compression: convertCompression(o.Compression), - Flags: []byte{o.Flags}, - Created: timestamppb.New(o.Created), - Modified: timestamppb.New(o.Modified), - Data: o.Data, - } - - return p -} - -func convertVersion(v *store.Version) *object.Version { - if v == nil { - return nil - } - - vers := &object.Version{ - Pid: v.PID, - Version: v.Version, - Region: v.Region, - Tombstone: v.Tombstone, - Created: timestamppb.New(v.Created), - } - - if v.Parent != nil { - vers.Parent = convertVersion(v.Parent) - } - - return vers -} - -func convertSchemaVersion(o *store.SchemaVersion) *object.SchemaVersion { - if o == nil { - return nil - } - - return &object.SchemaVersion{ - Name: o.Name, - MajorVersion: o.Major, - MinorVersion: o.Minor, - PatchVersion: o.Patch, - } -} - -func convertACL(a []*store.AccessControl) []*object.ACL { - if len(a) == 0 { - return nil - } - - acl := make([]*object.ACL, len(a)) - for i, c := range a { - acl[i] = &object.ACL{ - ClientId: c.ClientID[:], - Permissions: []byte{c.Permissions}, - } - } - - return acl -} - -func convertPublisher(o *store.Publisher) *object.Publisher { - if o == nil { - return nil - } - - return &object.Publisher{ - PublisherId: o.PublisherID[:], - ClientId: o.ClientID[:], - IpAddr: o.IPAddress.String(), - UserAgent: o.UserAgent, - } -} - -func convertEncryption(o *store.Encryption) *object.Encryption { - if o == nil { - return nil - } - - var encmap = map[store.EncryptionAlgorithm]object.Encryption_Algorithm{ - store.Plaintext: object.Encryption_PLAINTEXT, - store.AES256_GCM: object.Encryption_AES256_GCM, - store.AES192_GCM: object.Encryption_AES192_GCM, - store.AES128_GCM: object.Encryption_AES128_GCM, - store.HMAC_SHA256: object.Encryption_HMAC_SHA256, - store.RSA_OEAP_SHA512: object.Encryption_RSA_OAEP_SHA512, - } - - return &object.Encryption{ - PublicKeyId: o.PublicKeyID, - EncryptionKey: o.EncryptionKey, - HmacSecret: o.HMACSecret, - Signature: o.Signature, - SealingAlgorithm: encmap[o.SealingAlgorithm], - EncryptionAlgorithm: encmap[o.EncryptionAlgorithm], - SignatureAlgorithm: encmap[o.SignatureAlgorithm], - } -} - -func convertCompression(o *store.Compression) *object.Compression { - if o == nil { - return nil - } - return &object.Compression{ - Algorithm: object.Compression_Algorithm(int32(o.Algorithm)), - Level: o.Level, - } -} +//=========================================================================== +// Generate Random Objects +//=========================================================================== func generateRandomObject(size Size) *store.Object { obj := &store.Object{ @@ -510,12 +348,3 @@ func nRandomBytes(size Size) int64 { panic("unknown size") } } - -type Size uint8 - -const ( - Small Size = iota - Medium - Large - XLarge -) diff --git a/proto/object/v1/object.proto b/proto/object/v1/object.proto deleted file mode 100644 index 3818c2a..0000000 --- a/proto/object/v1/object.proto +++ /dev/null @@ -1,112 +0,0 @@ -syntax = "proto3"; - -package object.v1; - -import "google/protobuf/timestamp.proto"; - -message Object { - Version version = 1; - SchemaVersion schema = 2; - string mimetype = 3; - - // Access Controls - bytes owner = 4; - bytes group = 5; - bytes permissions = 6; - repeated ACL acl = 7; - - // Provenance Information - repeated string WriteRegions = 8; - Publisher publisher = 9; - - // Read Information - Encryption encryption = 10; - Compression compression = 11; - - // Flags - bytes flags = 12; - - // Modification Timestamps - google.protobuf.Timestamp created = 13; - google.protobuf.Timestamp modified = 14; - - // The actual data of the object - bytes data = 15; -} - -// Implements a geo-distributed version as a Lamport Scalar -message Version { - uint64 pid = 1; // Process ID - used to deconflict ties in the version number. - uint64 version = 2; // Montonically increasing version number. - string region = 3; // The region where the change occurred to track multi-region handling. - Version parent = 4; // In order to get a complete version history, identify the predessor; for compact data transfer parent should not be defined in parent version. - bool tombstone = 5; // Set to true in order to mark the object as deleted - - // The timestamp that the version was created (e.g. the last modified date). - google.protobuf.Timestamp created = 15; -} - -// An event type is composed of a name and a version so that the type can be looked up -// in the schema registry. The schema can then be used to validate the data inside the -// event. Schemas are optional but types are not unless the mimetype requries a schema -// for deserialization (e.g. protobuf, parquet, avro, etc.). -message SchemaVersion { - string name = 1; - uint32 major_version = 2; - uint32 minor_version = 3; - uint32 patch_version = 4; -} - -message ACL { - bytes client_id = 1; - bytes permissions = 2; -} - -// Metadata about the cryptography used to secure the event. -message Encryption { - enum Algorithm { - // No cryptography is being used - PLAINTEXT = 0; - - // Encryption Algorithms - AES256_GCM = 110; - AES192_GCM = 120; - AES128_GCM = 130; - - // Signature Algorithms - HMAC_SHA256 = 310; - - // Sealing Algorithms (Asymmetric) - RSA_OAEP_SHA512 = 510; - } - - string public_key_id = 1; - bytes encryption_key = 2; - bytes hmac_secret = 3; - bytes signature = 4; - Algorithm sealing_algorithm = 5; - Algorithm encryption_algorithm = 6; - Algorithm signature_algorithm = 7; -} - -// Metadata about compression used to reduce the storage size of the event. -message Compression { - enum Algorithm { - NONE = 0; - GZIP = 1; - COMPRESS = 2; - DEFLATE = 3; - BROTLI = 4; - } - - Algorithm algorithm = 1; - int64 level = 2; -} - -// Information about the publisher of the event for provenance and auditing purposes. -message Publisher { - bytes publisher_id = 1; - bytes client_id = 2; - string ip_addr = 3; - string user_agent = 4; -} \ No newline at end of file