fix(ORM): support for imported messages in iterators (#11372)

## Description

- adds support for imported messages in iterators

Closes: n/a



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
This commit is contained in:
Tyler 2022-03-14 14:56:18 -07:00 committed by GitHub
parent 18a816284a
commit 0a3298f4f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 878 additions and 52 deletions

View File

@ -36,7 +36,15 @@ func ValuesOf(values ...interface{}) []protoreflect.Value {
n := len(values)
res := make([]protoreflect.Value, n)
for i := 0; i < n; i++ {
res[i] = protoreflect.ValueOf(values[i])
// we catch the case of proto messages here and call ProtoReflect.
// this allows us to use imported messages, such as timestamppb.Timestamp
// in iterators.
value := values[i]
switch value.(type) {
case protoreflect.ProtoMessage:
value = value.(protoreflect.ProtoMessage).ProtoReflect()
}
res[i] = protoreflect.ValueOf(value)
}
return res
}

View File

@ -4,7 +4,6 @@ package testpb
import (
context "context"
ormlist "github.com/cosmos/cosmos-sdk/orm/model/ormlist"
ormtable "github.com/cosmos/cosmos-sdk/orm/model/ormtable"
ormerrors "github.com/cosmos/cosmos-sdk/orm/types/ormerrors"

View File

@ -3,16 +3,14 @@ package testpb
import (
fmt "fmt"
io "io"
reflect "reflect"
sync "sync"
runtime "github.com/cosmos/cosmos-proto/runtime"
_ "github.com/cosmos/cosmos-sdk/api/cosmos/orm/v1alpha1"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
_ "github.com/cosmos/cosmos-sdk/api/cosmos/orm/v1alpha1"
io "io"
reflect "reflect"
sync "sync"
)
var (
@ -1018,7 +1016,7 @@ func (x *fastReflection_Supply) ProtoMethods() *protoiface.Methods {
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.0
// protoc (unknown)
// protoc v3.19.1
// source: testpb/bank.proto
const (

View File

@ -4,10 +4,10 @@ package testpb
import (
context "context"
ormlist "github.com/cosmos/cosmos-sdk/orm/model/ormlist"
ormtable "github.com/cosmos/cosmos-sdk/orm/model/ormtable"
ormerrors "github.com/cosmos/cosmos-sdk/orm/types/ormerrors"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)
type ExampleTableTable interface {
@ -398,10 +398,143 @@ func NewExampleSingletonTable(db ormtable.Schema) (ExampleSingletonTable, error)
return &exampleSingletonTable{table}, nil
}
type ExampleTimestampTable interface {
Insert(ctx context.Context, exampleTimestamp *ExampleTimestamp) error
InsertReturningID(ctx context.Context, exampleTimestamp *ExampleTimestamp) (uint64, error)
Update(ctx context.Context, exampleTimestamp *ExampleTimestamp) error
Save(ctx context.Context, exampleTimestamp *ExampleTimestamp) error
Delete(ctx context.Context, exampleTimestamp *ExampleTimestamp) error
Has(ctx context.Context, id uint64) (found bool, err error)
// Get returns nil and an error which responds true to ormerrors.IsNotFound() if the record was not found.
Get(ctx context.Context, id uint64) (*ExampleTimestamp, error)
List(ctx context.Context, prefixKey ExampleTimestampIndexKey, opts ...ormlist.Option) (ExampleTimestampIterator, error)
ListRange(ctx context.Context, from, to ExampleTimestampIndexKey, opts ...ormlist.Option) (ExampleTimestampIterator, error)
DeleteBy(ctx context.Context, prefixKey ExampleTimestampIndexKey) error
DeleteRange(ctx context.Context, from, to ExampleTimestampIndexKey) error
doNotImplement()
}
type ExampleTimestampIterator struct {
ormtable.Iterator
}
func (i ExampleTimestampIterator) Value() (*ExampleTimestamp, error) {
var exampleTimestamp ExampleTimestamp
err := i.UnmarshalMessage(&exampleTimestamp)
return &exampleTimestamp, err
}
type ExampleTimestampIndexKey interface {
id() uint32
values() []interface{}
exampleTimestampIndexKey()
}
// primary key starting index..
type ExampleTimestampPrimaryKey = ExampleTimestampIdIndexKey
type ExampleTimestampIdIndexKey struct {
vs []interface{}
}
func (x ExampleTimestampIdIndexKey) id() uint32 { return 0 }
func (x ExampleTimestampIdIndexKey) values() []interface{} { return x.vs }
func (x ExampleTimestampIdIndexKey) exampleTimestampIndexKey() {}
func (this ExampleTimestampIdIndexKey) WithId(id uint64) ExampleTimestampIdIndexKey {
this.vs = []interface{}{id}
return this
}
type ExampleTimestampTsIndexKey struct {
vs []interface{}
}
func (x ExampleTimestampTsIndexKey) id() uint32 { return 1 }
func (x ExampleTimestampTsIndexKey) values() []interface{} { return x.vs }
func (x ExampleTimestampTsIndexKey) exampleTimestampIndexKey() {}
func (this ExampleTimestampTsIndexKey) WithTs(ts *timestamppb.Timestamp) ExampleTimestampTsIndexKey {
this.vs = []interface{}{ts}
return this
}
type exampleTimestampTable struct {
table ormtable.AutoIncrementTable
}
func (this exampleTimestampTable) Insert(ctx context.Context, exampleTimestamp *ExampleTimestamp) error {
return this.table.Insert(ctx, exampleTimestamp)
}
func (this exampleTimestampTable) Update(ctx context.Context, exampleTimestamp *ExampleTimestamp) error {
return this.table.Update(ctx, exampleTimestamp)
}
func (this exampleTimestampTable) Save(ctx context.Context, exampleTimestamp *ExampleTimestamp) error {
return this.table.Save(ctx, exampleTimestamp)
}
func (this exampleTimestampTable) Delete(ctx context.Context, exampleTimestamp *ExampleTimestamp) error {
return this.table.Delete(ctx, exampleTimestamp)
}
func (this exampleTimestampTable) InsertReturningID(ctx context.Context, exampleTimestamp *ExampleTimestamp) (uint64, error) {
return this.table.InsertReturningID(ctx, exampleTimestamp)
}
func (this exampleTimestampTable) Has(ctx context.Context, id uint64) (found bool, err error) {
return this.table.PrimaryKey().Has(ctx, id)
}
func (this exampleTimestampTable) Get(ctx context.Context, id uint64) (*ExampleTimestamp, error) {
var exampleTimestamp ExampleTimestamp
found, err := this.table.PrimaryKey().Get(ctx, &exampleTimestamp, id)
if err != nil {
return nil, err
}
if !found {
return nil, ormerrors.NotFound
}
return &exampleTimestamp, nil
}
func (this exampleTimestampTable) List(ctx context.Context, prefixKey ExampleTimestampIndexKey, opts ...ormlist.Option) (ExampleTimestampIterator, error) {
it, err := this.table.GetIndexByID(prefixKey.id()).List(ctx, prefixKey.values(), opts...)
return ExampleTimestampIterator{it}, err
}
func (this exampleTimestampTable) ListRange(ctx context.Context, from, to ExampleTimestampIndexKey, opts ...ormlist.Option) (ExampleTimestampIterator, error) {
it, err := this.table.GetIndexByID(from.id()).ListRange(ctx, from.values(), to.values(), opts...)
return ExampleTimestampIterator{it}, err
}
func (this exampleTimestampTable) DeleteBy(ctx context.Context, prefixKey ExampleTimestampIndexKey) error {
return this.table.GetIndexByID(prefixKey.id()).DeleteBy(ctx, prefixKey.values()...)
}
func (this exampleTimestampTable) DeleteRange(ctx context.Context, from, to ExampleTimestampIndexKey) error {
return this.table.GetIndexByID(from.id()).DeleteRange(ctx, from.values(), to.values())
}
func (this exampleTimestampTable) doNotImplement() {}
var _ ExampleTimestampTable = exampleTimestampTable{}
func NewExampleTimestampTable(db ormtable.Schema) (ExampleTimestampTable, error) {
table := db.GetTable(&ExampleTimestamp{})
if table == nil {
return nil, ormerrors.TableNotFound.Wrap(string((&ExampleTimestamp{}).ProtoReflect().Descriptor().FullName()))
}
return exampleTimestampTable{table.(ormtable.AutoIncrementTable)}, nil
}
type TestSchemaStore interface {
ExampleTableTable() ExampleTableTable
ExampleAutoIncrementTableTable() ExampleAutoIncrementTableTable
ExampleSingletonTable() ExampleSingletonTable
ExampleTimestampTable() ExampleTimestampTable
doNotImplement()
}
@ -410,6 +543,7 @@ type testSchemaStore struct {
exampleTable ExampleTableTable
exampleAutoIncrementTable ExampleAutoIncrementTableTable
exampleSingleton ExampleSingletonTable
exampleTimestamp ExampleTimestampTable
}
func (x testSchemaStore) ExampleTableTable() ExampleTableTable {
@ -424,6 +558,10 @@ func (x testSchemaStore) ExampleSingletonTable() ExampleSingletonTable {
return x.exampleSingleton
}
func (x testSchemaStore) ExampleTimestampTable() ExampleTimestampTable {
return x.exampleTimestamp
}
func (testSchemaStore) doNotImplement() {}
var _ TestSchemaStore = testSchemaStore{}
@ -444,9 +582,15 @@ func NewTestSchemaStore(db ormtable.Schema) (TestSchemaStore, error) {
return nil, err
}
exampleTimestampTable, err := NewExampleTimestampTable(db)
if err != nil {
return nil, err
}
return testSchemaStore{
exampleTableTable,
exampleAutoIncrementTableTable,
exampleSingletonTable,
exampleTimestampTable,
}, nil
}

View File

@ -92,3 +92,15 @@ message ExampleSingleton {
string foo = 1;
int32 bar = 2;
}
message ExampleTimestamp {
option (cosmos.orm.v1alpha1.table) = {
id: 4
primary_key: {fields: "id" auto_increment: true}
index: {id: 1 fields: "ts"}
};
uint64 id = 1;
string name = 2;
google.protobuf.Timestamp ts = 3;
}

View File

@ -4,19 +4,17 @@ package testpb
import (
binary "encoding/binary"
fmt "fmt"
io "io"
reflect "reflect"
sort "sort"
sync "sync"
runtime "github.com/cosmos/cosmos-proto/runtime"
_ "github.com/cosmos/cosmos-sdk/api/cosmos/orm/v1alpha1"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoiface "google.golang.org/protobuf/runtime/protoiface"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
durationpb "google.golang.org/protobuf/types/known/durationpb"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
_ "github.com/cosmos/cosmos-sdk/api/cosmos/orm/v1alpha1"
io "io"
reflect "reflect"
sort "sort"
sync "sync"
)
var _ protoreflect.List = (*_ExampleTable_17_list)(nil)
@ -1874,7 +1872,7 @@ func (x *ExampleTable_ExampleMessage) ProtoReflect() protoreflect.Message {
}
func (x *ExampleTable_ExampleMessage) slowProtoReflect() protoreflect.Message {
mi := &file_testpb_test_schema_proto_msgTypes[4]
mi := &file_testpb_test_schema_proto_msgTypes[5]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -3304,10 +3302,557 @@ func (x *fastReflection_ExampleSingleton) ProtoMethods() *protoiface.Methods {
}
}
var (
md_ExampleTimestamp protoreflect.MessageDescriptor
fd_ExampleTimestamp_id protoreflect.FieldDescriptor
fd_ExampleTimestamp_name protoreflect.FieldDescriptor
fd_ExampleTimestamp_ts protoreflect.FieldDescriptor
)
func init() {
file_testpb_test_schema_proto_init()
md_ExampleTimestamp = File_testpb_test_schema_proto.Messages().ByName("ExampleTimestamp")
fd_ExampleTimestamp_id = md_ExampleTimestamp.Fields().ByName("id")
fd_ExampleTimestamp_name = md_ExampleTimestamp.Fields().ByName("name")
fd_ExampleTimestamp_ts = md_ExampleTimestamp.Fields().ByName("ts")
}
var _ protoreflect.Message = (*fastReflection_ExampleTimestamp)(nil)
type fastReflection_ExampleTimestamp ExampleTimestamp
func (x *ExampleTimestamp) ProtoReflect() protoreflect.Message {
return (*fastReflection_ExampleTimestamp)(x)
}
func (x *ExampleTimestamp) slowProtoReflect() protoreflect.Message {
mi := &file_testpb_test_schema_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)
}
var _fastReflection_ExampleTimestamp_messageType fastReflection_ExampleTimestamp_messageType
var _ protoreflect.MessageType = fastReflection_ExampleTimestamp_messageType{}
type fastReflection_ExampleTimestamp_messageType struct{}
func (x fastReflection_ExampleTimestamp_messageType) Zero() protoreflect.Message {
return (*fastReflection_ExampleTimestamp)(nil)
}
func (x fastReflection_ExampleTimestamp_messageType) New() protoreflect.Message {
return new(fastReflection_ExampleTimestamp)
}
func (x fastReflection_ExampleTimestamp_messageType) Descriptor() protoreflect.MessageDescriptor {
return md_ExampleTimestamp
}
// Descriptor returns message descriptor, which contains only the protobuf
// type information for the message.
func (x *fastReflection_ExampleTimestamp) Descriptor() protoreflect.MessageDescriptor {
return md_ExampleTimestamp
}
// Type returns the message type, which encapsulates both Go and protobuf
// type information. If the Go type information is not needed,
// it is recommended that the message descriptor be used instead.
func (x *fastReflection_ExampleTimestamp) Type() protoreflect.MessageType {
return _fastReflection_ExampleTimestamp_messageType
}
// New returns a newly allocated and mutable empty message.
func (x *fastReflection_ExampleTimestamp) New() protoreflect.Message {
return new(fastReflection_ExampleTimestamp)
}
// Interface unwraps the message reflection interface and
// returns the underlying ProtoMessage interface.
func (x *fastReflection_ExampleTimestamp) Interface() protoreflect.ProtoMessage {
return (*ExampleTimestamp)(x)
}
// Range iterates over every populated field in an undefined order,
// calling f for each field descriptor and value encountered.
// Range returns immediately if f returns false.
// While iterating, mutating operations may only be performed
// on the current field descriptor.
func (x *fastReflection_ExampleTimestamp) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
if x.Id != uint64(0) {
value := protoreflect.ValueOfUint64(x.Id)
if !f(fd_ExampleTimestamp_id, value) {
return
}
}
if x.Name != "" {
value := protoreflect.ValueOfString(x.Name)
if !f(fd_ExampleTimestamp_name, value) {
return
}
}
if x.Ts != nil {
value := protoreflect.ValueOfMessage(x.Ts.ProtoReflect())
if !f(fd_ExampleTimestamp_ts, value) {
return
}
}
}
// Has reports whether a field is populated.
//
// Some fields have the property of nullability where it is possible to
// distinguish between the default value of a field and whether the field
// was explicitly populated with the default value. Singular message fields,
// member fields of a oneof, and proto2 scalar fields are nullable. Such
// fields are populated only if explicitly set.
//
// In other cases (aside from the nullable cases above),
// a proto3 scalar field is populated if it contains a non-zero value, and
// a repeated field is populated if it is non-empty.
func (x *fastReflection_ExampleTimestamp) Has(fd protoreflect.FieldDescriptor) bool {
switch fd.FullName() {
case "testpb.ExampleTimestamp.id":
return x.Id != uint64(0)
case "testpb.ExampleTimestamp.name":
return x.Name != ""
case "testpb.ExampleTimestamp.ts":
return x.Ts != nil
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleTimestamp"))
}
panic(fmt.Errorf("message testpb.ExampleTimestamp does not contain field %s", fd.FullName()))
}
}
// Clear clears the field such that a subsequent Has call reports false.
//
// Clearing an extension field clears both the extension type and value
// associated with the given field number.
//
// Clear is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_ExampleTimestamp) Clear(fd protoreflect.FieldDescriptor) {
switch fd.FullName() {
case "testpb.ExampleTimestamp.id":
x.Id = uint64(0)
case "testpb.ExampleTimestamp.name":
x.Name = ""
case "testpb.ExampleTimestamp.ts":
x.Ts = nil
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleTimestamp"))
}
panic(fmt.Errorf("message testpb.ExampleTimestamp does not contain field %s", fd.FullName()))
}
}
// Get retrieves the value for a field.
//
// For unpopulated scalars, it returns the default value, where
// the default value of a bytes scalar is guaranteed to be a copy.
// For unpopulated composite types, it returns an empty, read-only view
// of the value; to obtain a mutable reference, use Mutable.
func (x *fastReflection_ExampleTimestamp) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value {
switch descriptor.FullName() {
case "testpb.ExampleTimestamp.id":
value := x.Id
return protoreflect.ValueOfUint64(value)
case "testpb.ExampleTimestamp.name":
value := x.Name
return protoreflect.ValueOfString(value)
case "testpb.ExampleTimestamp.ts":
value := x.Ts
return protoreflect.ValueOfMessage(value.ProtoReflect())
default:
if descriptor.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleTimestamp"))
}
panic(fmt.Errorf("message testpb.ExampleTimestamp does not contain field %s", descriptor.FullName()))
}
}
// Set stores the value for a field.
//
// For a field belonging to a oneof, it implicitly clears any other field
// that may be currently set within the same oneof.
// For extension fields, it implicitly stores the provided ExtensionType.
// When setting a composite type, it is unspecified whether the stored value
// aliases the source's memory in any way. If the composite value is an
// empty, read-only value, then it panics.
//
// Set is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_ExampleTimestamp) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) {
switch fd.FullName() {
case "testpb.ExampleTimestamp.id":
x.Id = value.Uint()
case "testpb.ExampleTimestamp.name":
x.Name = value.Interface().(string)
case "testpb.ExampleTimestamp.ts":
x.Ts = value.Message().Interface().(*timestamppb.Timestamp)
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleTimestamp"))
}
panic(fmt.Errorf("message testpb.ExampleTimestamp does not contain field %s", fd.FullName()))
}
}
// Mutable returns a mutable reference to a composite type.
//
// If the field is unpopulated, it may allocate a composite value.
// For a field belonging to a oneof, it implicitly clears any other field
// that may be currently set within the same oneof.
// For extension fields, it implicitly stores the provided ExtensionType
// if not already stored.
// It panics if the field does not contain a composite type.
//
// Mutable is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_ExampleTimestamp) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value {
switch fd.FullName() {
case "testpb.ExampleTimestamp.ts":
if x.Ts == nil {
x.Ts = new(timestamppb.Timestamp)
}
return protoreflect.ValueOfMessage(x.Ts.ProtoReflect())
case "testpb.ExampleTimestamp.id":
panic(fmt.Errorf("field id of message testpb.ExampleTimestamp is not mutable"))
case "testpb.ExampleTimestamp.name":
panic(fmt.Errorf("field name of message testpb.ExampleTimestamp is not mutable"))
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleTimestamp"))
}
panic(fmt.Errorf("message testpb.ExampleTimestamp does not contain field %s", fd.FullName()))
}
}
// NewField returns a new value that is assignable to the field
// for the given descriptor. For scalars, this returns the default value.
// For lists, maps, and messages, this returns a new, empty, mutable value.
func (x *fastReflection_ExampleTimestamp) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value {
switch fd.FullName() {
case "testpb.ExampleTimestamp.id":
return protoreflect.ValueOfUint64(uint64(0))
case "testpb.ExampleTimestamp.name":
return protoreflect.ValueOfString("")
case "testpb.ExampleTimestamp.ts":
m := new(timestamppb.Timestamp)
return protoreflect.ValueOfMessage(m.ProtoReflect())
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ExampleTimestamp"))
}
panic(fmt.Errorf("message testpb.ExampleTimestamp does not contain field %s", fd.FullName()))
}
}
// WhichOneof reports which field within the oneof is populated,
// returning nil if none are populated.
// It panics if the oneof descriptor does not belong to this message.
func (x *fastReflection_ExampleTimestamp) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
switch d.FullName() {
default:
panic(fmt.Errorf("%s is not a oneof field in testpb.ExampleTimestamp", d.FullName()))
}
panic("unreachable")
}
// GetUnknown retrieves the entire list of unknown fields.
// The caller may only mutate the contents of the RawFields
// if the mutated bytes are stored back into the message with SetUnknown.
func (x *fastReflection_ExampleTimestamp) GetUnknown() protoreflect.RawFields {
return x.unknownFields
}
// SetUnknown stores an entire list of unknown fields.
// The raw fields must be syntactically valid according to the wire format.
// An implementation may panic if this is not the case.
// Once stored, the caller must not mutate the content of the RawFields.
// An empty RawFields may be passed to clear the fields.
//
// SetUnknown is a mutating operation and unsafe for concurrent use.
func (x *fastReflection_ExampleTimestamp) SetUnknown(fields protoreflect.RawFields) {
x.unknownFields = fields
}
// IsValid reports whether the message is valid.
//
// An invalid message is an empty, read-only value.
//
// An invalid message often corresponds to a nil pointer of the concrete
// message type, but the details are implementation dependent.
// Validity is not part of the protobuf data model, and may not
// be preserved in marshaling or other operations.
func (x *fastReflection_ExampleTimestamp) IsValid() bool {
return x != nil
}
// ProtoMethods returns optional fastReflectionFeature-path implementations of various operations.
// This method may return nil.
//
// The returned methods type is identical to
// "google.golang.org/protobuf/runtime/protoiface".Methods.
// Consult the protoiface package documentation for details.
func (x *fastReflection_ExampleTimestamp) ProtoMethods() *protoiface.Methods {
size := func(input protoiface.SizeInput) protoiface.SizeOutput {
x := input.Message.Interface().(*ExampleTimestamp)
if x == nil {
return protoiface.SizeOutput{
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
Size: 0,
}
}
options := runtime.SizeInputToOptions(input)
_ = options
var n int
var l int
_ = l
if x.Id != 0 {
n += 1 + runtime.Sov(uint64(x.Id))
}
l = len(x.Name)
if l > 0 {
n += 1 + l + runtime.Sov(uint64(l))
}
if x.Ts != nil {
l = options.Size(x.Ts)
n += 1 + l + runtime.Sov(uint64(l))
}
if x.unknownFields != nil {
n += len(x.unknownFields)
}
return protoiface.SizeOutput{
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
Size: n,
}
}
marshal := func(input protoiface.MarshalInput) (protoiface.MarshalOutput, error) {
x := input.Message.Interface().(*ExampleTimestamp)
if x == nil {
return protoiface.MarshalOutput{
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
Buf: input.Buf,
}, nil
}
options := runtime.MarshalInputToOptions(input)
_ = options
size := options.Size(x)
dAtA := make([]byte, size)
i := len(dAtA)
_ = i
var l int
_ = l
if x.unknownFields != nil {
i -= len(x.unknownFields)
copy(dAtA[i:], x.unknownFields)
}
if x.Ts != nil {
encoded, err := options.Marshal(x.Ts)
if err != nil {
return protoiface.MarshalOutput{
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
Buf: input.Buf,
}, err
}
i -= len(encoded)
copy(dAtA[i:], encoded)
i = runtime.EncodeVarint(dAtA, i, uint64(len(encoded)))
i--
dAtA[i] = 0x1a
}
if len(x.Name) > 0 {
i -= len(x.Name)
copy(dAtA[i:], x.Name)
i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Name)))
i--
dAtA[i] = 0x12
}
if x.Id != 0 {
i = runtime.EncodeVarint(dAtA, i, uint64(x.Id))
i--
dAtA[i] = 0x8
}
if input.Buf != nil {
input.Buf = append(input.Buf, dAtA...)
} else {
input.Buf = dAtA
}
return protoiface.MarshalOutput{
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
Buf: input.Buf,
}, nil
}
unmarshal := func(input protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) {
x := input.Message.Interface().(*ExampleTimestamp)
if x == nil {
return protoiface.UnmarshalOutput{
NoUnkeyedLiterals: input.NoUnkeyedLiterals,
Flags: input.Flags,
}, nil
}
options := runtime.UnmarshalInputToOptions(input)
_ = options
dAtA := input.Buf
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow
}
if iNdEx >= l {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: ExampleTimestamp: wiretype end group for non-group")
}
if fieldNum <= 0 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: ExampleTimestamp: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 0 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Id", wireType)
}
x.Id = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow
}
if iNdEx >= l {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
x.Id |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
case 2:
if wireType != 2 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Name", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow
}
if iNdEx >= l {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength
}
if postIndex > l {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
}
x.Name = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 2 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Ts", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrIntOverflow
}
if iNdEx >= l {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength
}
if postIndex > l {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
}
if x.Ts == nil {
x.Ts = &timestamppb.Timestamp{}
}
if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Ts); err != nil {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := runtime.Skip(dAtA[iNdEx:])
if err != nil {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength
}
if (iNdEx + skippy) > l {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
}
if !options.DiscardUnknown {
x.unknownFields = append(x.unknownFields, dAtA[iNdEx:iNdEx+skippy]...)
}
iNdEx += skippy
}
}
if iNdEx > l {
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF
}
return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, nil
}
return &protoiface.Methods{
NoUnkeyedLiterals: struct{}{},
Flags: protoiface.SupportMarshalDeterministic | protoiface.SupportUnmarshalDiscardUnknown,
Size: size,
Marshal: marshal,
Unmarshal: unmarshal,
Merge: nil,
CheckInitialized: nil,
}
}
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.0
// protoc (unknown)
// protoc v3.19.1
// source: testpb/test_schema.proto
const (
@ -3674,6 +4219,57 @@ func (x *ExampleSingleton) GetBar() int32 {
return 0
}
type ExampleTimestamp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Ts *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=ts,proto3" json:"ts,omitempty"`
}
func (x *ExampleTimestamp) Reset() {
*x = ExampleTimestamp{}
if protoimpl.UnsafeEnabled {
mi := &file_testpb_test_schema_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ExampleTimestamp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ExampleTimestamp) ProtoMessage() {}
// Deprecated: Use ExampleTimestamp.ProtoReflect.Descriptor instead.
func (*ExampleTimestamp) Descriptor() ([]byte, []int) {
return file_testpb_test_schema_proto_rawDescGZIP(), []int{3}
}
func (x *ExampleTimestamp) GetId() uint64 {
if x != nil {
return x.Id
}
return 0
}
func (x *ExampleTimestamp) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *ExampleTimestamp) GetTs() *timestamppb.Timestamp {
if x != nil {
return x.Ts
}
return nil
}
type ExampleTable_ExampleMessage struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -3686,7 +4282,7 @@ type ExampleTable_ExampleMessage struct {
func (x *ExampleTable_ExampleMessage) Reset() {
*x = ExampleTable_ExampleMessage{}
if protoimpl.UnsafeEnabled {
mi := &file_testpb_test_schema_proto_msgTypes[4]
mi := &file_testpb_test_schema_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -3782,22 +4378,30 @@ var file_testpb_test_schema_proto_rawDesc = []byte{
0x65, 0x53, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x74, 0x6f, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f,
0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03,
0x62, 0x61, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x62, 0x61, 0x72, 0x3a, 0x08,
0xfa, 0x9e, 0xd3, 0x8e, 0x03, 0x02, 0x08, 0x02, 0x2a, 0x64, 0x0a, 0x04, 0x45, 0x6e, 0x75, 0x6d,
0x12, 0x14, 0x0a, 0x10, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49,
0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4f,
0x4e, 0x45, 0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x54, 0x57, 0x4f,
0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x46, 0x49, 0x56, 0x45, 0x10,
0x05, 0x12, 0x1b, 0x0a, 0x0e, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4e, 0x45, 0x47, 0x5f, 0x54, 0x48,
0x52, 0x45, 0x45, 0x10, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x42, 0x87,
0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x0f, 0x54,
0x65, 0x73, 0x74, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01,
0x5a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73,
0x6d, 0x6f, 0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x6f,
0x72, 0x6d, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74,
0x70, 0x62, 0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70,
0x62, 0xca, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73,
0x74, 0x70, 0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea,
0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0xfa, 0x9e, 0xd3, 0x8e, 0x03, 0x02, 0x08, 0x02, 0x22, 0x7c, 0x0a, 0x10, 0x45, 0x78, 0x61, 0x6d,
0x70, 0x6c, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x0e, 0x0a, 0x02,
0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04,
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,
0x12, 0x2a, 0x0a, 0x02, 0x74, 0x73, 0x18, 0x03, 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, 0x02, 0x74, 0x73, 0x3a, 0x18, 0xf2, 0x9e,
0xd3, 0x8e, 0x03, 0x12, 0x0a, 0x06, 0x0a, 0x02, 0x69, 0x64, 0x10, 0x01, 0x12, 0x06, 0x0a, 0x02,
0x74, 0x73, 0x10, 0x01, 0x18, 0x04, 0x2a, 0x64, 0x0a, 0x04, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x14,
0x0a, 0x10, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49,
0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4f, 0x4e, 0x45,
0x10, 0x01, 0x12, 0x0c, 0x0a, 0x08, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x54, 0x57, 0x4f, 0x10, 0x02,
0x12, 0x0d, 0x0a, 0x09, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x46, 0x49, 0x56, 0x45, 0x10, 0x05, 0x12,
0x1b, 0x0a, 0x0e, 0x45, 0x4e, 0x55, 0x4d, 0x5f, 0x4e, 0x45, 0x47, 0x5f, 0x54, 0x48, 0x52, 0x45,
0x45, 0x10, 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x42, 0x87, 0x01, 0x0a,
0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x0f, 0x54, 0x65, 0x73,
0x74, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x30,
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f,
0x73, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x2f, 0x6f, 0x72, 0x6d,
0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62,
0xa2, 0x02, 0x03, 0x54, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xca,
0x02, 0x06, 0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0xe2, 0x02, 0x12, 0x54, 0x65, 0x73, 0x74, 0x70,
0x62, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06,
0x54, 0x65, 0x73, 0x74, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -3813,28 +4417,30 @@ func file_testpb_test_schema_proto_rawDescGZIP() []byte {
}
var file_testpb_test_schema_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_testpb_test_schema_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_testpb_test_schema_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
var file_testpb_test_schema_proto_goTypes = []interface{}{
(Enum)(0), // 0: testpb.Enum
(*ExampleTable)(nil), // 1: testpb.ExampleTable
(*ExampleAutoIncrementTable)(nil), // 2: testpb.ExampleAutoIncrementTable
(*ExampleSingleton)(nil), // 3: testpb.ExampleSingleton
nil, // 4: testpb.ExampleTable.MapEntry
(*ExampleTable_ExampleMessage)(nil), // 5: testpb.ExampleTable.ExampleMessage
(*timestamppb.Timestamp)(nil), // 6: google.protobuf.Timestamp
(*durationpb.Duration)(nil), // 7: google.protobuf.Duration
(*ExampleTimestamp)(nil), // 4: testpb.ExampleTimestamp
nil, // 5: testpb.ExampleTable.MapEntry
(*ExampleTable_ExampleMessage)(nil), // 6: testpb.ExampleTable.ExampleMessage
(*timestamppb.Timestamp)(nil), // 7: google.protobuf.Timestamp
(*durationpb.Duration)(nil), // 8: google.protobuf.Duration
}
var file_testpb_test_schema_proto_depIdxs = []int32{
6, // 0: testpb.ExampleTable.ts:type_name -> google.protobuf.Timestamp
7, // 1: testpb.ExampleTable.dur:type_name -> google.protobuf.Duration
7, // 0: testpb.ExampleTable.ts:type_name -> google.protobuf.Timestamp
8, // 1: testpb.ExampleTable.dur:type_name -> google.protobuf.Duration
0, // 2: testpb.ExampleTable.e:type_name -> testpb.Enum
4, // 3: testpb.ExampleTable.map:type_name -> testpb.ExampleTable.MapEntry
5, // 4: testpb.ExampleTable.msg:type_name -> testpb.ExampleTable.ExampleMessage
5, // [5:5] is the sub-list for method output_type
5, // [5:5] is the sub-list for method input_type
5, // [5:5] is the sub-list for extension type_name
5, // [5:5] is the sub-list for extension extendee
0, // [0:5] is the sub-list for field type_name
5, // 3: testpb.ExampleTable.map:type_name -> testpb.ExampleTable.MapEntry
6, // 4: testpb.ExampleTable.msg:type_name -> testpb.ExampleTable.ExampleMessage
7, // 5: testpb.ExampleTimestamp.ts:type_name -> google.protobuf.Timestamp
6, // [6:6] is the sub-list for method output_type
6, // [6:6] is the sub-list for method input_type
6, // [6:6] is the sub-list for extension type_name
6, // [6:6] is the sub-list for extension extendee
0, // [0:6] is the sub-list for field type_name
}
func init() { file_testpb_test_schema_proto_init() }
@ -3879,7 +4485,19 @@ func file_testpb_test_schema_proto_init() {
return nil
}
}
file_testpb_test_schema_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
file_testpb_test_schema_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ExampleTimestamp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_testpb_test_schema_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ExampleTable_ExampleMessage); i {
case 0:
return &v.state
@ -3901,7 +4519,7 @@ func file_testpb_test_schema_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_testpb_test_schema_proto_rawDesc,
NumEnums: 1,
NumMessages: 5,
NumMessages: 6,
NumExtensions: 0,
NumServices: 0,
},

View File

@ -4,9 +4,11 @@ import (
"bytes"
"context"
"fmt"
"google.golang.org/protobuf/types/known/timestamppb"
"sort"
"strings"
"testing"
"time"
dbm "github.com/tendermint/tm-db"
@ -65,6 +67,51 @@ func TestScenario(t *testing.T) {
checkEncodeDecodeEntries(t, table, store.IndexStoreReader())
}
func TestImportedMessageIterator(t *testing.T) {
table, err := ormtable.Build(ormtable.Options{
MessageType: (&testpb.ExampleTimestamp{}).ProtoReflect().Type(),
})
backend := testkv.NewSplitMemBackend()
ctx := ormtable.WrapContextDefault(backend)
store, err := testpb.NewExampleTimestampTable(table)
assert.NilError(t, err)
past, err := time.Parse("2006-01-02", "2000-01-01")
assert.NilError(t, err)
middle, err := time.Parse("2006-01-02", "2020-01-01")
assert.NilError(t, err)
future, err := time.Parse("2006-01-02", "2049-01-01")
assert.NilError(t, err)
pastPb, middlePb, futurePb := timestamppb.New(past), timestamppb.New(middle), timestamppb.New(future)
timeOrder := [3]*timestamppb.Timestamp{pastPb, middlePb, futurePb}
assert.NilError(t, store.Insert(ctx, &testpb.ExampleTimestamp{
Name: "foo",
Ts: pastPb,
}))
assert.NilError(t, store.Insert(ctx, &testpb.ExampleTimestamp{
Name: "bar",
Ts: middlePb,
}))
assert.NilError(t, store.Insert(ctx, &testpb.ExampleTimestamp{
Name: "baz",
Ts: futurePb,
}))
from, to := testpb.ExampleTimestampTsIndexKey{}.WithTs(timestamppb.New(past)), testpb.ExampleTimestampTsIndexKey{}.WithTs(timestamppb.New(future))
it, err := store.ListRange(ctx, from, to)
assert.NilError(t, err)
i := 0
for it.Next() {
v, err := it.Value()
assert.NilError(t, err)
assert.Equal(t, timeOrder[i].String(), v.Ts.String())
i++
}
}
// check that the ormkv.Entry's decode and encode to the same bytes
func checkEncodeDecodeEntries(t *testing.T, table ormtable.Table, store kv.ReadonlyStore) {
it, err := store.Iterator(nil, nil)