diff --git a/tests/go.mod b/tests/go.mod index a969d4de2afd..514c164f9473 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -13,9 +13,11 @@ require ( cosmossdk.io/x/evidence v0.1.0 cosmossdk.io/x/feegrant v0.0.0-20230117113717-50e7c4a4ceff cosmossdk.io/x/nft v0.0.0-20230113085233-fae3332d62fc + cosmossdk.io/x/tx v0.2.0 cosmossdk.io/x/upgrade v0.0.0-20230127052425-54c8e1568335 github.com/cometbft/cometbft v0.37.0-alpha.3 github.com/cosmos/cosmos-db v1.0.0-rc.1 + github.com/cosmos/cosmos-proto v1.0.0-beta.2 // this version is not used as it is always replaced by the latest Cosmos SDK version github.com/cosmos/cosmos-sdk v0.48.0 github.com/cosmos/gogoproto v1.4.6 @@ -37,7 +39,6 @@ require ( cosmossdk.io/client/v2 v2.0.0-20230220152935-67f04e629623 // indirect cosmossdk.io/collections v0.0.0-20230214153846-b6c6e4e99177 // indirect cosmossdk.io/core v0.5.1 // indirect - cosmossdk.io/x/tx v0.2.0 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect @@ -61,7 +62,6 @@ require ( github.com/cometbft/cometbft-db v0.7.0 // indirect github.com/confio/ics23/go v0.9.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect - github.com/cosmos/cosmos-proto v1.0.0-beta.2 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/iavl v0.21.0-alpha.1 // indirect @@ -113,6 +113,7 @@ require ( github.com/hashicorp/hcl v1.0.0 // indirect github.com/hdevalence/ed25519consensus v0.1.0 // indirect github.com/huandu/skiplist v1.2.0 // indirect + github.com/iancoleman/strcase v0.2.0 // indirect github.com/improbable-eng/grpc-web v0.15.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect @@ -191,9 +192,11 @@ require ( // It must be in sync with SimApp temporary replaces replace ( // TODO tag all extracted modules after SDK refactor + cosmossdk.io/client/v2 => ../client/v2 cosmossdk.io/x/evidence => ../x/evidence cosmossdk.io/x/feegrant => ../x/feegrant cosmossdk.io/x/nft => ../x/nft + cosmossdk.io/x/tx => ../x/tx cosmossdk.io/x/upgrade => ../x/upgrade // This can be deleted after the CometBFT PR is merged github.com/cometbft/cometbft => github.com/cometbft/cometbft v0.0.0-20230203130311-387422ac220d diff --git a/tests/go.sum b/tests/go.sum index 6ddb23db2586..fbd36b0d97a5 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -190,8 +190,6 @@ cloud.google.com/go/workflows v1.6.0/go.mod h1:6t9F5h/unJz41YqfBmqSASJSXccBLtD1V cloud.google.com/go/workflows v1.7.0/go.mod h1:JhSrZuVZWuiDfKEFxU0/F1PQjmpnpcoISEXH2bcHC3M= cosmossdk.io/api v0.3.1 h1:NNiOclKRR0AOlO4KIqeaG6PS6kswOMhHD0ir0SscNXE= cosmossdk.io/api v0.3.1/go.mod h1:DfHfMkiNA2Uhy8fj0JJlOCYOBp4eWUUJ1te5zBGNyIw= -cosmossdk.io/client/v2 v2.0.0-20230220152935-67f04e629623 h1:QzZA1P+twvj10ylCVXzHodLge+RvrwoNIlWpU+MrRa0= -cosmossdk.io/client/v2 v2.0.0-20230220152935-67f04e629623/go.mod h1:Yo6R3XSXKxi+G642kK7+ZOh2czNTwTO1b8ywOvwaFQo= cosmossdk.io/collections v0.0.0-20230214153846-b6c6e4e99177 h1:At2M0aYQKEAWqr6JtZrJPOlfhdvENiGwJg2NCNHwIdc= cosmossdk.io/collections v0.0.0-20230214153846-b6c6e4e99177/go.mod h1:uqCi8FG+Bh2vv/qf5xZ8iab0E0c/DMA/cwafbp8dkcU= cosmossdk.io/core v0.5.1 h1:vQVtFrIYOQJDV3f7rw4pjjVqc1id4+mE0L9hHP66pyI= @@ -206,8 +204,6 @@ cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4 h1:/jnzJ9zFsL7qkV8 cosmossdk.io/math v1.0.0-beta.6.0.20230216172121-959ce49135e4/go.mod h1:gUVtWwIzfSXqcOT+lBVz2jyjfua8DoBdzRsIyaUAT/8= cosmossdk.io/store v0.0.0-20230206092147-e03195e4b8a7 h1:IwyDN/YaQmF+Pmuv8d7vRWMM/k2RjSmPBycMcmd3ICE= cosmossdk.io/store v0.0.0-20230206092147-e03195e4b8a7/go.mod h1:1XOtuYs7jsfQkn7G3VQXB6I+2tHXKHZw2U/AafNbnlk= -cosmossdk.io/x/tx v0.2.0 h1:53f5TIXhpPYJGMm47SUslcV2i8JNBEN3eE08BmxE/Zg= -cosmossdk.io/x/tx v0.2.0/go.mod h1:CTko7wgt7aBdbxOesZ+Wo1uO/03ueKzIQ0iI323Rqgk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= @@ -685,6 +681,8 @@ github.com/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w= github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE= +github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= +github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA= diff --git a/tests/integration/aminojson/.gitignore b/tests/integration/aminojson/.gitignore new file mode 100644 index 000000000000..9309455bc5b4 --- /dev/null +++ b/tests/integration/aminojson/.gitignore @@ -0,0 +1 @@ +testdata/rapid diff --git a/tests/integration/aminojson/aminojson_test.go b/tests/integration/aminojson/aminojson_test.go new file mode 100644 index 000000000000..9e0733e2343f --- /dev/null +++ b/tests/integration/aminojson/aminojson_test.go @@ -0,0 +1,684 @@ +package aminojson + +import ( + "fmt" + "reflect" + "testing" + "time" + + cosmos_proto "github.com/cosmos/cosmos-proto" + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" + "google.golang.org/protobuf/types/known/anypb" + "google.golang.org/protobuf/types/known/durationpb" + "google.golang.org/protobuf/types/known/timestamppb" + "pgregory.net/rapid" + + "github.com/cosmos/cosmos-proto/rapidproto" + gogoproto "github.com/cosmos/gogoproto/proto" + + "cosmossdk.io/api/amino" + authapi "cosmossdk.io/api/cosmos/auth/v1beta1" + authzapi "cosmossdk.io/api/cosmos/authz/v1beta1" + bankapi "cosmossdk.io/api/cosmos/bank/v1beta1" + v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" + consensusapi "cosmossdk.io/api/cosmos/consensus/v1" + "cosmossdk.io/api/cosmos/crypto/ed25519" + multisigapi "cosmossdk.io/api/cosmos/crypto/multisig" + "cosmossdk.io/api/cosmos/crypto/secp256k1" + distapi "cosmossdk.io/api/cosmos/distribution/v1beta1" + evidenceapi "cosmossdk.io/api/cosmos/evidence/v1beta1" + feegrantapi "cosmossdk.io/api/cosmos/feegrant/v1beta1" + gov_v1_api "cosmossdk.io/api/cosmos/gov/v1" + gov_v1beta1_api "cosmossdk.io/api/cosmos/gov/v1beta1" + groupapi "cosmossdk.io/api/cosmos/group/v1" + mintapi "cosmossdk.io/api/cosmos/mint/v1beta1" + paramsapi "cosmossdk.io/api/cosmos/params/v1beta1" + slashingapi "cosmossdk.io/api/cosmos/slashing/v1beta1" + stakingapi "cosmossdk.io/api/cosmos/staking/v1beta1" + upgradeapi "cosmossdk.io/api/cosmos/upgrade/v1beta1" + vestingapi "cosmossdk.io/api/cosmos/vesting/v1beta1" + "cosmossdk.io/x/evidence" + evidencetypes "cosmossdk.io/x/evidence/types" + feegranttypes "cosmossdk.io/x/feegrant" + feegrantmodule "cosmossdk.io/x/feegrant/module" + "cosmossdk.io/x/tx/aminojson" + "cosmossdk.io/x/upgrade" + upgradetypes "cosmossdk.io/x/upgrade/types" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + ed25519types "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" + secp256k1types "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + gogo_testpb "github.com/cosmos/cosmos-sdk/tests/integration/aminojson/internal/gogo/testpb" + pulsar_testpb "github.com/cosmos/cosmos-sdk/tests/integration/aminojson/internal/pulsar/testpb" + "github.com/cosmos/cosmos-sdk/testutil/testdata" + "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/bech32" + "github.com/cosmos/cosmos-sdk/types/module/testutil" + "github.com/cosmos/cosmos-sdk/x/auth" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" + vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + authztypes "github.com/cosmos/cosmos-sdk/x/authz" + authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" + "github.com/cosmos/cosmos-sdk/x/bank" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/consensus" + consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types" + "github.com/cosmos/cosmos-sdk/x/distribution" + disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/gov" + gov_v1_types "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + gov_v1beta1_types "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + grouptypes "github.com/cosmos/cosmos-sdk/x/group" + groupmodule "github.com/cosmos/cosmos-sdk/x/group/module" + "github.com/cosmos/cosmos-sdk/x/mint" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/cosmos/cosmos-sdk/x/params" + "github.com/cosmos/cosmos-sdk/x/params/types/proposal" + "github.com/cosmos/cosmos-sdk/x/slashing" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +type generatedType struct { + pulsar proto.Message + gogo gogoproto.Message + opts rapidproto.GeneratorOptions +} + +func genType(gogo gogoproto.Message, pulsar proto.Message, opts rapidproto.GeneratorOptions) generatedType { + return generatedType{ + pulsar: pulsar, + gogo: gogo, + opts: opts, + } +} + +func withDecisionPolicy(opts rapidproto.GeneratorOptions) rapidproto.GeneratorOptions { + return opts. + WithAnyTypes( + &groupapi.ThresholdDecisionPolicy{}, + &groupapi.PercentageDecisionPolicy{}). + WithDisallowNil(). + WithInterfaceHint("cosmos.group.v1.DecisionPolicy", &groupapi.ThresholdDecisionPolicy{}). + WithInterfaceHint("cosmos.group.v1.DecisionPolicy", &groupapi.PercentageDecisionPolicy{}) +} + +func generatorFieldMapper(t *rapid.T, field protoreflect.FieldDescriptor, name string) (protoreflect.Value, bool) { + opts := field.Options() + switch { + case proto.HasExtension(opts, cosmos_proto.E_Scalar): + scalar := proto.GetExtension(opts, cosmos_proto.E_Scalar).(string) + switch scalar { + case "cosmos.Int": + i32 := rapid.Int32().Draw(t, name) + return protoreflect.ValueOfString(fmt.Sprintf("%d", i32)), true + case "cosmos.Dec": + return protoreflect.ValueOfString(""), true + } + case field.Kind() == protoreflect.BytesKind: + if proto.HasExtension(opts, amino.E_Encoding) { + encoding := proto.GetExtension(opts, amino.E_Encoding).(string) + if encoding == "cosmos_dec_bytes" { + return protoreflect.ValueOfBytes([]byte{}), true + } + } + } + + return protoreflect.Value{}, false +} + +var ( + genOpts = rapidproto.GeneratorOptions{ + Resolver: protoregistry.GlobalTypes, + FieldMaps: []rapidproto.FieldMapper{generatorFieldMapper}, + } + genTypes = []generatedType{ + // auth + genType(&authtypes.Params{}, &authapi.Params{}, genOpts), + genType(&authtypes.BaseAccount{}, &authapi.BaseAccount{}, genOpts.WithAnyTypes(&ed25519.PubKey{})), + genType(&authtypes.ModuleAccount{}, &authapi.ModuleAccount{}, genOpts.WithAnyTypes(&ed25519.PubKey{})), + genType(&authtypes.ModuleCredential{}, &authapi.ModuleCredential{}, genOpts), + genType(&authtypes.MsgUpdateParams{}, &authapi.MsgUpdateParams{}, genOpts.WithDisallowNil()), + + // authz + genType(&authztypes.GenericAuthorization{}, &authzapi.GenericAuthorization{}, genOpts), + genType(&authztypes.Grant{}, &authzapi.Grant{}, + genOpts.WithAnyTypes(&authzapi.GenericAuthorization{}). + WithDisallowNil(). + WithInterfaceHint("cosmos.authz.v1beta1.Authorization", &authzapi.GenericAuthorization{}), + ), + genType(&authztypes.MsgGrant{}, &authzapi.MsgGrant{}, + genOpts.WithAnyTypes(&authzapi.GenericAuthorization{}). + WithInterfaceHint("cosmos.authz.v1beta1.Authorization", &authzapi.GenericAuthorization{}). + WithDisallowNil(), + ), + genType(&authztypes.MsgExec{}, &authzapi.MsgExec{}, + genOpts.WithAnyTypes(&authzapi.MsgGrant{}, &authzapi.GenericAuthorization{}). + WithDisallowNil(). + WithInterfaceHint("cosmos.authz.v1beta1.Authorization", &authzapi.GenericAuthorization{}). + WithInterfaceHint("cosmos.base.v1beta1.Msg", &authzapi.MsgGrant{}), + ), + + // bank + genType(&banktypes.MsgSend{}, &bankapi.MsgSend{}, genOpts.WithDisallowNil()), + genType(&banktypes.MsgMultiSend{}, &bankapi.MsgMultiSend{}, genOpts.WithDisallowNil()), + genType(&banktypes.MsgUpdateParams{}, &bankapi.MsgUpdateParams{}, genOpts.WithDisallowNil()), + genType(&banktypes.MsgSetSendEnabled{}, &bankapi.MsgSetSendEnabled{}, genOpts), + genType(&banktypes.SendAuthorization{}, &bankapi.SendAuthorization{}, genOpts), + genType(&banktypes.Params{}, &bankapi.Params{}, genOpts), + + // consensus + genType(&consensustypes.MsgUpdateParams{}, &consensusapi.MsgUpdateParams{}, genOpts.WithDisallowNil()), + + // crypto + genType(&multisig.LegacyAminoPubKey{}, &multisigapi.LegacyAminoPubKey{}, + genOpts.WithAnyTypes(&ed25519.PubKey{}, &secp256k1.PubKey{})), + + // distribution + genType(&disttypes.MsgWithdrawDelegatorReward{}, &distapi.MsgWithdrawDelegatorReward{}, genOpts), + genType(&disttypes.MsgWithdrawValidatorCommission{}, &distapi.MsgWithdrawValidatorCommission{}, genOpts), + genType(&disttypes.MsgSetWithdrawAddress{}, &distapi.MsgSetWithdrawAddress{}, genOpts), + genType(&disttypes.MsgFundCommunityPool{}, &distapi.MsgFundCommunityPool{}, genOpts), + genType(&disttypes.MsgUpdateParams{}, &distapi.MsgUpdateParams{}, genOpts.WithDisallowNil()), + genType(&disttypes.MsgCommunityPoolSpend{}, &distapi.MsgCommunityPoolSpend{}, genOpts), + genType(&disttypes.MsgDepositValidatorRewardsPool{}, &distapi.MsgDepositValidatorRewardsPool{}, genOpts), + genType(&disttypes.Params{}, &distapi.Params{}, genOpts), + + // evidence + genType(&evidencetypes.Equivocation{}, &evidenceapi.Equivocation{}, genOpts.WithDisallowNil()), + genType(&evidencetypes.MsgSubmitEvidence{}, &evidenceapi.MsgSubmitEvidence{}, + genOpts.WithAnyTypes(&evidenceapi.Equivocation{}). + WithDisallowNil(). + WithInterfaceHint("cosmos.evidence.v1beta1.Evidence", &evidenceapi.Equivocation{})), + + // feegrant + genType(&feegranttypes.MsgGrantAllowance{}, &feegrantapi.MsgGrantAllowance{}, + genOpts.WithDisallowNil(). + WithAnyTypes( + &feegrantapi.BasicAllowance{}, + &feegrantapi.PeriodicAllowance{}). + WithInterfaceHint("cosmos.feegrant.v1beta1.FeeAllowanceI", &feegrantapi.BasicAllowance{}). + WithInterfaceHint("cosmos.feegrant.v1beta1.FeeAllowanceI", &feegrantapi.PeriodicAllowance{}), + ), + genType(&feegranttypes.MsgRevokeAllowance{}, &feegrantapi.MsgRevokeAllowance{}, genOpts), + genType(&feegranttypes.BasicAllowance{}, &feegrantapi.BasicAllowance{}, genOpts.WithDisallowNil()), + genType(&feegranttypes.PeriodicAllowance{}, &feegrantapi.PeriodicAllowance{}, genOpts.WithDisallowNil()), + genType(&feegranttypes.AllowedMsgAllowance{}, &feegrantapi.AllowedMsgAllowance{}, + genOpts.WithDisallowNil(). + WithAnyTypes( + &feegrantapi.BasicAllowance{}, + &feegrantapi.PeriodicAllowance{}). + WithInterfaceHint("cosmos.feegrant.v1beta1.FeeAllowanceI", &feegrantapi.BasicAllowance{}). + WithInterfaceHint("cosmos.feegrant.v1beta1.FeeAllowanceI", &feegrantapi.PeriodicAllowance{}), + ), + + // gov v1beta1 + genType(&gov_v1beta1_types.MsgSubmitProposal{}, &gov_v1beta1_api.MsgSubmitProposal{}, + genOpts.WithAnyTypes(&gov_v1beta1_api.TextProposal{}). + WithDisallowNil(). + WithInterfaceHint("cosmos.gov.v1beta1.Content", &gov_v1beta1_api.TextProposal{}), + ), + genType(&gov_v1beta1_types.MsgDeposit{}, &gov_v1beta1_api.MsgDeposit{}, genOpts), + genType(&gov_v1beta1_types.MsgVote{}, &gov_v1beta1_api.MsgVote{}, genOpts), + genType(&gov_v1beta1_types.MsgVoteWeighted{}, &gov_v1beta1_api.MsgVoteWeighted{}, genOpts), + genType(&gov_v1beta1_types.TextProposal{}, &gov_v1beta1_api.TextProposal{}, genOpts), + + // gov v1 + genType(&gov_v1_types.MsgSubmitProposal{}, &gov_v1_api.MsgSubmitProposal{}, + genOpts.WithAnyTypes(&gov_v1_api.MsgVote{}, &gov_v1_api.MsgVoteWeighted{}, &gov_v1_api.MsgDeposit{}, + &gov_v1_api.MsgExecLegacyContent{}, &gov_v1_api.MsgUpdateParams{}). + WithInterfaceHint("cosmos.gov.v1beta1.Content", &gov_v1beta1_api.TextProposal{}). + WithDisallowNil(), + ), + genType(&gov_v1_types.MsgDeposit{}, &gov_v1_api.MsgDeposit{}, genOpts), + genType(&gov_v1_types.MsgVote{}, &gov_v1_api.MsgVote{}, genOpts), + genType(&gov_v1_types.MsgVoteWeighted{}, &gov_v1_api.MsgVoteWeighted{}, genOpts), + genType(&gov_v1_types.MsgExecLegacyContent{}, &gov_v1_api.MsgExecLegacyContent{}, + genOpts.WithAnyTypes(&gov_v1beta1_api.TextProposal{}). + WithDisallowNil(). + WithInterfaceHint("cosmos.gov.v1beta1.Content", &gov_v1beta1_api.TextProposal{})), + genType(&gov_v1_types.MsgUpdateParams{}, &gov_v1_api.MsgUpdateParams{}, genOpts.WithDisallowNil()), + + // group + genType(&grouptypes.MsgCreateGroup{}, &groupapi.MsgCreateGroup{}, genOpts), + genType(&grouptypes.MsgUpdateGroupMembers{}, &groupapi.MsgUpdateGroupMembers{}, genOpts), + genType(&grouptypes.MsgUpdateGroupAdmin{}, &groupapi.MsgUpdateGroupAdmin{}, genOpts), + genType(&grouptypes.MsgUpdateGroupMetadata{}, &groupapi.MsgUpdateGroupMetadata{}, genOpts), + genType(&grouptypes.MsgCreateGroupWithPolicy{}, &groupapi.MsgCreateGroupWithPolicy{}, + withDecisionPolicy(genOpts)), + genType(&grouptypes.MsgCreateGroupPolicy{}, &groupapi.MsgCreateGroupPolicy{}, + withDecisionPolicy(genOpts)), + genType(&grouptypes.MsgUpdateGroupPolicyAdmin{}, &groupapi.MsgUpdateGroupPolicyAdmin{}, genOpts), + genType(&grouptypes.MsgUpdateGroupPolicyDecisionPolicy{}, &groupapi.MsgUpdateGroupPolicyDecisionPolicy{}, + withDecisionPolicy(genOpts)), + genType(&grouptypes.MsgUpdateGroupPolicyMetadata{}, &groupapi.MsgUpdateGroupPolicyMetadata{}, genOpts), + genType(&grouptypes.MsgSubmitProposal{}, &groupapi.MsgSubmitProposal{}, + genOpts.WithDisallowNil(). + WithAnyTypes(&groupapi.MsgCreateGroup{}, &groupapi.MsgUpdateGroupMembers{}). + WithInterfaceHint("cosmos.base.v1beta1.Msg", &groupapi.MsgCreateGroup{}). + WithInterfaceHint("cosmos.base.v1beta1.Msg", &groupapi.MsgUpdateGroupMembers{}), + ), + genType(&grouptypes.MsgVote{}, &groupapi.MsgVote{}, genOpts), + genType(&grouptypes.MsgExec{}, &groupapi.MsgExec{}, genOpts), + genType(&grouptypes.MsgLeaveGroup{}, &groupapi.MsgLeaveGroup{}, genOpts), + + // mint + genType(&minttypes.Params{}, &mintapi.Params{}, genOpts), + genType(&minttypes.MsgUpdateParams{}, &mintapi.MsgUpdateParams{}, genOpts.WithDisallowNil()), + + // params + genType(&proposal.ParameterChangeProposal{}, ¶msapi.ParameterChangeProposal{}, genOpts), + + // slashing + genType(&slashingtypes.Params{}, &slashingapi.Params{}, genOpts.WithDisallowNil()), + genType(&slashingtypes.MsgUnjail{}, &slashingapi.MsgUnjail{}, genOpts), + genType(&slashingtypes.MsgUpdateParams{}, &slashingapi.MsgUpdateParams{}, genOpts.WithDisallowNil()), + + // staking + genType(&stakingtypes.MsgCreateValidator{}, &stakingapi.MsgCreateValidator{}, + genOpts.WithDisallowNil(). + WithAnyTypes(&ed25519.PubKey{}). + WithInterfaceHint("cosmos.crypto.PubKey", &ed25519.PubKey{}), + ), + genType(&stakingtypes.MsgEditValidator{}, &stakingapi.MsgEditValidator{}, genOpts.WithDisallowNil()), + genType(&stakingtypes.MsgDelegate{}, &stakingapi.MsgDelegate{}, genOpts.WithDisallowNil()), + genType(&stakingtypes.MsgUndelegate{}, &stakingapi.MsgUndelegate{}, genOpts.WithDisallowNil()), + genType(&stakingtypes.MsgBeginRedelegate{}, &stakingapi.MsgBeginRedelegate{}, genOpts.WithDisallowNil()), + genType(&stakingtypes.MsgUpdateParams{}, &stakingapi.MsgUpdateParams{}, genOpts.WithDisallowNil()), + genType(&stakingtypes.StakeAuthorization{}, &stakingapi.StakeAuthorization{}, genOpts), + + // upgrade + genType(&upgradetypes.Plan{}, &upgradeapi.Plan{}, genOpts.WithDisallowNil()), + genType(&upgradetypes.SoftwareUpgradeProposal{}, &upgradeapi.SoftwareUpgradeProposal{}, genOpts.WithDisallowNil()), + genType(&upgradetypes.CancelSoftwareUpgradeProposal{}, &upgradeapi.CancelSoftwareUpgradeProposal{}, genOpts), + genType(&upgradetypes.MsgSoftwareUpgrade{}, &upgradeapi.MsgSoftwareUpgrade{}, genOpts.WithDisallowNil()), + genType(&upgradetypes.MsgCancelUpgrade{}, &upgradeapi.MsgCancelUpgrade{}, genOpts), + + // vesting + genType(&vestingtypes.BaseVestingAccount{}, &vestingapi.BaseVestingAccount{}, genOpts.WithDisallowNil()), + genType(&vestingtypes.ContinuousVestingAccount{}, &vestingapi.ContinuousVestingAccount{}, genOpts.WithDisallowNil()), + genType(&vestingtypes.DelayedVestingAccount{}, &vestingapi.DelayedVestingAccount{}, genOpts.WithDisallowNil()), + genType(&vestingtypes.PeriodicVestingAccount{}, &vestingapi.PeriodicVestingAccount{}, genOpts.WithDisallowNil()), + genType(&vestingtypes.PermanentLockedAccount{}, &vestingapi.PermanentLockedAccount{}, genOpts.WithDisallowNil()), + genType(&vestingtypes.MsgCreateVestingAccount{}, &vestingapi.MsgCreateVestingAccount{}, genOpts), + genType(&vestingtypes.MsgCreatePermanentLockedAccount{}, &vestingapi.MsgCreatePermanentLockedAccount{}, genOpts), + genType(&vestingtypes.MsgCreatePeriodicVestingAccount{}, &vestingapi.MsgCreatePeriodicVestingAccount{}, genOpts), + } +) + +// TestAminoJSON_Equivalence tests that x/tx/Encoder encoding is equivalent to the legacy Encoder encoding. +// A custom generator is used to generate random messages that are then encoded using both encoders. The custom +// generator only supports proto.Message (which implement the protoreflect API) so in order to test legacy gogo types +// we end up with a workflow as follows: +// +// 1. Generate a random protobuf proto.Message using the custom generator +// 2. Marshal the proto.Message to protobuf binary bytes +// 3. Unmarshal the protobuf bytes to a gogoproto.Message +// 4. Marshal the gogoproto.Message to amino JSON bytes +// 5. Marshal the proto.Message to amino JSON bytes +// 6. Compare the amino JSON bytes from steps 4 and 5 +// +// In order for step 3 to work certain restrictions on the data generated in step 1 must be enforced and are described +// by the mutation of genOpts passed to the generator. +func TestAminoJSON_Equivalence(t *testing.T) { + encCfg := testutil.MakeTestEncodingConfig( + auth.AppModuleBasic{}, authzmodule.AppModuleBasic{}, bank.AppModuleBasic{}, consensus.AppModuleBasic{}, + distribution.AppModuleBasic{}, evidence.AppModuleBasic{}, feegrantmodule.AppModuleBasic{}, + gov.AppModuleBasic{}, groupmodule.AppModuleBasic{}, mint.AppModuleBasic{}, params.AppModuleBasic{}, + slashing.AppModuleBasic{}, staking.AppModuleBasic{}, upgrade.AppModuleBasic{}, vesting.AppModuleBasic{}) + aj := aminojson.NewAminoJSON() + + for _, tt := range genTypes { + name := string(tt.pulsar.ProtoReflect().Descriptor().FullName()) + t.Run(name, func(t *testing.T) { + gen := rapidproto.MessageGenerator(tt.pulsar, tt.opts) + fmt.Printf("testing %s\n", tt.pulsar.ProtoReflect().Descriptor().FullName()) + rapid.Check(t, func(t *rapid.T) { + // uncomment to debug; catch a panic and inspect application state + //defer func() { + // if r := recover(); r != nil { + // //fmt.Printf("Panic: %+v\n", r) + // t.FailNow() + // } + //}() + + msg := gen.Draw(t, "msg") + postFixPulsarMessage(msg) + + gogo := tt.gogo + sanity := tt.pulsar + + protoBz, err := proto.Marshal(msg) + require.NoError(t, err) + + err = proto.Unmarshal(protoBz, sanity) + require.NoError(t, err) + + err = encCfg.Codec.Unmarshal(protoBz, gogo) + require.NoError(t, err) + + legacyAminoJson, err := encCfg.Amino.MarshalJSON(gogo) + require.NoError(t, err) + aminoJson, err := aj.Marshal(msg) + require.NoError(t, err) + require.Equal(t, string(legacyAminoJson), string(aminoJson)) + }) + }) + } +} + +func newAny(t *testing.T, msg proto.Message) *anypb.Any { + bz, err := proto.Marshal(msg) + require.NoError(t, err) + typeName := fmt.Sprintf("/%s", msg.ProtoReflect().Descriptor().FullName()) + return &anypb.Any{ + TypeUrl: typeName, + Value: bz, + } +} + +// TestAminoJSON_LegacyParity tests that the Encoder encoder produces the same output as the Encoder encoder. +func TestAminoJSON_LegacyParity(t *testing.T) { + encCfg := testutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, authzmodule.AppModuleBasic{}, + bank.AppModuleBasic{}, distribution.AppModuleBasic{}, slashing.AppModuleBasic{}, staking.AppModuleBasic{}, + vesting.AppModuleBasic{}) + + aj := aminojson.NewAminoJSON() + addr1 := types.AccAddress("addr1") + now := time.Now() + + genericAuth, _ := codectypes.NewAnyWithValue(&authztypes.GenericAuthorization{Msg: "foo"}) + genericAuthPulsar := newAny(t, &authzapi.GenericAuthorization{Msg: "foo"}) + pubkeyAny, _ := codectypes.NewAnyWithValue(&secp256k1types.PubKey{Key: []byte("foo")}) + pubkeyAnyPulsar := newAny(t, &secp256k1.PubKey{Key: []byte("foo")}) + dec10bz, _ := types.NewDec(10).Marshal() + int123bz, _ := types.NewInt(123).Marshal() + + cases := map[string]struct { + gogo gogoproto.Message + pulsar proto.Message + pulsarMarshalFails bool + + // this will fail in cases where a lossy encoding of an empty array to protobuf occurs. the unmarshalled bytes + // represent the array as nil, and a subsequent marshal to JSON represent the array as null instead of empty. + roundTripUnequal bool + + // pulsar does not support marshalling a math.Dec as anything except a string. Therefore, we cannot unmarshal + // a pulsar encoded Math.dec (the string representation of a Decimal) into a gogo Math.dec (expecting an int64). + protoUnmarshalFails bool + }{ + "auth/params": {gogo: &authtypes.Params{TxSigLimit: 10}, pulsar: &authapi.Params{TxSigLimit: 10}}, + "auth/module_account": { + gogo: &authtypes.ModuleAccount{ + BaseAccount: authtypes.NewBaseAccountWithAddress(addr1), Permissions: []string{}}, + pulsar: &authapi.ModuleAccount{ + BaseAccount: &authapi.BaseAccount{Address: addr1.String()}, Permissions: []string{}}, + roundTripUnequal: true, + }, + "auth/base_account": { + gogo: &authtypes.BaseAccount{Address: addr1.String(), PubKey: pubkeyAny}, + pulsar: &authapi.BaseAccount{Address: addr1.String(), PubKey: pubkeyAnyPulsar}, + }, + "authz/msg_grant": { + gogo: &authztypes.MsgGrant{ + Grant: authztypes.Grant{Expiration: &now, Authorization: genericAuth}}, + pulsar: &authzapi.MsgGrant{ + Grant: &authzapi.Grant{Expiration: timestamppb.New(now), Authorization: genericAuthPulsar}}, + }, + "authz/msg_update_params": { + gogo: &authtypes.MsgUpdateParams{Params: authtypes.Params{TxSigLimit: 10}}, + pulsar: &authapi.MsgUpdateParams{Params: &authapi.Params{TxSigLimit: 10}}, + }, + "authz/msg_exec/empty_msgs": { + gogo: &authztypes.MsgExec{Msgs: []*codectypes.Any{}}, + pulsar: &authzapi.MsgExec{Msgs: []*anypb.Any{}}, + }, + "distribution/delegator_starting_info": { + gogo: &disttypes.DelegatorStartingInfo{}, + pulsar: &distapi.DelegatorStartingInfo{}, + }, + "distribution/delegator_starting_info/non_zero_dec": { + gogo: &disttypes.DelegatorStartingInfo{Stake: types.NewDec(10)}, + pulsar: &distapi.DelegatorStartingInfo{Stake: "10.000000000000000000"}, + protoUnmarshalFails: true, + }, + "distribution/delegation_delegator_reward": { + gogo: &disttypes.DelegationDelegatorReward{}, + pulsar: &distapi.DelegationDelegatorReward{}, + }, + "distribution/community_pool_spend_proposal_with_deposit": { + gogo: &disttypes.CommunityPoolSpendProposalWithDeposit{}, + pulsar: &distapi.CommunityPoolSpendProposalWithDeposit{}, + }, + "distribution/msg_withdraw_delegator_reward": { + gogo: &disttypes.MsgWithdrawDelegatorReward{DelegatorAddress: "foo"}, + pulsar: &distapi.MsgWithdrawDelegatorReward{DelegatorAddress: "foo"}, + }, + "crypto/ed25519": { + gogo: &ed25519types.PubKey{Key: []byte("key")}, + pulsar: &ed25519.PubKey{Key: []byte("key")}, + }, + "crypto/secp256k1": { + gogo: &secp256k1types.PubKey{Key: []byte("key")}, + pulsar: &secp256k1.PubKey{Key: []byte("key")}, + }, + "crypto/legacy_amino_pubkey": { + gogo: &multisig.LegacyAminoPubKey{PubKeys: []*codectypes.Any{pubkeyAny}}, + pulsar: &multisigapi.LegacyAminoPubKey{PublicKeys: []*anypb.Any{pubkeyAnyPulsar}}, + }, + "crypto/legacy_amino_pubkey/empty": { + gogo: &multisig.LegacyAminoPubKey{}, + pulsar: &multisigapi.LegacyAminoPubKey{}, + }, + "consensus/evidence_params/duration": { + gogo: &gov_v1beta1_types.VotingParams{VotingPeriod: 1e9 + 7}, + pulsar: &gov_v1beta1_api.VotingParams{VotingPeriod: &durationpb.Duration{Seconds: 1, Nanos: 7}}, + }, + "consensus/evidence_params/big_duration": { + gogo: &gov_v1beta1_types.VotingParams{VotingPeriod: time.Duration(rapidproto.MaxDurationSeconds*1e9) + 999999999}, + pulsar: &gov_v1beta1_api.VotingParams{VotingPeriod: &durationpb.Duration{ + Seconds: rapidproto.MaxDurationSeconds, Nanos: 999999999}}, + }, + "consensus/evidence_params/too_big_duration": { + gogo: &gov_v1beta1_types.VotingParams{VotingPeriod: time.Duration(rapidproto.MaxDurationSeconds*1e9) + 999999999}, + pulsar: &gov_v1beta1_api.VotingParams{VotingPeriod: &durationpb.Duration{ + Seconds: rapidproto.MaxDurationSeconds + 1, Nanos: 999999999}}, + pulsarMarshalFails: true, + }, + // amino.dont_omitempty + empty/nil lists produce some surprising results + "bank/send_authorization/empty_coins": { + gogo: &banktypes.SendAuthorization{SpendLimit: []types.Coin{}}, + pulsar: &bankapi.SendAuthorization{SpendLimit: []*v1beta1.Coin{}}, + }, + "bank/send_authorization/nil_coins": { + gogo: &banktypes.SendAuthorization{SpendLimit: nil}, + pulsar: &bankapi.SendAuthorization{SpendLimit: nil}, + }, + "bank/send_authorization/empty_list": { + gogo: &banktypes.SendAuthorization{AllowList: []string{}}, + pulsar: &bankapi.SendAuthorization{AllowList: []string{}}, + }, + "bank/send_authorization/nil_list": { + gogo: &banktypes.SendAuthorization{AllowList: nil}, + pulsar: &bankapi.SendAuthorization{AllowList: nil}, + }, + "bank/msg_multi_send/nil_everything": { + gogo: &banktypes.MsgMultiSend{}, + pulsar: &bankapi.MsgMultiSend{}, + }, + "slashing/params/empty_dec": { + gogo: &slashingtypes.Params{DowntimeJailDuration: 1e9 + 7}, + pulsar: &slashingapi.Params{DowntimeJailDuration: &durationpb.Duration{Seconds: 1, Nanos: 7}}, + }, + // This test cases demonstrates the expected contract and proper way to set a cosmos.Dec field represented + // as bytes in protobuf message, namely: + // dec10bz, _ := types.NewDec(10).Marshal() + "slashing/params/dec": { + gogo: &slashingtypes.Params{ + DowntimeJailDuration: 1e9 + 7, + MinSignedPerWindow: types.NewDec(10)}, + pulsar: &slashingapi.Params{ + DowntimeJailDuration: &durationpb.Duration{Seconds: 1, Nanos: 7}, + MinSignedPerWindow: dec10bz, + }, + }, + "staking/create_validator": { + gogo: &stakingtypes.MsgCreateValidator{Pubkey: pubkeyAny}, + pulsar: &stakingapi.MsgCreateValidator{ + Pubkey: pubkeyAnyPulsar, + Description: &stakingapi.Description{}, + Commission: &stakingapi.CommissionRates{}, + Value: &v1beta1.Coin{}, + }, + }, + "staking/msg_cancel_unbonding_delegation_response": { + gogo: &stakingtypes.MsgCancelUnbondingDelegationResponse{}, + pulsar: &stakingapi.MsgCancelUnbondingDelegationResponse{}, + }, + "staking/stake_authorization_empty": { + gogo: &stakingtypes.StakeAuthorization{}, + pulsar: &stakingapi.StakeAuthorization{}, + }, + "staking/stake_authorization_allow": { + gogo: &stakingtypes.StakeAuthorization{ + Validators: &stakingtypes.StakeAuthorization_AllowList{ + AllowList: &stakingtypes.StakeAuthorization_Validators{Address: []string{"foo"}}, + }}, + pulsar: &stakingapi.StakeAuthorization{ + Validators: &stakingapi.StakeAuthorization_AllowList{ + AllowList: &stakingapi.StakeAuthorization_Validators{Address: []string{"foo"}}, + }}, + }, + "vesting/base_account_empty": { + gogo: &vestingtypes.BaseVestingAccount{BaseAccount: &authtypes.BaseAccount{}}, + pulsar: &vestingapi.BaseVestingAccount{BaseAccount: &authapi.BaseAccount{}}, + }, + "vesting/base_account_pubkey": { + gogo: &vestingtypes.BaseVestingAccount{BaseAccount: &authtypes.BaseAccount{PubKey: pubkeyAny}}, + pulsar: &vestingapi.BaseVestingAccount{BaseAccount: &authapi.BaseAccount{PubKey: pubkeyAnyPulsar}}, + }, + "math/int_as_string": { + gogo: &gogo_testpb.IntAsString{IntAsString: types.NewInt(123)}, + pulsar: &pulsar_testpb.IntAsString{IntAsString: "123"}, + }, + "math/int_as_string/empty": { + gogo: &gogo_testpb.IntAsString{}, + pulsar: &pulsar_testpb.IntAsString{}, + }, + "math/int_as_bytes": { + gogo: &gogo_testpb.IntAsBytes{IntAsBytes: types.NewInt(123)}, + pulsar: &pulsar_testpb.IntAsBytes{IntAsBytes: int123bz}, + }, + "math/int_as_bytes/empty": { + gogo: &gogo_testpb.IntAsBytes{}, + pulsar: &pulsar_testpb.IntAsBytes{}, + }, + } + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + gogoBytes, err := encCfg.Amino.MarshalJSON(tc.gogo) + require.NoError(t, err) + + pulsarBytes, err := aj.Marshal(tc.pulsar) + if tc.pulsarMarshalFails { + require.Error(t, err) + return + } + require.NoError(t, err) + + fmt.Printf("pulsar: %s\n", string(pulsarBytes)) + fmt.Printf(" gogo: %s\n", string(gogoBytes)) + require.Equal(t, string(gogoBytes), string(pulsarBytes)) + + pulsarProtoBytes, err := proto.Marshal(tc.pulsar) + require.NoError(t, err) + + gogoType := reflect.TypeOf(tc.gogo).Elem() + newGogo := reflect.New(gogoType).Interface().(gogoproto.Message) + + err = encCfg.Codec.Unmarshal(pulsarProtoBytes, newGogo) + if tc.protoUnmarshalFails { + require.Error(t, err) + return + } + require.NoError(t, err) + + newGogoBytes, err := encCfg.Amino.MarshalJSON(newGogo) + if tc.roundTripUnequal { + require.NotEqual(t, string(gogoBytes), string(newGogoBytes)) + return + } + require.Equal(t, string(gogoBytes), string(newGogoBytes)) + }) + } +} + +func TestSendAuthorization(t *testing.T) { + encCfg := testutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, authzmodule.AppModuleBasic{}, + distribution.AppModuleBasic{}, bank.AppModuleBasic{}) + + aj := aminojson.NewAminoJSON() + + // beware, Coins has as custom MarshalJSON method which changes how nil is handled + // nil -> [] (empty list) + // [] -> [] (empty list) + // https://github.com/cosmos/cosmos-sdk/blob/be9bd7a8c1b41b115d58f4e76ee358e18a52c0af/types/coin.go#L199 + + // explicitly show the default for clarity + pulsar := &bankapi.SendAuthorization{SpendLimit: []*v1beta1.Coin{}} + sanityPulsar := &bankapi.SendAuthorization{} + gogo := &banktypes.SendAuthorization{SpendLimit: types.Coins{}} + + protoBz, err := proto.Marshal(pulsar) + require.NoError(t, err) + + err = encCfg.Codec.Unmarshal(protoBz, gogo) + require.NoError(t, err) + + err = proto.Unmarshal(protoBz, sanityPulsar) + + // !!! + // empty []string is not the same as nil []string. this is a bug in gogo. + // `[]string` -> proto.Marshal -> legacyAmino.UnmarshalProto (unmarshals empty slice as nil) + // -> legacyAmino.MarshalJson -> `null` + // `[]string` -> [proto.Marshal -> pulsar.Unmarshal] -> amino.MarshalJson -> `[]` + require.Nil(t, gogo.SpendLimit) + require.Nil(t, sanityPulsar.SpendLimit) + require.NotNil(t, pulsar.SpendLimit) + require.Zero(t, len(pulsar.SpendLimit)) + + legacyAminoJson, err := encCfg.Amino.MarshalJSON(gogo) + aminoJson, err := aj.Marshal(sanityPulsar) + + require.Equal(t, string(legacyAminoJson), string(aminoJson)) + + aminoJson, err = aj.Marshal(pulsar) + require.NoError(t, err) + + // at this point, pulsar.SpendLimit = [], and gogo.SpendLimit = nil, but they will both marshal to `[]` + // this is *only* possible because of Cosmos SDK's custom MarshalJSON method for Coins + require.Equal(t, string(legacyAminoJson), string(aminoJson)) +} + +func postFixPulsarMessage(msg proto.Message) { + switch m := msg.(type) { + case *authapi.ModuleAccount: + if m.BaseAccount == nil { + m.BaseAccount = &authapi.BaseAccount{} + } + _, _, bz := testdata.KeyTestPubAddr() + // always set address to a valid bech32 address + text, _ := bech32.ConvertAndEncode("cosmos", bz) + m.BaseAccount.Address = text + + // see negative test + if len(m.Permissions) == 0 { + m.Permissions = nil + } + } +} diff --git a/tests/integration/aminojson/internal/Makefile b/tests/integration/aminojson/internal/Makefile new file mode 100644 index 000000000000..658d11adeaba --- /dev/null +++ b/tests/integration/aminojson/internal/Makefile @@ -0,0 +1,4 @@ +codegen: + @echo "Generating proto files" + buf --template buf.gen.gogo.yaml generate + buf --template buf.gen.pulsar.yaml generate diff --git a/tests/integration/aminojson/internal/buf.gen.gogo.yaml b/tests/integration/aminojson/internal/buf.gen.gogo.yaml new file mode 100644 index 000000000000..d1b5140d80ad --- /dev/null +++ b/tests/integration/aminojson/internal/buf.gen.gogo.yaml @@ -0,0 +1,8 @@ +version: v1 +plugins: + - name: gocosmos + out: ./gogo + opt: plugins=grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types + - name: grpc-gateway + out: ./gogo + opt: logtostderr=true,allow_colon_final_segments=true diff --git a/tests/integration/aminojson/internal/buf.gen.pulsar.yaml b/tests/integration/aminojson/internal/buf.gen.pulsar.yaml new file mode 100644 index 000000000000..aa687b9d0f4b --- /dev/null +++ b/tests/integration/aminojson/internal/buf.gen.pulsar.yaml @@ -0,0 +1,15 @@ +version: v1 +managed: + enabled: true + go_package_prefix: + default: github.com/cosmos/cosmos-sdk/tests/integration/aminojson/internal/testpb/pulsar + except: + - buf.build/googleapis/googleapis + - buf.build/cosmos/gogo-proto + - buf.build/cosmos/cosmos-proto + override: + buf.build/cosmos/cosmos-sdk: cosmossdk.io/api +plugins: + - name: go-pulsar + out: ./pulsar + opt: paths=source_relative diff --git a/tests/integration/aminojson/internal/buf.lock b/tests/integration/aminojson/internal/buf.lock new file mode 100644 index 000000000000..88709c98ef99 --- /dev/null +++ b/tests/integration/aminojson/internal/buf.lock @@ -0,0 +1,11 @@ +# Generated by buf. DO NOT EDIT. +version: v1 +deps: + - remote: buf.build + owner: cosmos + repository: cosmos-proto + commit: 1935555c206d4afb9e94615dfd0fad31 + - remote: buf.build + owner: cosmos + repository: gogo-proto + commit: 34d970b699f84aa382f3c29773a60836 diff --git a/tests/integration/aminojson/internal/buf.yaml b/tests/integration/aminojson/internal/buf.yaml new file mode 100644 index 000000000000..5aee45ac2b4f --- /dev/null +++ b/tests/integration/aminojson/internal/buf.yaml @@ -0,0 +1,12 @@ +version: v1 +deps: + - buf.build/cosmos/cosmos-proto + - buf.build/cosmos/gogo-proto +lint: + use: + - DEFAULT + except: + - PACKAGE_VERSION_SUFFIX +breaking: + ignore: + - testpb diff --git a/tests/integration/aminojson/internal/gogo/testpb/test.pb.go b/tests/integration/aminojson/internal/gogo/testpb/test.pb.go new file mode 100644 index 000000000000..4ed2ed504d53 --- /dev/null +++ b/tests/integration/aminojson/internal/gogo/testpb/test.pb.go @@ -0,0 +1,1600 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: testpb/test.proto + +package testpb + +import ( + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type Streng struct { + Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (m *Streng) Reset() { *m = Streng{} } +func (m *Streng) String() string { return proto.CompactTextString(m) } +func (*Streng) ProtoMessage() {} +func (*Streng) Descriptor() ([]byte, []int) { + return fileDescriptor_41c67e33ca9d1f26, []int{0} +} +func (m *Streng) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Streng) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Streng.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Streng) XXX_Merge(src proto.Message) { + xxx_messageInfo_Streng.Merge(m, src) +} +func (m *Streng) XXX_Size() int { + return m.Size() +} +func (m *Streng) XXX_DiscardUnknown() { + xxx_messageInfo_Streng.DiscardUnknown(m) +} + +var xxx_messageInfo_Streng proto.InternalMessageInfo + +func (m *Streng) GetValue() string { + if m != nil { + return m.Value + } + return "" +} + +type TestRepeatedFields struct { + NullableOmitempty []*Streng `protobuf:"bytes,1,rep,name=nullable_omitempty,json=nullableOmitempty,proto3" json:"nullable_omitempty,omitempty"` + // not supported for empty sets + // go-amino emits nothing but the protoreflect library emits a null + NullableDontOmitempty []*Streng `protobuf:"bytes,2,rep,name=nullable_dont_omitempty,json=nullableDontOmitempty,proto3" json:"nullable_dont_omitempty,omitempty"` + // not supported for empty sets + // go-amino emits a null but the protoreflect library emits nothing + NonNullableOmitempty []Streng `protobuf:"bytes,3,rep,name=non_nullable_omitempty,json=nonNullableOmitempty,proto3" json:"non_nullable_omitempty"` + NonNullableDontOmitempty []Streng `protobuf:"bytes,4,rep,name=non_nullable_dont_omitempty,json=nonNullableDontOmitempty,proto3" json:"non_nullable_dont_omitempty"` +} + +func (m *TestRepeatedFields) Reset() { *m = TestRepeatedFields{} } +func (m *TestRepeatedFields) String() string { return proto.CompactTextString(m) } +func (*TestRepeatedFields) ProtoMessage() {} +func (*TestRepeatedFields) Descriptor() ([]byte, []int) { + return fileDescriptor_41c67e33ca9d1f26, []int{1} +} +func (m *TestRepeatedFields) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TestRepeatedFields) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TestRepeatedFields.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *TestRepeatedFields) XXX_Merge(src proto.Message) { + xxx_messageInfo_TestRepeatedFields.Merge(m, src) +} +func (m *TestRepeatedFields) XXX_Size() int { + return m.Size() +} +func (m *TestRepeatedFields) XXX_DiscardUnknown() { + xxx_messageInfo_TestRepeatedFields.DiscardUnknown(m) +} + +var xxx_messageInfo_TestRepeatedFields proto.InternalMessageInfo + +func (m *TestRepeatedFields) GetNullableOmitempty() []*Streng { + if m != nil { + return m.NullableOmitempty + } + return nil +} + +func (m *TestRepeatedFields) GetNullableDontOmitempty() []*Streng { + if m != nil { + return m.NullableDontOmitempty + } + return nil +} + +func (m *TestRepeatedFields) GetNonNullableOmitempty() []Streng { + if m != nil { + return m.NonNullableOmitempty + } + return nil +} + +func (m *TestRepeatedFields) GetNonNullableDontOmitempty() []Streng { + if m != nil { + return m.NonNullableDontOmitempty + } + return nil +} + +type TestNullableFields struct { + NullableOmitempty *Streng `protobuf:"bytes,1,opt,name=nullable_omitempty,json=nullableOmitempty,proto3" json:"nullable_omitempty,omitempty"` + // not supported + // go-amino emits nothing and the protoreflect returns an error + // alternatively protoreflect could emit `{}` + NullableDontOmitempty *Streng `protobuf:"bytes,2,opt,name=nullable_dont_omitempty,json=nullableDontOmitempty,proto3" json:"nullable_dont_omitempty,omitempty"` + // not supported + // go-amino emits `{}` but the protoreflect library emits nothing + NonNullableOmitempty Streng `protobuf:"bytes,3,opt,name=non_nullable_omitempty,json=nonNullableOmitempty,proto3" json:"non_nullable_omitempty"` + NonNullableDontOmitempty Streng `protobuf:"bytes,4,opt,name=non_nullable_dont_omitempty,json=nonNullableDontOmitempty,proto3" json:"non_nullable_dont_omitempty"` +} + +func (m *TestNullableFields) Reset() { *m = TestNullableFields{} } +func (m *TestNullableFields) String() string { return proto.CompactTextString(m) } +func (*TestNullableFields) ProtoMessage() {} +func (*TestNullableFields) Descriptor() ([]byte, []int) { + return fileDescriptor_41c67e33ca9d1f26, []int{2} +} +func (m *TestNullableFields) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TestNullableFields) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TestNullableFields.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *TestNullableFields) XXX_Merge(src proto.Message) { + xxx_messageInfo_TestNullableFields.Merge(m, src) +} +func (m *TestNullableFields) XXX_Size() int { + return m.Size() +} +func (m *TestNullableFields) XXX_DiscardUnknown() { + xxx_messageInfo_TestNullableFields.DiscardUnknown(m) +} + +var xxx_messageInfo_TestNullableFields proto.InternalMessageInfo + +func (m *TestNullableFields) GetNullableOmitempty() *Streng { + if m != nil { + return m.NullableOmitempty + } + return nil +} + +func (m *TestNullableFields) GetNullableDontOmitempty() *Streng { + if m != nil { + return m.NullableDontOmitempty + } + return nil +} + +func (m *TestNullableFields) GetNonNullableOmitempty() Streng { + if m != nil { + return m.NonNullableOmitempty + } + return Streng{} +} + +func (m *TestNullableFields) GetNonNullableDontOmitempty() Streng { + if m != nil { + return m.NonNullableDontOmitempty + } + return Streng{} +} + +type IntAsString struct { + IntAsString github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=int_as_string,json=intAsString,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"int_as_string"` +} + +func (m *IntAsString) Reset() { *m = IntAsString{} } +func (m *IntAsString) String() string { return proto.CompactTextString(m) } +func (*IntAsString) ProtoMessage() {} +func (*IntAsString) Descriptor() ([]byte, []int) { + return fileDescriptor_41c67e33ca9d1f26, []int{3} +} +func (m *IntAsString) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *IntAsString) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_IntAsString.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *IntAsString) XXX_Merge(src proto.Message) { + xxx_messageInfo_IntAsString.Merge(m, src) +} +func (m *IntAsString) XXX_Size() int { + return m.Size() +} +func (m *IntAsString) XXX_DiscardUnknown() { + xxx_messageInfo_IntAsString.DiscardUnknown(m) +} + +var xxx_messageInfo_IntAsString proto.InternalMessageInfo + +type IntAsBytes struct { + IntAsBytes github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=int_as_bytes,json=intAsBytes,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"int_as_bytes"` +} + +func (m *IntAsBytes) Reset() { *m = IntAsBytes{} } +func (m *IntAsBytes) String() string { return proto.CompactTextString(m) } +func (*IntAsBytes) ProtoMessage() {} +func (*IntAsBytes) Descriptor() ([]byte, []int) { + return fileDescriptor_41c67e33ca9d1f26, []int{4} +} +func (m *IntAsBytes) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *IntAsBytes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_IntAsBytes.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *IntAsBytes) XXX_Merge(src proto.Message) { + xxx_messageInfo_IntAsBytes.Merge(m, src) +} +func (m *IntAsBytes) XXX_Size() int { + return m.Size() +} +func (m *IntAsBytes) XXX_DiscardUnknown() { + xxx_messageInfo_IntAsBytes.DiscardUnknown(m) +} + +var xxx_messageInfo_IntAsBytes proto.InternalMessageInfo + +type IntAsBothStringAndBytes struct { + IntAsString github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=int_as_string,json=intAsString,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"int_as_string"` + IntAsBytes github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=int_as_bytes,json=intAsBytes,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"int_as_bytes"` +} + +func (m *IntAsBothStringAndBytes) Reset() { *m = IntAsBothStringAndBytes{} } +func (m *IntAsBothStringAndBytes) String() string { return proto.CompactTextString(m) } +func (*IntAsBothStringAndBytes) ProtoMessage() {} +func (*IntAsBothStringAndBytes) Descriptor() ([]byte, []int) { + return fileDescriptor_41c67e33ca9d1f26, []int{5} +} +func (m *IntAsBothStringAndBytes) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *IntAsBothStringAndBytes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_IntAsBothStringAndBytes.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *IntAsBothStringAndBytes) XXX_Merge(src proto.Message) { + xxx_messageInfo_IntAsBothStringAndBytes.Merge(m, src) +} +func (m *IntAsBothStringAndBytes) XXX_Size() int { + return m.Size() +} +func (m *IntAsBothStringAndBytes) XXX_DiscardUnknown() { + xxx_messageInfo_IntAsBothStringAndBytes.DiscardUnknown(m) +} + +var xxx_messageInfo_IntAsBothStringAndBytes proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Streng)(nil), "testpb.streng") + proto.RegisterType((*TestRepeatedFields)(nil), "testpb.TestRepeatedFields") + proto.RegisterType((*TestNullableFields)(nil), "testpb.TestNullableFields") + proto.RegisterType((*IntAsString)(nil), "testpb.IntAsString") + proto.RegisterType((*IntAsBytes)(nil), "testpb.IntAsBytes") + proto.RegisterType((*IntAsBothStringAndBytes)(nil), "testpb.IntAsBothStringAndBytes") +} + +func init() { proto.RegisterFile("testpb/test.proto", fileDescriptor_41c67e33ca9d1f26) } + +var fileDescriptor_41c67e33ca9d1f26 = []byte{ + // 445 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x54, 0x4d, 0x8b, 0xd3, 0x40, + 0x18, 0xce, 0x74, 0x77, 0x0b, 0xfb, 0x76, 0x15, 0x3a, 0x54, 0x37, 0xae, 0x90, 0x5d, 0x72, 0x90, + 0x45, 0xd8, 0x04, 0xf4, 0xec, 0xa1, 0x41, 0x84, 0x0a, 0x2a, 0x44, 0x0f, 0xde, 0x42, 0xd2, 0x0c, + 0xd9, 0xc1, 0x64, 0x26, 0x76, 0xde, 0x0a, 0xfd, 0x17, 0xfe, 0x0c, 0x8f, 0x1e, 0xfc, 0x11, 0x3d, + 0x2e, 0x9e, 0xc4, 0xc3, 0x22, 0x2d, 0xe2, 0xdf, 0x90, 0x64, 0x92, 0x7e, 0xd8, 0x80, 0x20, 0x71, + 0x2f, 0x99, 0xbc, 0x1f, 0xf3, 0x3c, 0xcf, 0xfb, 0xf0, 0x26, 0xd0, 0x47, 0xa6, 0x30, 0x8f, 0xdc, + 0xe2, 0x70, 0xf2, 0x89, 0x44, 0x49, 0xbb, 0x3a, 0x75, 0x32, 0x48, 0x64, 0x22, 0xcb, 0x94, 0x5b, + 0xbc, 0xe9, 0xea, 0x49, 0x3f, 0xcc, 0xb8, 0x90, 0x6e, 0xf9, 0xac, 0x52, 0xf7, 0xc6, 0x52, 0x65, + 0x52, 0x05, 0xba, 0x57, 0x07, 0xba, 0x64, 0x5b, 0xd0, 0x55, 0x38, 0x61, 0x22, 0xa1, 0x03, 0x38, + 0xf8, 0x10, 0xa6, 0x53, 0x66, 0x92, 0x33, 0x72, 0x7e, 0xe8, 0xeb, 0xc0, 0x9e, 0x77, 0x80, 0xbe, + 0x61, 0x0a, 0x7d, 0x96, 0xb3, 0x10, 0x59, 0xfc, 0x8c, 0xb3, 0x34, 0x56, 0xf4, 0x09, 0x50, 0x31, + 0x4d, 0xd3, 0x30, 0x4a, 0x59, 0x20, 0x33, 0x8e, 0x2c, 0xcb, 0x71, 0x66, 0x92, 0xb3, 0xbd, 0xf3, + 0xde, 0xa3, 0xdb, 0x8e, 0xd6, 0xe7, 0x68, 0x60, 0xbf, 0x5f, 0x77, 0xbe, 0xaa, 0x1b, 0xe9, 0x0b, + 0x38, 0x5e, 0x5d, 0x8f, 0xa5, 0xc0, 0x0d, 0x8c, 0x4e, 0x13, 0x86, 0x77, 0xf0, 0xe9, 0xd7, 0xe7, + 0x87, 0xc4, 0xbf, 0x53, 0xdf, 0x7a, 0x2a, 0x05, 0xae, 0xe1, 0x9e, 0xc3, 0x5d, 0x21, 0x45, 0xd0, + 0xa0, 0x68, 0xaf, 0x11, 0x6d, 0x7f, 0x7e, 0x7d, 0x6a, 0xf8, 0x03, 0x21, 0xc5, 0xcb, 0x1d, 0x69, + 0x6f, 0xe1, 0xfe, 0x16, 0xd6, 0x1f, 0xf2, 0xf6, 0x1b, 0x01, 0x0f, 0x0b, 0x40, 0x2d, 0xd1, 0xdc, + 0x40, 0xdd, 0x52, 0xb9, 0xb2, 0xb2, 0xae, 0xfe, 0xc5, 0x4a, 0xd2, 0x82, 0x95, 0xa4, 0x55, 0x2b, + 0x49, 0xdb, 0x56, 0x92, 0x7f, 0xb5, 0x12, 0xa1, 0x37, 0x12, 0x38, 0x54, 0xaf, 0x71, 0xc2, 0x45, + 0x42, 0x19, 0xdc, 0xe2, 0x02, 0x83, 0x50, 0x05, 0xaa, 0x4c, 0xe8, 0x15, 0xf6, 0x86, 0x05, 0xd4, + 0xf7, 0xeb, 0xd3, 0x07, 0x09, 0xc7, 0xcb, 0x69, 0xe4, 0x8c, 0x65, 0x56, 0x2d, 0x7f, 0x75, 0x5c, + 0xa8, 0xf8, 0x9d, 0x8b, 0xb3, 0x9c, 0x29, 0x67, 0x24, 0xf0, 0xeb, 0x97, 0x0b, 0xa8, 0xbe, 0x8d, + 0x91, 0x40, 0x2d, 0xa1, 0xc7, 0xd7, 0x34, 0xf6, 0x7b, 0x80, 0x92, 0xd5, 0x9b, 0x21, 0x53, 0x74, + 0x0c, 0x47, 0x15, 0x69, 0x54, 0xc4, 0x25, 0xe7, 0x51, 0x1b, 0x9c, 0xc0, 0x57, 0x24, 0xf6, 0x4f, + 0x02, 0xc7, 0x9a, 0x53, 0xe2, 0xa5, 0x96, 0x31, 0x14, 0xb1, 0x16, 0x70, 0x33, 0x53, 0xef, 0xcc, + 0xd9, 0xf9, 0x0f, 0x73, 0x7a, 0xe6, 0x7c, 0x61, 0x91, 0xab, 0x85, 0x45, 0x7e, 0x2c, 0x2c, 0xf2, + 0x71, 0x69, 0x19, 0x57, 0x4b, 0xcb, 0xf8, 0xb6, 0xb4, 0x8c, 0xa8, 0x5b, 0xfe, 0xa7, 0x1e, 0xff, + 0x0e, 0x00, 0x00, 0xff, 0xff, 0xdd, 0xa4, 0x3a, 0xad, 0x08, 0x05, 0x00, 0x00, +} + +func (m *Streng) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Streng) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Streng) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Value) > 0 { + i -= len(m.Value) + copy(dAtA[i:], m.Value) + i = encodeVarintTest(dAtA, i, uint64(len(m.Value))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *TestRepeatedFields) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TestRepeatedFields) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TestRepeatedFields) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.NonNullableDontOmitempty) > 0 { + for iNdEx := len(m.NonNullableDontOmitempty) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.NonNullableDontOmitempty[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + if len(m.NonNullableOmitempty) > 0 { + for iNdEx := len(m.NonNullableOmitempty) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.NonNullableOmitempty[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.NullableDontOmitempty) > 0 { + for iNdEx := len(m.NullableDontOmitempty) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.NullableDontOmitempty[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.NullableOmitempty) > 0 { + for iNdEx := len(m.NullableOmitempty) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.NullableOmitempty[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *TestNullableFields) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TestNullableFields) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TestNullableFields) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.NonNullableDontOmitempty.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + size, err := m.NonNullableOmitempty.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if m.NullableDontOmitempty != nil { + { + size, err := m.NullableDontOmitempty.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if m.NullableOmitempty != nil { + { + size, err := m.NullableOmitempty.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *IntAsString) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *IntAsString) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *IntAsString) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.IntAsString.Size() + i -= size + if _, err := m.IntAsString.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *IntAsBytes) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *IntAsBytes) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *IntAsBytes) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.IntAsBytes.Size() + i -= size + if _, err := m.IntAsBytes.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *IntAsBothStringAndBytes) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *IntAsBothStringAndBytes) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *IntAsBothStringAndBytes) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.IntAsBytes.Size() + i -= size + if _, err := m.IntAsBytes.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size := m.IntAsString.Size() + i -= size + if _, err := m.IntAsString.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTest(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintTest(dAtA []byte, offset int, v uint64) int { + offset -= sovTest(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Streng) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Value) + if l > 0 { + n += 1 + l + sovTest(uint64(l)) + } + return n +} + +func (m *TestRepeatedFields) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.NullableOmitempty) > 0 { + for _, e := range m.NullableOmitempty { + l = e.Size() + n += 1 + l + sovTest(uint64(l)) + } + } + if len(m.NullableDontOmitempty) > 0 { + for _, e := range m.NullableDontOmitempty { + l = e.Size() + n += 1 + l + sovTest(uint64(l)) + } + } + if len(m.NonNullableOmitempty) > 0 { + for _, e := range m.NonNullableOmitempty { + l = e.Size() + n += 1 + l + sovTest(uint64(l)) + } + } + if len(m.NonNullableDontOmitempty) > 0 { + for _, e := range m.NonNullableDontOmitempty { + l = e.Size() + n += 1 + l + sovTest(uint64(l)) + } + } + return n +} + +func (m *TestNullableFields) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.NullableOmitempty != nil { + l = m.NullableOmitempty.Size() + n += 1 + l + sovTest(uint64(l)) + } + if m.NullableDontOmitempty != nil { + l = m.NullableDontOmitempty.Size() + n += 1 + l + sovTest(uint64(l)) + } + l = m.NonNullableOmitempty.Size() + n += 1 + l + sovTest(uint64(l)) + l = m.NonNullableDontOmitempty.Size() + n += 1 + l + sovTest(uint64(l)) + return n +} + +func (m *IntAsString) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.IntAsString.Size() + n += 1 + l + sovTest(uint64(l)) + return n +} + +func (m *IntAsBytes) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.IntAsBytes.Size() + n += 1 + l + sovTest(uint64(l)) + return n +} + +func (m *IntAsBothStringAndBytes) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.IntAsString.Size() + n += 1 + l + sovTest(uint64(l)) + l = m.IntAsBytes.Size() + n += 1 + l + sovTest(uint64(l)) + return n +} + +func sovTest(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTest(x uint64) (n int) { + return sovTest(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Streng) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: streng: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: streng: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Value = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TestRepeatedFields) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: TestRepeatedFields: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TestRepeatedFields: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NullableOmitempty", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NullableOmitempty = append(m.NullableOmitempty, &Streng{}) + if err := m.NullableOmitempty[len(m.NullableOmitempty)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NullableDontOmitempty", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NullableDontOmitempty = append(m.NullableDontOmitempty, &Streng{}) + if err := m.NullableDontOmitempty[len(m.NullableDontOmitempty)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NonNullableOmitempty", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NonNullableOmitempty = append(m.NonNullableOmitempty, Streng{}) + if err := m.NonNullableOmitempty[len(m.NonNullableOmitempty)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NonNullableDontOmitempty", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.NonNullableDontOmitempty = append(m.NonNullableDontOmitempty, Streng{}) + if err := m.NonNullableDontOmitempty[len(m.NonNullableDontOmitempty)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TestNullableFields) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: TestNullableFields: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TestNullableFields: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NullableOmitempty", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.NullableOmitempty == nil { + m.NullableOmitempty = &Streng{} + } + if err := m.NullableOmitempty.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NullableDontOmitempty", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.NullableDontOmitempty == nil { + m.NullableDontOmitempty = &Streng{} + } + if err := m.NullableDontOmitempty.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NonNullableOmitempty", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.NonNullableOmitempty.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NonNullableDontOmitempty", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.NonNullableDontOmitempty.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *IntAsString) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: IntAsString: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IntAsString: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IntAsString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.IntAsString.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *IntAsBytes) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: IntAsBytes: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IntAsBytes: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IntAsBytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.IntAsBytes.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *IntAsBothStringAndBytes) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return 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 fmt.Errorf("proto: IntAsBothStringAndBytes: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: IntAsBothStringAndBytes: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IntAsString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.IntAsString.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IntAsBytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTest + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.IntAsBytes.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTest(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTest + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTest + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTest + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTest + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTest + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTest + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTest = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTest = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTest = fmt.Errorf("proto: unexpected end of group") +) diff --git a/tests/integration/aminojson/internal/pulsar/testpb/test.pulsar.go b/tests/integration/aminojson/internal/pulsar/testpb/test.pulsar.go new file mode 100644 index 000000000000..dd3158b93eae --- /dev/null +++ b/tests/integration/aminojson/internal/pulsar/testpb/test.pulsar.go @@ -0,0 +1,3863 @@ +// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. +package testpb + +import ( + _ "cosmossdk.io/api/amino" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + runtime "github.com/cosmos/cosmos-proto/runtime" + _ "github.com/cosmos/gogoproto/gogoproto" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoiface "google.golang.org/protobuf/runtime/protoiface" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + io "io" + reflect "reflect" + sync "sync" +) + +var ( + md_Streng protoreflect.MessageDescriptor + fd_Streng_value protoreflect.FieldDescriptor +) + +func init() { + file_testpb_test_proto_init() + md_Streng = File_testpb_test_proto.Messages().ByName("streng") + fd_Streng_value = md_Streng.Fields().ByName("value") +} + +var _ protoreflect.Message = (*fastReflection_Streng)(nil) + +type fastReflection_Streng Streng + +func (x *Streng) ProtoReflect() protoreflect.Message { + return (*fastReflection_Streng)(x) +} + +func (x *Streng) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_test_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) +} + +var _fastReflection_Streng_messageType fastReflection_Streng_messageType +var _ protoreflect.MessageType = fastReflection_Streng_messageType{} + +type fastReflection_Streng_messageType struct{} + +func (x fastReflection_Streng_messageType) Zero() protoreflect.Message { + return (*fastReflection_Streng)(nil) +} +func (x fastReflection_Streng_messageType) New() protoreflect.Message { + return new(fastReflection_Streng) +} +func (x fastReflection_Streng_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_Streng +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_Streng) Descriptor() protoreflect.MessageDescriptor { + return md_Streng +} + +// 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_Streng) Type() protoreflect.MessageType { + return _fastReflection_Streng_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_Streng) New() protoreflect.Message { + return new(fastReflection_Streng) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_Streng) Interface() protoreflect.ProtoMessage { + return (*Streng)(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_Streng) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Value != "" { + value := protoreflect.ValueOfString(x.Value) + if !f(fd_Streng_value, 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_Streng) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.streng.value": + return x.Value != "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.streng")) + } + panic(fmt.Errorf("message testpb.streng 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_Streng) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.streng.value": + x.Value = "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.streng")) + } + panic(fmt.Errorf("message testpb.streng 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_Streng) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.streng.value": + value := x.Value + return protoreflect.ValueOfString(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.streng")) + } + panic(fmt.Errorf("message testpb.streng 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_Streng) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.streng.value": + x.Value = value.Interface().(string) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.streng")) + } + panic(fmt.Errorf("message testpb.streng 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_Streng) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.streng.value": + panic(fmt.Errorf("field value of message testpb.streng is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.streng")) + } + panic(fmt.Errorf("message testpb.streng 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_Streng) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.streng.value": + return protoreflect.ValueOfString("") + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.streng")) + } + panic(fmt.Errorf("message testpb.streng 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_Streng) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.streng", 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_Streng) 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_Streng) 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_Streng) 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_Streng) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*Streng) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.Value) + if l > 0 { + 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().(*Streng) + 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 len(x.Value) > 0 { + i -= len(x.Value) + copy(dAtA[i:], x.Value) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Value))) + i-- + dAtA[i] = 0xa + } + 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().(*Streng) + 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: Streng: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: Streng: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Value", 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.Value = string(dAtA[iNdEx:postIndex]) + 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, + } +} + +var _ protoreflect.List = (*_TestRepeatedFields_1_list)(nil) + +type _TestRepeatedFields_1_list struct { + list *[]*Streng +} + +func (x *_TestRepeatedFields_1_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_TestRepeatedFields_1_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *_TestRepeatedFields_1_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*Streng) + (*x.list)[i] = concreteValue +} + +func (x *_TestRepeatedFields_1_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*Streng) + *x.list = append(*x.list, concreteValue) +} + +func (x *_TestRepeatedFields_1_list) AppendMutable() protoreflect.Value { + v := new(Streng) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_TestRepeatedFields_1_list) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = nil + } + *x.list = (*x.list)[:n] +} + +func (x *_TestRepeatedFields_1_list) NewElement() protoreflect.Value { + v := new(Streng) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_TestRepeatedFields_1_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_TestRepeatedFields_2_list)(nil) + +type _TestRepeatedFields_2_list struct { + list *[]*Streng +} + +func (x *_TestRepeatedFields_2_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_TestRepeatedFields_2_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *_TestRepeatedFields_2_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*Streng) + (*x.list)[i] = concreteValue +} + +func (x *_TestRepeatedFields_2_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*Streng) + *x.list = append(*x.list, concreteValue) +} + +func (x *_TestRepeatedFields_2_list) AppendMutable() protoreflect.Value { + v := new(Streng) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_TestRepeatedFields_2_list) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = nil + } + *x.list = (*x.list)[:n] +} + +func (x *_TestRepeatedFields_2_list) NewElement() protoreflect.Value { + v := new(Streng) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_TestRepeatedFields_2_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_TestRepeatedFields_3_list)(nil) + +type _TestRepeatedFields_3_list struct { + list *[]*Streng +} + +func (x *_TestRepeatedFields_3_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_TestRepeatedFields_3_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *_TestRepeatedFields_3_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*Streng) + (*x.list)[i] = concreteValue +} + +func (x *_TestRepeatedFields_3_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*Streng) + *x.list = append(*x.list, concreteValue) +} + +func (x *_TestRepeatedFields_3_list) AppendMutable() protoreflect.Value { + v := new(Streng) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_TestRepeatedFields_3_list) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = nil + } + *x.list = (*x.list)[:n] +} + +func (x *_TestRepeatedFields_3_list) NewElement() protoreflect.Value { + v := new(Streng) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_TestRepeatedFields_3_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_TestRepeatedFields_4_list)(nil) + +type _TestRepeatedFields_4_list struct { + list *[]*Streng +} + +func (x *_TestRepeatedFields_4_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_TestRepeatedFields_4_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfMessage((*x.list)[i].ProtoReflect()) +} + +func (x *_TestRepeatedFields_4_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*Streng) + (*x.list)[i] = concreteValue +} + +func (x *_TestRepeatedFields_4_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Message() + concreteValue := valueUnwrapped.Interface().(*Streng) + *x.list = append(*x.list, concreteValue) +} + +func (x *_TestRepeatedFields_4_list) AppendMutable() protoreflect.Value { + v := new(Streng) + *x.list = append(*x.list, v) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_TestRepeatedFields_4_list) Truncate(n int) { + for i := n; i < len(*x.list); i++ { + (*x.list)[i] = nil + } + *x.list = (*x.list)[:n] +} + +func (x *_TestRepeatedFields_4_list) NewElement() protoreflect.Value { + v := new(Streng) + return protoreflect.ValueOfMessage(v.ProtoReflect()) +} + +func (x *_TestRepeatedFields_4_list) IsValid() bool { + return x.list != nil +} + +var ( + md_TestRepeatedFields protoreflect.MessageDescriptor + fd_TestRepeatedFields_nullable_omitempty protoreflect.FieldDescriptor + fd_TestRepeatedFields_nullable_dont_omitempty protoreflect.FieldDescriptor + fd_TestRepeatedFields_non_nullable_omitempty protoreflect.FieldDescriptor + fd_TestRepeatedFields_non_nullable_dont_omitempty protoreflect.FieldDescriptor +) + +func init() { + file_testpb_test_proto_init() + md_TestRepeatedFields = File_testpb_test_proto.Messages().ByName("TestRepeatedFields") + fd_TestRepeatedFields_nullable_omitempty = md_TestRepeatedFields.Fields().ByName("nullable_omitempty") + fd_TestRepeatedFields_nullable_dont_omitempty = md_TestRepeatedFields.Fields().ByName("nullable_dont_omitempty") + fd_TestRepeatedFields_non_nullable_omitempty = md_TestRepeatedFields.Fields().ByName("non_nullable_omitempty") + fd_TestRepeatedFields_non_nullable_dont_omitempty = md_TestRepeatedFields.Fields().ByName("non_nullable_dont_omitempty") +} + +var _ protoreflect.Message = (*fastReflection_TestRepeatedFields)(nil) + +type fastReflection_TestRepeatedFields TestRepeatedFields + +func (x *TestRepeatedFields) ProtoReflect() protoreflect.Message { + return (*fastReflection_TestRepeatedFields)(x) +} + +func (x *TestRepeatedFields) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_test_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) +} + +var _fastReflection_TestRepeatedFields_messageType fastReflection_TestRepeatedFields_messageType +var _ protoreflect.MessageType = fastReflection_TestRepeatedFields_messageType{} + +type fastReflection_TestRepeatedFields_messageType struct{} + +func (x fastReflection_TestRepeatedFields_messageType) Zero() protoreflect.Message { + return (*fastReflection_TestRepeatedFields)(nil) +} +func (x fastReflection_TestRepeatedFields_messageType) New() protoreflect.Message { + return new(fastReflection_TestRepeatedFields) +} +func (x fastReflection_TestRepeatedFields_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_TestRepeatedFields +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_TestRepeatedFields) Descriptor() protoreflect.MessageDescriptor { + return md_TestRepeatedFields +} + +// 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_TestRepeatedFields) Type() protoreflect.MessageType { + return _fastReflection_TestRepeatedFields_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_TestRepeatedFields) New() protoreflect.Message { + return new(fastReflection_TestRepeatedFields) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_TestRepeatedFields) Interface() protoreflect.ProtoMessage { + return (*TestRepeatedFields)(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_TestRepeatedFields) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if len(x.NullableOmitempty) != 0 { + value := protoreflect.ValueOfList(&_TestRepeatedFields_1_list{list: &x.NullableOmitempty}) + if !f(fd_TestRepeatedFields_nullable_omitempty, value) { + return + } + } + if len(x.NullableDontOmitempty) != 0 { + value := protoreflect.ValueOfList(&_TestRepeatedFields_2_list{list: &x.NullableDontOmitempty}) + if !f(fd_TestRepeatedFields_nullable_dont_omitempty, value) { + return + } + } + if len(x.NonNullableOmitempty) != 0 { + value := protoreflect.ValueOfList(&_TestRepeatedFields_3_list{list: &x.NonNullableOmitempty}) + if !f(fd_TestRepeatedFields_non_nullable_omitempty, value) { + return + } + } + if len(x.NonNullableDontOmitempty) != 0 { + value := protoreflect.ValueOfList(&_TestRepeatedFields_4_list{list: &x.NonNullableDontOmitempty}) + if !f(fd_TestRepeatedFields_non_nullable_dont_omitempty, 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_TestRepeatedFields) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.TestRepeatedFields.nullable_omitempty": + return len(x.NullableOmitempty) != 0 + case "testpb.TestRepeatedFields.nullable_dont_omitempty": + return len(x.NullableDontOmitempty) != 0 + case "testpb.TestRepeatedFields.non_nullable_omitempty": + return len(x.NonNullableOmitempty) != 0 + case "testpb.TestRepeatedFields.non_nullable_dont_omitempty": + return len(x.NonNullableDontOmitempty) != 0 + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestRepeatedFields")) + } + panic(fmt.Errorf("message testpb.TestRepeatedFields 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_TestRepeatedFields) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.TestRepeatedFields.nullable_omitempty": + x.NullableOmitempty = nil + case "testpb.TestRepeatedFields.nullable_dont_omitempty": + x.NullableDontOmitempty = nil + case "testpb.TestRepeatedFields.non_nullable_omitempty": + x.NonNullableOmitempty = nil + case "testpb.TestRepeatedFields.non_nullable_dont_omitempty": + x.NonNullableDontOmitempty = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestRepeatedFields")) + } + panic(fmt.Errorf("message testpb.TestRepeatedFields 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_TestRepeatedFields) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.TestRepeatedFields.nullable_omitempty": + if len(x.NullableOmitempty) == 0 { + return protoreflect.ValueOfList(&_TestRepeatedFields_1_list{}) + } + listValue := &_TestRepeatedFields_1_list{list: &x.NullableOmitempty} + return protoreflect.ValueOfList(listValue) + case "testpb.TestRepeatedFields.nullable_dont_omitempty": + if len(x.NullableDontOmitempty) == 0 { + return protoreflect.ValueOfList(&_TestRepeatedFields_2_list{}) + } + listValue := &_TestRepeatedFields_2_list{list: &x.NullableDontOmitempty} + return protoreflect.ValueOfList(listValue) + case "testpb.TestRepeatedFields.non_nullable_omitempty": + if len(x.NonNullableOmitempty) == 0 { + return protoreflect.ValueOfList(&_TestRepeatedFields_3_list{}) + } + listValue := &_TestRepeatedFields_3_list{list: &x.NonNullableOmitempty} + return protoreflect.ValueOfList(listValue) + case "testpb.TestRepeatedFields.non_nullable_dont_omitempty": + if len(x.NonNullableDontOmitempty) == 0 { + return protoreflect.ValueOfList(&_TestRepeatedFields_4_list{}) + } + listValue := &_TestRepeatedFields_4_list{list: &x.NonNullableDontOmitempty} + return protoreflect.ValueOfList(listValue) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestRepeatedFields")) + } + panic(fmt.Errorf("message testpb.TestRepeatedFields 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_TestRepeatedFields) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.TestRepeatedFields.nullable_omitempty": + lv := value.List() + clv := lv.(*_TestRepeatedFields_1_list) + x.NullableOmitempty = *clv.list + case "testpb.TestRepeatedFields.nullable_dont_omitempty": + lv := value.List() + clv := lv.(*_TestRepeatedFields_2_list) + x.NullableDontOmitempty = *clv.list + case "testpb.TestRepeatedFields.non_nullable_omitempty": + lv := value.List() + clv := lv.(*_TestRepeatedFields_3_list) + x.NonNullableOmitempty = *clv.list + case "testpb.TestRepeatedFields.non_nullable_dont_omitempty": + lv := value.List() + clv := lv.(*_TestRepeatedFields_4_list) + x.NonNullableDontOmitempty = *clv.list + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestRepeatedFields")) + } + panic(fmt.Errorf("message testpb.TestRepeatedFields 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_TestRepeatedFields) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.TestRepeatedFields.nullable_omitempty": + if x.NullableOmitempty == nil { + x.NullableOmitempty = []*Streng{} + } + value := &_TestRepeatedFields_1_list{list: &x.NullableOmitempty} + return protoreflect.ValueOfList(value) + case "testpb.TestRepeatedFields.nullable_dont_omitempty": + if x.NullableDontOmitempty == nil { + x.NullableDontOmitempty = []*Streng{} + } + value := &_TestRepeatedFields_2_list{list: &x.NullableDontOmitempty} + return protoreflect.ValueOfList(value) + case "testpb.TestRepeatedFields.non_nullable_omitempty": + if x.NonNullableOmitempty == nil { + x.NonNullableOmitempty = []*Streng{} + } + value := &_TestRepeatedFields_3_list{list: &x.NonNullableOmitempty} + return protoreflect.ValueOfList(value) + case "testpb.TestRepeatedFields.non_nullable_dont_omitempty": + if x.NonNullableDontOmitempty == nil { + x.NonNullableDontOmitempty = []*Streng{} + } + value := &_TestRepeatedFields_4_list{list: &x.NonNullableDontOmitempty} + return protoreflect.ValueOfList(value) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestRepeatedFields")) + } + panic(fmt.Errorf("message testpb.TestRepeatedFields 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_TestRepeatedFields) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.TestRepeatedFields.nullable_omitempty": + list := []*Streng{} + return protoreflect.ValueOfList(&_TestRepeatedFields_1_list{list: &list}) + case "testpb.TestRepeatedFields.nullable_dont_omitempty": + list := []*Streng{} + return protoreflect.ValueOfList(&_TestRepeatedFields_2_list{list: &list}) + case "testpb.TestRepeatedFields.non_nullable_omitempty": + list := []*Streng{} + return protoreflect.ValueOfList(&_TestRepeatedFields_3_list{list: &list}) + case "testpb.TestRepeatedFields.non_nullable_dont_omitempty": + list := []*Streng{} + return protoreflect.ValueOfList(&_TestRepeatedFields_4_list{list: &list}) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestRepeatedFields")) + } + panic(fmt.Errorf("message testpb.TestRepeatedFields 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_TestRepeatedFields) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.TestRepeatedFields", 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_TestRepeatedFields) 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_TestRepeatedFields) 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_TestRepeatedFields) 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_TestRepeatedFields) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*TestRepeatedFields) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if len(x.NullableOmitempty) > 0 { + for _, e := range x.NullableOmitempty { + l = options.Size(e) + n += 1 + l + runtime.Sov(uint64(l)) + } + } + if len(x.NullableDontOmitempty) > 0 { + for _, e := range x.NullableDontOmitempty { + l = options.Size(e) + n += 1 + l + runtime.Sov(uint64(l)) + } + } + if len(x.NonNullableOmitempty) > 0 { + for _, e := range x.NonNullableOmitempty { + l = options.Size(e) + n += 1 + l + runtime.Sov(uint64(l)) + } + } + if len(x.NonNullableDontOmitempty) > 0 { + for _, e := range x.NonNullableDontOmitempty { + l = options.Size(e) + 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().(*TestRepeatedFields) + 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 len(x.NonNullableDontOmitempty) > 0 { + for iNdEx := len(x.NonNullableDontOmitempty) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.NonNullableDontOmitempty[iNdEx]) + 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] = 0x22 + } + } + if len(x.NonNullableOmitempty) > 0 { + for iNdEx := len(x.NonNullableOmitempty) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.NonNullableOmitempty[iNdEx]) + 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.NullableDontOmitempty) > 0 { + for iNdEx := len(x.NullableDontOmitempty) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.NullableDontOmitempty[iNdEx]) + 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] = 0x12 + } + } + if len(x.NullableOmitempty) > 0 { + for iNdEx := len(x.NullableOmitempty) - 1; iNdEx >= 0; iNdEx-- { + encoded, err := options.Marshal(x.NullableOmitempty[iNdEx]) + 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] = 0xa + } + } + 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().(*TestRepeatedFields) + 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: TestRepeatedFields: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: TestRepeatedFields: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field NullableOmitempty", 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 + } + x.NullableOmitempty = append(x.NullableOmitempty, &Streng{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.NullableOmitempty[len(x.NullableOmitempty)-1]); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field NullableDontOmitempty", 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 + } + x.NullableDontOmitempty = append(x.NullableDontOmitempty, &Streng{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.NullableDontOmitempty[len(x.NullableDontOmitempty)-1]); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field NonNullableOmitempty", 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 + } + x.NonNullableOmitempty = append(x.NonNullableOmitempty, &Streng{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.NonNullableOmitempty[len(x.NonNullableOmitempty)-1]); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field NonNullableDontOmitempty", 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 + } + x.NonNullableDontOmitempty = append(x.NonNullableDontOmitempty, &Streng{}) + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.NonNullableDontOmitempty[len(x.NonNullableDontOmitempty)-1]); 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, + } +} + +var ( + md_TestNullableFields protoreflect.MessageDescriptor + fd_TestNullableFields_nullable_omitempty protoreflect.FieldDescriptor + fd_TestNullableFields_nullable_dont_omitempty protoreflect.FieldDescriptor + fd_TestNullableFields_non_nullable_omitempty protoreflect.FieldDescriptor + fd_TestNullableFields_non_nullable_dont_omitempty protoreflect.FieldDescriptor +) + +func init() { + file_testpb_test_proto_init() + md_TestNullableFields = File_testpb_test_proto.Messages().ByName("TestNullableFields") + fd_TestNullableFields_nullable_omitempty = md_TestNullableFields.Fields().ByName("nullable_omitempty") + fd_TestNullableFields_nullable_dont_omitempty = md_TestNullableFields.Fields().ByName("nullable_dont_omitempty") + fd_TestNullableFields_non_nullable_omitempty = md_TestNullableFields.Fields().ByName("non_nullable_omitempty") + fd_TestNullableFields_non_nullable_dont_omitempty = md_TestNullableFields.Fields().ByName("non_nullable_dont_omitempty") +} + +var _ protoreflect.Message = (*fastReflection_TestNullableFields)(nil) + +type fastReflection_TestNullableFields TestNullableFields + +func (x *TestNullableFields) ProtoReflect() protoreflect.Message { + return (*fastReflection_TestNullableFields)(x) +} + +func (x *TestNullableFields) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_test_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) +} + +var _fastReflection_TestNullableFields_messageType fastReflection_TestNullableFields_messageType +var _ protoreflect.MessageType = fastReflection_TestNullableFields_messageType{} + +type fastReflection_TestNullableFields_messageType struct{} + +func (x fastReflection_TestNullableFields_messageType) Zero() protoreflect.Message { + return (*fastReflection_TestNullableFields)(nil) +} +func (x fastReflection_TestNullableFields_messageType) New() protoreflect.Message { + return new(fastReflection_TestNullableFields) +} +func (x fastReflection_TestNullableFields_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_TestNullableFields +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_TestNullableFields) Descriptor() protoreflect.MessageDescriptor { + return md_TestNullableFields +} + +// 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_TestNullableFields) Type() protoreflect.MessageType { + return _fastReflection_TestNullableFields_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_TestNullableFields) New() protoreflect.Message { + return new(fastReflection_TestNullableFields) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_TestNullableFields) Interface() protoreflect.ProtoMessage { + return (*TestNullableFields)(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_TestNullableFields) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.NullableOmitempty != nil { + value := protoreflect.ValueOfMessage(x.NullableOmitempty.ProtoReflect()) + if !f(fd_TestNullableFields_nullable_omitempty, value) { + return + } + } + if x.NullableDontOmitempty != nil { + value := protoreflect.ValueOfMessage(x.NullableDontOmitempty.ProtoReflect()) + if !f(fd_TestNullableFields_nullable_dont_omitempty, value) { + return + } + } + if x.NonNullableOmitempty != nil { + value := protoreflect.ValueOfMessage(x.NonNullableOmitempty.ProtoReflect()) + if !f(fd_TestNullableFields_non_nullable_omitempty, value) { + return + } + } + if x.NonNullableDontOmitempty != nil { + value := protoreflect.ValueOfMessage(x.NonNullableDontOmitempty.ProtoReflect()) + if !f(fd_TestNullableFields_non_nullable_dont_omitempty, 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_TestNullableFields) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.TestNullableFields.nullable_omitempty": + return x.NullableOmitempty != nil + case "testpb.TestNullableFields.nullable_dont_omitempty": + return x.NullableDontOmitempty != nil + case "testpb.TestNullableFields.non_nullable_omitempty": + return x.NonNullableOmitempty != nil + case "testpb.TestNullableFields.non_nullable_dont_omitempty": + return x.NonNullableDontOmitempty != nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestNullableFields")) + } + panic(fmt.Errorf("message testpb.TestNullableFields 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_TestNullableFields) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.TestNullableFields.nullable_omitempty": + x.NullableOmitempty = nil + case "testpb.TestNullableFields.nullable_dont_omitempty": + x.NullableDontOmitempty = nil + case "testpb.TestNullableFields.non_nullable_omitempty": + x.NonNullableOmitempty = nil + case "testpb.TestNullableFields.non_nullable_dont_omitempty": + x.NonNullableDontOmitempty = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestNullableFields")) + } + panic(fmt.Errorf("message testpb.TestNullableFields 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_TestNullableFields) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.TestNullableFields.nullable_omitempty": + value := x.NullableOmitempty + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.TestNullableFields.nullable_dont_omitempty": + value := x.NullableDontOmitempty + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.TestNullableFields.non_nullable_omitempty": + value := x.NonNullableOmitempty + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.TestNullableFields.non_nullable_dont_omitempty": + value := x.NonNullableDontOmitempty + return protoreflect.ValueOfMessage(value.ProtoReflect()) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestNullableFields")) + } + panic(fmt.Errorf("message testpb.TestNullableFields 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_TestNullableFields) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.TestNullableFields.nullable_omitempty": + x.NullableOmitempty = value.Message().Interface().(*Streng) + case "testpb.TestNullableFields.nullable_dont_omitempty": + x.NullableDontOmitempty = value.Message().Interface().(*Streng) + case "testpb.TestNullableFields.non_nullable_omitempty": + x.NonNullableOmitempty = value.Message().Interface().(*Streng) + case "testpb.TestNullableFields.non_nullable_dont_omitempty": + x.NonNullableDontOmitempty = value.Message().Interface().(*Streng) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestNullableFields")) + } + panic(fmt.Errorf("message testpb.TestNullableFields 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_TestNullableFields) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.TestNullableFields.nullable_omitempty": + if x.NullableOmitempty == nil { + x.NullableOmitempty = new(Streng) + } + return protoreflect.ValueOfMessage(x.NullableOmitempty.ProtoReflect()) + case "testpb.TestNullableFields.nullable_dont_omitempty": + if x.NullableDontOmitempty == nil { + x.NullableDontOmitempty = new(Streng) + } + return protoreflect.ValueOfMessage(x.NullableDontOmitempty.ProtoReflect()) + case "testpb.TestNullableFields.non_nullable_omitempty": + if x.NonNullableOmitempty == nil { + x.NonNullableOmitempty = new(Streng) + } + return protoreflect.ValueOfMessage(x.NonNullableOmitempty.ProtoReflect()) + case "testpb.TestNullableFields.non_nullable_dont_omitempty": + if x.NonNullableDontOmitempty == nil { + x.NonNullableDontOmitempty = new(Streng) + } + return protoreflect.ValueOfMessage(x.NonNullableDontOmitempty.ProtoReflect()) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestNullableFields")) + } + panic(fmt.Errorf("message testpb.TestNullableFields 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_TestNullableFields) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.TestNullableFields.nullable_omitempty": + m := new(Streng) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.TestNullableFields.nullable_dont_omitempty": + m := new(Streng) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.TestNullableFields.non_nullable_omitempty": + m := new(Streng) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.TestNullableFields.non_nullable_dont_omitempty": + m := new(Streng) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.TestNullableFields")) + } + panic(fmt.Errorf("message testpb.TestNullableFields 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_TestNullableFields) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.TestNullableFields", 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_TestNullableFields) 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_TestNullableFields) 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_TestNullableFields) 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_TestNullableFields) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*TestNullableFields) + 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.NullableOmitempty != nil { + l = options.Size(x.NullableOmitempty) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.NullableDontOmitempty != nil { + l = options.Size(x.NullableDontOmitempty) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.NonNullableOmitempty != nil { + l = options.Size(x.NonNullableOmitempty) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.NonNullableDontOmitempty != nil { + l = options.Size(x.NonNullableDontOmitempty) + 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().(*TestNullableFields) + 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.NonNullableDontOmitempty != nil { + encoded, err := options.Marshal(x.NonNullableDontOmitempty) + 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] = 0x22 + } + if x.NonNullableOmitempty != nil { + encoded, err := options.Marshal(x.NonNullableOmitempty) + 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 x.NullableDontOmitempty != nil { + encoded, err := options.Marshal(x.NullableDontOmitempty) + 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] = 0x12 + } + if x.NullableOmitempty != nil { + encoded, err := options.Marshal(x.NullableOmitempty) + 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] = 0xa + } + 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().(*TestNullableFields) + 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: TestNullableFields: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: TestNullableFields: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field NullableOmitempty", 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.NullableOmitempty == nil { + x.NullableOmitempty = &Streng{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.NullableOmitempty); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field NullableDontOmitempty", 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.NullableDontOmitempty == nil { + x.NullableDontOmitempty = &Streng{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.NullableDontOmitempty); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field NonNullableOmitempty", 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.NonNullableOmitempty == nil { + x.NonNullableOmitempty = &Streng{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.NonNullableOmitempty); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field NonNullableDontOmitempty", 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.NonNullableDontOmitempty == nil { + x.NonNullableDontOmitempty = &Streng{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.NonNullableDontOmitempty); 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, + } +} + +var ( + md_IntAsString protoreflect.MessageDescriptor + fd_IntAsString_int_as_string protoreflect.FieldDescriptor +) + +func init() { + file_testpb_test_proto_init() + md_IntAsString = File_testpb_test_proto.Messages().ByName("IntAsString") + fd_IntAsString_int_as_string = md_IntAsString.Fields().ByName("int_as_string") +} + +var _ protoreflect.Message = (*fastReflection_IntAsString)(nil) + +type fastReflection_IntAsString IntAsString + +func (x *IntAsString) ProtoReflect() protoreflect.Message { + return (*fastReflection_IntAsString)(x) +} + +func (x *IntAsString) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_test_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_IntAsString_messageType fastReflection_IntAsString_messageType +var _ protoreflect.MessageType = fastReflection_IntAsString_messageType{} + +type fastReflection_IntAsString_messageType struct{} + +func (x fastReflection_IntAsString_messageType) Zero() protoreflect.Message { + return (*fastReflection_IntAsString)(nil) +} +func (x fastReflection_IntAsString_messageType) New() protoreflect.Message { + return new(fastReflection_IntAsString) +} +func (x fastReflection_IntAsString_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_IntAsString +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_IntAsString) Descriptor() protoreflect.MessageDescriptor { + return md_IntAsString +} + +// 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_IntAsString) Type() protoreflect.MessageType { + return _fastReflection_IntAsString_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_IntAsString) New() protoreflect.Message { + return new(fastReflection_IntAsString) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_IntAsString) Interface() protoreflect.ProtoMessage { + return (*IntAsString)(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_IntAsString) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.IntAsString != "" { + value := protoreflect.ValueOfString(x.IntAsString) + if !f(fd_IntAsString_int_as_string, 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_IntAsString) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.IntAsString.int_as_string": + return x.IntAsString != "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsString")) + } + panic(fmt.Errorf("message testpb.IntAsString 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_IntAsString) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.IntAsString.int_as_string": + x.IntAsString = "" + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsString")) + } + panic(fmt.Errorf("message testpb.IntAsString 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_IntAsString) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.IntAsString.int_as_string": + value := x.IntAsString + return protoreflect.ValueOfString(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsString")) + } + panic(fmt.Errorf("message testpb.IntAsString 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_IntAsString) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.IntAsString.int_as_string": + x.IntAsString = value.Interface().(string) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsString")) + } + panic(fmt.Errorf("message testpb.IntAsString 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_IntAsString) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.IntAsString.int_as_string": + panic(fmt.Errorf("field int_as_string of message testpb.IntAsString is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsString")) + } + panic(fmt.Errorf("message testpb.IntAsString 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_IntAsString) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.IntAsString.int_as_string": + return protoreflect.ValueOfString("") + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsString")) + } + panic(fmt.Errorf("message testpb.IntAsString 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_IntAsString) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.IntAsString", 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_IntAsString) 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_IntAsString) 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_IntAsString) 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_IntAsString) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*IntAsString) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.IntAsString) + if l > 0 { + 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().(*IntAsString) + 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 len(x.IntAsString) > 0 { + i -= len(x.IntAsString) + copy(dAtA[i:], x.IntAsString) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.IntAsString))) + i-- + dAtA[i] = 0xa + } + 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().(*IntAsString) + 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: IntAsString: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: IntAsString: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field IntAsString", 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.IntAsString = string(dAtA[iNdEx:postIndex]) + 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, + } +} + +var ( + md_IntAsBytes protoreflect.MessageDescriptor + fd_IntAsBytes_int_as_bytes protoreflect.FieldDescriptor +) + +func init() { + file_testpb_test_proto_init() + md_IntAsBytes = File_testpb_test_proto.Messages().ByName("IntAsBytes") + fd_IntAsBytes_int_as_bytes = md_IntAsBytes.Fields().ByName("int_as_bytes") +} + +var _ protoreflect.Message = (*fastReflection_IntAsBytes)(nil) + +type fastReflection_IntAsBytes IntAsBytes + +func (x *IntAsBytes) ProtoReflect() protoreflect.Message { + return (*fastReflection_IntAsBytes)(x) +} + +func (x *IntAsBytes) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_test_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) +} + +var _fastReflection_IntAsBytes_messageType fastReflection_IntAsBytes_messageType +var _ protoreflect.MessageType = fastReflection_IntAsBytes_messageType{} + +type fastReflection_IntAsBytes_messageType struct{} + +func (x fastReflection_IntAsBytes_messageType) Zero() protoreflect.Message { + return (*fastReflection_IntAsBytes)(nil) +} +func (x fastReflection_IntAsBytes_messageType) New() protoreflect.Message { + return new(fastReflection_IntAsBytes) +} +func (x fastReflection_IntAsBytes_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_IntAsBytes +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_IntAsBytes) Descriptor() protoreflect.MessageDescriptor { + return md_IntAsBytes +} + +// 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_IntAsBytes) Type() protoreflect.MessageType { + return _fastReflection_IntAsBytes_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_IntAsBytes) New() protoreflect.Message { + return new(fastReflection_IntAsBytes) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_IntAsBytes) Interface() protoreflect.ProtoMessage { + return (*IntAsBytes)(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_IntAsBytes) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if len(x.IntAsBytes) != 0 { + value := protoreflect.ValueOfBytes(x.IntAsBytes) + if !f(fd_IntAsBytes_int_as_bytes, 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_IntAsBytes) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.IntAsBytes.int_as_bytes": + return len(x.IntAsBytes) != 0 + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsBytes")) + } + panic(fmt.Errorf("message testpb.IntAsBytes 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_IntAsBytes) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.IntAsBytes.int_as_bytes": + x.IntAsBytes = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsBytes")) + } + panic(fmt.Errorf("message testpb.IntAsBytes 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_IntAsBytes) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.IntAsBytes.int_as_bytes": + value := x.IntAsBytes + return protoreflect.ValueOfBytes(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsBytes")) + } + panic(fmt.Errorf("message testpb.IntAsBytes 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_IntAsBytes) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.IntAsBytes.int_as_bytes": + x.IntAsBytes = value.Bytes() + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsBytes")) + } + panic(fmt.Errorf("message testpb.IntAsBytes 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_IntAsBytes) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.IntAsBytes.int_as_bytes": + panic(fmt.Errorf("field int_as_bytes of message testpb.IntAsBytes is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsBytes")) + } + panic(fmt.Errorf("message testpb.IntAsBytes 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_IntAsBytes) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.IntAsBytes.int_as_bytes": + return protoreflect.ValueOfBytes(nil) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsBytes")) + } + panic(fmt.Errorf("message testpb.IntAsBytes 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_IntAsBytes) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.IntAsBytes", 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_IntAsBytes) 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_IntAsBytes) 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_IntAsBytes) 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_IntAsBytes) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*IntAsBytes) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.IntAsBytes) + if l > 0 { + 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().(*IntAsBytes) + 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 len(x.IntAsBytes) > 0 { + i -= len(x.IntAsBytes) + copy(dAtA[i:], x.IntAsBytes) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.IntAsBytes))) + i-- + dAtA[i] = 0xa + } + 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().(*IntAsBytes) + 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: IntAsBytes: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: IntAsBytes: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field IntAsBytes", wireType) + } + var byteLen 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++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + byteLen + 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.IntAsBytes = append(x.IntAsBytes[:0], dAtA[iNdEx:postIndex]...) + if x.IntAsBytes == nil { + x.IntAsBytes = []byte{} + } + 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, + } +} + +var ( + md_IntAsBothStringAndBytes protoreflect.MessageDescriptor + fd_IntAsBothStringAndBytes_int_as_string protoreflect.FieldDescriptor + fd_IntAsBothStringAndBytes_int_as_bytes protoreflect.FieldDescriptor +) + +func init() { + file_testpb_test_proto_init() + md_IntAsBothStringAndBytes = File_testpb_test_proto.Messages().ByName("IntAsBothStringAndBytes") + fd_IntAsBothStringAndBytes_int_as_string = md_IntAsBothStringAndBytes.Fields().ByName("int_as_string") + fd_IntAsBothStringAndBytes_int_as_bytes = md_IntAsBothStringAndBytes.Fields().ByName("int_as_bytes") +} + +var _ protoreflect.Message = (*fastReflection_IntAsBothStringAndBytes)(nil) + +type fastReflection_IntAsBothStringAndBytes IntAsBothStringAndBytes + +func (x *IntAsBothStringAndBytes) ProtoReflect() protoreflect.Message { + return (*fastReflection_IntAsBothStringAndBytes)(x) +} + +func (x *IntAsBothStringAndBytes) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_test_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) +} + +var _fastReflection_IntAsBothStringAndBytes_messageType fastReflection_IntAsBothStringAndBytes_messageType +var _ protoreflect.MessageType = fastReflection_IntAsBothStringAndBytes_messageType{} + +type fastReflection_IntAsBothStringAndBytes_messageType struct{} + +func (x fastReflection_IntAsBothStringAndBytes_messageType) Zero() protoreflect.Message { + return (*fastReflection_IntAsBothStringAndBytes)(nil) +} +func (x fastReflection_IntAsBothStringAndBytes_messageType) New() protoreflect.Message { + return new(fastReflection_IntAsBothStringAndBytes) +} +func (x fastReflection_IntAsBothStringAndBytes_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_IntAsBothStringAndBytes +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_IntAsBothStringAndBytes) Descriptor() protoreflect.MessageDescriptor { + return md_IntAsBothStringAndBytes +} + +// 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_IntAsBothStringAndBytes) Type() protoreflect.MessageType { + return _fastReflection_IntAsBothStringAndBytes_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_IntAsBothStringAndBytes) New() protoreflect.Message { + return new(fastReflection_IntAsBothStringAndBytes) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_IntAsBothStringAndBytes) Interface() protoreflect.ProtoMessage { + return (*IntAsBothStringAndBytes)(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_IntAsBothStringAndBytes) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.IntAsString != "" { + value := protoreflect.ValueOfString(x.IntAsString) + if !f(fd_IntAsBothStringAndBytes_int_as_string, value) { + return + } + } + if len(x.IntAsBytes) != 0 { + value := protoreflect.ValueOfBytes(x.IntAsBytes) + if !f(fd_IntAsBothStringAndBytes_int_as_bytes, 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_IntAsBothStringAndBytes) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.IntAsBothStringAndBytes.int_as_string": + return x.IntAsString != "" + case "testpb.IntAsBothStringAndBytes.int_as_bytes": + return len(x.IntAsBytes) != 0 + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsBothStringAndBytes")) + } + panic(fmt.Errorf("message testpb.IntAsBothStringAndBytes 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_IntAsBothStringAndBytes) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.IntAsBothStringAndBytes.int_as_string": + x.IntAsString = "" + case "testpb.IntAsBothStringAndBytes.int_as_bytes": + x.IntAsBytes = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsBothStringAndBytes")) + } + panic(fmt.Errorf("message testpb.IntAsBothStringAndBytes 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_IntAsBothStringAndBytes) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.IntAsBothStringAndBytes.int_as_string": + value := x.IntAsString + return protoreflect.ValueOfString(value) + case "testpb.IntAsBothStringAndBytes.int_as_bytes": + value := x.IntAsBytes + return protoreflect.ValueOfBytes(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsBothStringAndBytes")) + } + panic(fmt.Errorf("message testpb.IntAsBothStringAndBytes 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_IntAsBothStringAndBytes) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.IntAsBothStringAndBytes.int_as_string": + x.IntAsString = value.Interface().(string) + case "testpb.IntAsBothStringAndBytes.int_as_bytes": + x.IntAsBytes = value.Bytes() + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsBothStringAndBytes")) + } + panic(fmt.Errorf("message testpb.IntAsBothStringAndBytes 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_IntAsBothStringAndBytes) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.IntAsBothStringAndBytes.int_as_string": + panic(fmt.Errorf("field int_as_string of message testpb.IntAsBothStringAndBytes is not mutable")) + case "testpb.IntAsBothStringAndBytes.int_as_bytes": + panic(fmt.Errorf("field int_as_bytes of message testpb.IntAsBothStringAndBytes is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsBothStringAndBytes")) + } + panic(fmt.Errorf("message testpb.IntAsBothStringAndBytes 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_IntAsBothStringAndBytes) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.IntAsBothStringAndBytes.int_as_string": + return protoreflect.ValueOfString("") + case "testpb.IntAsBothStringAndBytes.int_as_bytes": + return protoreflect.ValueOfBytes(nil) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.IntAsBothStringAndBytes")) + } + panic(fmt.Errorf("message testpb.IntAsBothStringAndBytes 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_IntAsBothStringAndBytes) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.IntAsBothStringAndBytes", 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_IntAsBothStringAndBytes) 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_IntAsBothStringAndBytes) 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_IntAsBothStringAndBytes) 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_IntAsBothStringAndBytes) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*IntAsBothStringAndBytes) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.IntAsString) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + l = len(x.IntAsBytes) + if l > 0 { + 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().(*IntAsBothStringAndBytes) + 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 len(x.IntAsBytes) > 0 { + i -= len(x.IntAsBytes) + copy(dAtA[i:], x.IntAsBytes) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.IntAsBytes))) + i-- + dAtA[i] = 0x12 + } + if len(x.IntAsString) > 0 { + i -= len(x.IntAsString) + copy(dAtA[i:], x.IntAsString) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.IntAsString))) + i-- + dAtA[i] = 0xa + } + 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().(*IntAsBothStringAndBytes) + 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: IntAsBothStringAndBytes: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: IntAsBothStringAndBytes: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field IntAsString", 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.IntAsString = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field IntAsBytes", wireType) + } + var byteLen 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++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + byteLen + 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.IntAsBytes = append(x.IntAsBytes[:0], dAtA[iNdEx:postIndex]...) + if x.IntAsBytes == nil { + x.IntAsBytes = []byte{} + } + 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) +// source: testpb/test.proto + +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 Streng struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *Streng) Reset() { + *x = Streng{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_test_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Streng) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Streng) ProtoMessage() {} + +// Deprecated: Use Streng.ProtoReflect.Descriptor instead. +func (*Streng) Descriptor() ([]byte, []int) { + return file_testpb_test_proto_rawDescGZIP(), []int{0} +} + +func (x *Streng) GetValue() string { + if x != nil { + return x.Value + } + return "" +} + +type TestRepeatedFields struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + NullableOmitempty []*Streng `protobuf:"bytes,1,rep,name=nullable_omitempty,json=nullableOmitempty,proto3" json:"nullable_omitempty,omitempty"` + // not supported for empty sets + // go-amino emits nothing but the protoreflect library emits a null + NullableDontOmitempty []*Streng `protobuf:"bytes,2,rep,name=nullable_dont_omitempty,json=nullableDontOmitempty,proto3" json:"nullable_dont_omitempty,omitempty"` + // not supported for empty sets + // go-amino emits a null but the protoreflect library emits nothing + NonNullableOmitempty []*Streng `protobuf:"bytes,3,rep,name=non_nullable_omitempty,json=nonNullableOmitempty,proto3" json:"non_nullable_omitempty,omitempty"` + NonNullableDontOmitempty []*Streng `protobuf:"bytes,4,rep,name=non_nullable_dont_omitempty,json=nonNullableDontOmitempty,proto3" json:"non_nullable_dont_omitempty,omitempty"` +} + +func (x *TestRepeatedFields) Reset() { + *x = TestRepeatedFields{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_test_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TestRepeatedFields) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TestRepeatedFields) ProtoMessage() {} + +// Deprecated: Use TestRepeatedFields.ProtoReflect.Descriptor instead. +func (*TestRepeatedFields) Descriptor() ([]byte, []int) { + return file_testpb_test_proto_rawDescGZIP(), []int{1} +} + +func (x *TestRepeatedFields) GetNullableOmitempty() []*Streng { + if x != nil { + return x.NullableOmitempty + } + return nil +} + +func (x *TestRepeatedFields) GetNullableDontOmitempty() []*Streng { + if x != nil { + return x.NullableDontOmitempty + } + return nil +} + +func (x *TestRepeatedFields) GetNonNullableOmitempty() []*Streng { + if x != nil { + return x.NonNullableOmitempty + } + return nil +} + +func (x *TestRepeatedFields) GetNonNullableDontOmitempty() []*Streng { + if x != nil { + return x.NonNullableDontOmitempty + } + return nil +} + +type TestNullableFields struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + NullableOmitempty *Streng `protobuf:"bytes,1,opt,name=nullable_omitempty,json=nullableOmitempty,proto3" json:"nullable_omitempty,omitempty"` + // not supported + // go-amino emits nothing and the protoreflect returns an error + // alternatively protoreflect could emit `{}` + NullableDontOmitempty *Streng `protobuf:"bytes,2,opt,name=nullable_dont_omitempty,json=nullableDontOmitempty,proto3" json:"nullable_dont_omitempty,omitempty"` + // not supported + // go-amino emits `{}` but the protoreflect library emits nothing + NonNullableOmitempty *Streng `protobuf:"bytes,3,opt,name=non_nullable_omitempty,json=nonNullableOmitempty,proto3" json:"non_nullable_omitempty,omitempty"` + NonNullableDontOmitempty *Streng `protobuf:"bytes,4,opt,name=non_nullable_dont_omitempty,json=nonNullableDontOmitempty,proto3" json:"non_nullable_dont_omitempty,omitempty"` +} + +func (x *TestNullableFields) Reset() { + *x = TestNullableFields{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_test_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TestNullableFields) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TestNullableFields) ProtoMessage() {} + +// Deprecated: Use TestNullableFields.ProtoReflect.Descriptor instead. +func (*TestNullableFields) Descriptor() ([]byte, []int) { + return file_testpb_test_proto_rawDescGZIP(), []int{2} +} + +func (x *TestNullableFields) GetNullableOmitempty() *Streng { + if x != nil { + return x.NullableOmitempty + } + return nil +} + +func (x *TestNullableFields) GetNullableDontOmitempty() *Streng { + if x != nil { + return x.NullableDontOmitempty + } + return nil +} + +func (x *TestNullableFields) GetNonNullableOmitempty() *Streng { + if x != nil { + return x.NonNullableOmitempty + } + return nil +} + +func (x *TestNullableFields) GetNonNullableDontOmitempty() *Streng { + if x != nil { + return x.NonNullableDontOmitempty + } + return nil +} + +type IntAsString struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IntAsString string `protobuf:"bytes,1,opt,name=int_as_string,json=intAsString,proto3" json:"int_as_string,omitempty"` +} + +func (x *IntAsString) Reset() { + *x = IntAsString{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_test_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IntAsString) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IntAsString) ProtoMessage() {} + +// Deprecated: Use IntAsString.ProtoReflect.Descriptor instead. +func (*IntAsString) Descriptor() ([]byte, []int) { + return file_testpb_test_proto_rawDescGZIP(), []int{3} +} + +func (x *IntAsString) GetIntAsString() string { + if x != nil { + return x.IntAsString + } + return "" +} + +type IntAsBytes struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IntAsBytes []byte `protobuf:"bytes,1,opt,name=int_as_bytes,json=intAsBytes,proto3" json:"int_as_bytes,omitempty"` +} + +func (x *IntAsBytes) Reset() { + *x = IntAsBytes{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_test_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IntAsBytes) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IntAsBytes) ProtoMessage() {} + +// Deprecated: Use IntAsBytes.ProtoReflect.Descriptor instead. +func (*IntAsBytes) Descriptor() ([]byte, []int) { + return file_testpb_test_proto_rawDescGZIP(), []int{4} +} + +func (x *IntAsBytes) GetIntAsBytes() []byte { + if x != nil { + return x.IntAsBytes + } + return nil +} + +type IntAsBothStringAndBytes struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + IntAsString string `protobuf:"bytes,1,opt,name=int_as_string,json=intAsString,proto3" json:"int_as_string,omitempty"` + IntAsBytes []byte `protobuf:"bytes,2,opt,name=int_as_bytes,json=intAsBytes,proto3" json:"int_as_bytes,omitempty"` +} + +func (x *IntAsBothStringAndBytes) Reset() { + *x = IntAsBothStringAndBytes{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_test_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IntAsBothStringAndBytes) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IntAsBothStringAndBytes) ProtoMessage() {} + +// Deprecated: Use IntAsBothStringAndBytes.ProtoReflect.Descriptor instead. +func (*IntAsBothStringAndBytes) Descriptor() ([]byte, []int) { + return file_testpb_test_proto_rawDescGZIP(), []int{5} +} + +func (x *IntAsBothStringAndBytes) GetIntAsString() string { + if x != nil { + return x.IntAsString + } + return "" +} + +func (x *IntAsBothStringAndBytes) GetIntAsBytes() []byte { + if x != nil { + return x.IntAsBytes + } + return nil +} + +var File_testpb_test_proto protoreflect.FileDescriptor + +var file_testpb_test_proto_rawDesc = []byte{ + 0x0a, 0x11, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x1a, 0x14, 0x67, 0x6f, 0x67, + 0x6f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x1a, 0x11, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x5f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0x1e, 0x0a, 0x06, 0x73, 0x74, 0x72, 0x65, 0x6e, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, + 0xc8, 0x02, 0x0a, 0x12, 0x54, 0x65, 0x73, 0x74, 0x52, 0x65, 0x70, 0x65, 0x61, 0x74, 0x65, 0x64, + 0x46, 0x69, 0x65, 0x6c, 0x64, 0x73, 0x12, 0x3d, 0x0a, 0x12, 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x62, + 0x6c, 0x65, 0x5f, 0x6f, 0x6d, 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x73, 0x74, 0x72, 0x65, + 0x6e, 0x67, 0x52, 0x11, 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x4f, 0x6d, 0x69, 0x74, + 0x65, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x4d, 0x0a, 0x17, 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, + 0x65, 0x5f, 0x64, 0x6f, 0x6e, 0x74, 0x5f, 0x6f, 0x6d, 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, + 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, + 0x73, 0x74, 0x72, 0x65, 0x6e, 0x67, 0x42, 0x05, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x15, 0x6e, + 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x44, 0x6f, 0x6e, 0x74, 0x4f, 0x6d, 0x69, 0x74, 0x65, + 0x6d, 0x70, 0x74, 0x79, 0x12, 0x4a, 0x0a, 0x16, 0x6e, 0x6f, 0x6e, 0x5f, 0x6e, 0x75, 0x6c, 0x6c, + 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x6f, 0x6d, 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x18, 0x03, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x73, 0x74, + 0x72, 0x65, 0x6e, 0x67, 0x42, 0x04, 0xc8, 0xde, 0x1f, 0x00, 0x52, 0x14, 0x6e, 0x6f, 0x6e, 0x4e, + 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x4f, 0x6d, 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, + 0x12, 0x58, 0x0a, 0x1b, 0x6e, 0x6f, 0x6e, 0x5f, 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, + 0x5f, 0x64, 0x6f, 0x6e, 0x74, 0x5f, 0x6f, 0x6d, 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x18, + 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x73, + 0x74, 0x72, 0x65, 0x6e, 0x67, 0x42, 0x09, 0xc8, 0xde, 0x1f, 0x00, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, + 0x52, 0x18, 0x6e, 0x6f, 0x6e, 0x4e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x44, 0x6f, 0x6e, + 0x74, 0x4f, 0x6d, 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x22, 0xc8, 0x02, 0x0a, 0x12, 0x54, + 0x65, 0x73, 0x74, 0x4e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x69, 0x65, 0x6c, 0x64, + 0x73, 0x12, 0x3d, 0x0a, 0x12, 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x6f, 0x6d, + 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, + 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x73, 0x74, 0x72, 0x65, 0x6e, 0x67, 0x52, 0x11, 0x6e, + 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x4f, 0x6d, 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, + 0x12, 0x4d, 0x0a, 0x17, 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x64, 0x6f, 0x6e, + 0x74, 0x5f, 0x6f, 0x6d, 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x73, 0x74, 0x72, 0x65, 0x6e, + 0x67, 0x42, 0x05, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x15, 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x62, + 0x6c, 0x65, 0x44, 0x6f, 0x6e, 0x74, 0x4f, 0x6d, 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x12, + 0x4a, 0x0a, 0x16, 0x6e, 0x6f, 0x6e, 0x5f, 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, + 0x6f, 0x6d, 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x73, 0x74, 0x72, 0x65, 0x6e, 0x67, 0x42, + 0x04, 0xc8, 0xde, 0x1f, 0x00, 0x52, 0x14, 0x6e, 0x6f, 0x6e, 0x4e, 0x75, 0x6c, 0x6c, 0x61, 0x62, + 0x6c, 0x65, 0x4f, 0x6d, 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x58, 0x0a, 0x1b, 0x6e, + 0x6f, 0x6e, 0x5f, 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x64, 0x6f, 0x6e, 0x74, + 0x5f, 0x6f, 0x6d, 0x69, 0x74, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x73, 0x74, 0x72, 0x65, 0x6e, 0x67, + 0x42, 0x09, 0xc8, 0xde, 0x1f, 0x00, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x18, 0x6e, 0x6f, 0x6e, + 0x4e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x44, 0x6f, 0x6e, 0x74, 0x4f, 0x6d, 0x69, 0x74, + 0x65, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x74, 0x0a, 0x0b, 0x49, 0x6e, 0x74, 0x41, 0x73, 0x53, 0x74, + 0x72, 0x69, 0x6e, 0x67, 0x12, 0x65, 0x0a, 0x0d, 0x69, 0x6e, 0x74, 0x5f, 0x61, 0x73, 0x5f, 0x73, + 0x74, 0x72, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x41, 0xc8, 0xde, 0x1f, + 0x00, 0xda, 0xde, 0x1f, 0x26, 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, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x49, 0x6e, 0x74, 0xd2, 0xb4, 0x2d, 0x0a, 0x63, + 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x49, 0x6e, 0x74, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x0b, + 0x69, 0x6e, 0x74, 0x41, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x71, 0x0a, 0x0a, 0x49, + 0x6e, 0x74, 0x41, 0x73, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x63, 0x0a, 0x0c, 0x69, 0x6e, 0x74, + 0x5f, 0x61, 0x73, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x42, + 0x41, 0xc8, 0xde, 0x1f, 0x00, 0xda, 0xde, 0x1f, 0x26, 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, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x49, 0x6e, 0x74, 0xd2, + 0xb4, 0x2d, 0x0a, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x49, 0x6e, 0x74, 0xa8, 0xe7, 0xb0, + 0x2a, 0x01, 0x52, 0x0a, 0x69, 0x6e, 0x74, 0x41, 0x73, 0x42, 0x79, 0x74, 0x65, 0x73, 0x22, 0xe5, + 0x01, 0x0a, 0x17, 0x49, 0x6e, 0x74, 0x41, 0x73, 0x42, 0x6f, 0x74, 0x68, 0x53, 0x74, 0x72, 0x69, + 0x6e, 0x67, 0x41, 0x6e, 0x64, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x65, 0x0a, 0x0d, 0x69, 0x6e, + 0x74, 0x5f, 0x61, 0x73, 0x5f, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x42, 0x41, 0xc8, 0xde, 0x1f, 0x00, 0xda, 0xde, 0x1f, 0x26, 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, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x49, 0x6e, + 0x74, 0xd2, 0xb4, 0x2d, 0x0a, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2e, 0x49, 0x6e, 0x74, 0xa8, + 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x0b, 0x69, 0x6e, 0x74, 0x41, 0x73, 0x53, 0x74, 0x72, 0x69, 0x6e, + 0x67, 0x12, 0x63, 0x0a, 0x0c, 0x69, 0x6e, 0x74, 0x5f, 0x61, 0x73, 0x5f, 0x62, 0x79, 0x74, 0x65, + 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x42, 0x41, 0xc8, 0xde, 0x1f, 0x00, 0xda, 0xde, 0x1f, + 0x26, 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, 0x74, 0x79, + 0x70, 0x65, 0x73, 0x2e, 0x49, 0x6e, 0x74, 0xd2, 0xb4, 0x2d, 0x0a, 0x63, 0x6f, 0x73, 0x6d, 0x6f, + 0x73, 0x2e, 0x49, 0x6e, 0x74, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x0a, 0x69, 0x6e, 0x74, 0x41, + 0x73, 0x42, 0x79, 0x74, 0x65, 0x73, 0x42, 0xa7, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, + 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x09, 0x54, 0x65, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, + 0x50, 0x01, 0x5a, 0x56, 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, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x6a, 0x73, 0x6f, 0x6e, 0x2f, 0x69, 0x6e, 0x74, + 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x70, 0x75, 0x6c, + 0x73, 0x61, 0x72, 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 ( + file_testpb_test_proto_rawDescOnce sync.Once + file_testpb_test_proto_rawDescData = file_testpb_test_proto_rawDesc +) + +func file_testpb_test_proto_rawDescGZIP() []byte { + file_testpb_test_proto_rawDescOnce.Do(func() { + file_testpb_test_proto_rawDescData = protoimpl.X.CompressGZIP(file_testpb_test_proto_rawDescData) + }) + return file_testpb_test_proto_rawDescData +} + +var file_testpb_test_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_testpb_test_proto_goTypes = []interface{}{ + (*Streng)(nil), // 0: testpb.streng + (*TestRepeatedFields)(nil), // 1: testpb.TestRepeatedFields + (*TestNullableFields)(nil), // 2: testpb.TestNullableFields + (*IntAsString)(nil), // 3: testpb.IntAsString + (*IntAsBytes)(nil), // 4: testpb.IntAsBytes + (*IntAsBothStringAndBytes)(nil), // 5: testpb.IntAsBothStringAndBytes +} +var file_testpb_test_proto_depIdxs = []int32{ + 0, // 0: testpb.TestRepeatedFields.nullable_omitempty:type_name -> testpb.streng + 0, // 1: testpb.TestRepeatedFields.nullable_dont_omitempty:type_name -> testpb.streng + 0, // 2: testpb.TestRepeatedFields.non_nullable_omitempty:type_name -> testpb.streng + 0, // 3: testpb.TestRepeatedFields.non_nullable_dont_omitempty:type_name -> testpb.streng + 0, // 4: testpb.TestNullableFields.nullable_omitempty:type_name -> testpb.streng + 0, // 5: testpb.TestNullableFields.nullable_dont_omitempty:type_name -> testpb.streng + 0, // 6: testpb.TestNullableFields.non_nullable_omitempty:type_name -> testpb.streng + 0, // 7: testpb.TestNullableFields.non_nullable_dont_omitempty:type_name -> testpb.streng + 8, // [8:8] is the sub-list for method output_type + 8, // [8:8] is the sub-list for method input_type + 8, // [8:8] is the sub-list for extension type_name + 8, // [8:8] is the sub-list for extension extendee + 0, // [0:8] is the sub-list for field type_name +} + +func init() { file_testpb_test_proto_init() } +func file_testpb_test_proto_init() { + if File_testpb_test_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_testpb_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Streng); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TestRepeatedFields); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_test_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TestNullableFields); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_test_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*IntAsString); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_test_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*IntAsBytes); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_test_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*IntAsBothStringAndBytes); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_testpb_test_proto_rawDesc, + NumEnums: 0, + NumMessages: 6, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_testpb_test_proto_goTypes, + DependencyIndexes: file_testpb_test_proto_depIdxs, + MessageInfos: file_testpb_test_proto_msgTypes, + }.Build() + File_testpb_test_proto = out.File + file_testpb_test_proto_rawDesc = nil + file_testpb_test_proto_goTypes = nil + file_testpb_test_proto_depIdxs = nil +} diff --git a/tests/integration/aminojson/internal/testpb/test.proto b/tests/integration/aminojson/internal/testpb/test.proto new file mode 100644 index 000000000000..413b0411744f --- /dev/null +++ b/tests/integration/aminojson/internal/testpb/test.proto @@ -0,0 +1,58 @@ +syntax = "proto3"; + +package testpb; + +import "gogoproto/gogo.proto"; +import "amino/amino.proto"; +import "cosmos_proto/cosmos.proto"; + +message streng { + string value = 1; +} + +message TestRepeatedFields { + repeated streng nullable_omitempty = 1; + + // not supported for empty sets + // go-amino emits nothing but the protoreflect library emits a null + repeated streng nullable_dont_omitempty = 2 [(amino.dont_omitempty) = true]; + + // not supported for empty sets + // go-amino emits a null but the protoreflect library emits nothing + repeated streng non_nullable_omitempty = 3 [(gogoproto.nullable) = false]; + + repeated streng non_nullable_dont_omitempty = 4 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} + +message TestNullableFields { + streng nullable_omitempty = 1; + + // not supported + // go-amino emits nothing and the protoreflect returns an error + // alternatively protoreflect could emit `{}` + streng nullable_dont_omitempty = 2 [(amino.dont_omitempty) = true]; + + // not supported + // go-amino emits `{}` but the protoreflect library emits nothing + streng non_nullable_omitempty = 3 [(gogoproto.nullable) = false]; + + streng non_nullable_dont_omitempty = 4 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; +} + +message IntAsString { + string int_as_string = 1 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (amino.dont_omitempty) = true, + (gogoproto.nullable) = false + ]; +} + +message IntAsBytes { + bytes int_as_bytes = 1 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (amino.dont_omitempty) = true, + (gogoproto.nullable) = false + ]; +} \ No newline at end of file diff --git a/tests/integration/aminojson/repeated_test.go b/tests/integration/aminojson/repeated_test.go new file mode 100644 index 000000000000..ae0a2bdfd490 --- /dev/null +++ b/tests/integration/aminojson/repeated_test.go @@ -0,0 +1,81 @@ +package aminojson + +import ( + "fmt" + "testing" + + gogoproto "github.com/cosmos/gogoproto/proto" + "google.golang.org/protobuf/proto" + + "github.com/stretchr/testify/require" + + "cosmossdk.io/x/tx/aminojson" + "github.com/cosmos/cosmos-sdk/codec" + gogopb "github.com/cosmos/cosmos-sdk/tests/integration/aminojson/internal/gogo/testpb" + pulsarpb "github.com/cosmos/cosmos-sdk/tests/integration/aminojson/internal/pulsar/testpb" +) + +func TestRepeatedFields(t *testing.T) { + cdc := codec.NewLegacyAmino() + aj := aminojson.NewAminoJSON() + + cases := map[string]struct { + gogo gogoproto.Message + pulsar proto.Message + unequal bool + errs bool + }{ + "unsupported_empty_sets": { + gogo: &gogopb.TestRepeatedFields{}, + pulsar: &pulsarpb.TestRepeatedFields{}, + unequal: true, + }, + "unsupported_empty_sets_are_set": { + gogo: &gogopb.TestRepeatedFields{ + NullableDontOmitempty: []*gogopb.Streng{{Value: "foo"}}, + NonNullableOmitempty: []gogopb.Streng{{Value: "foo"}}, + }, + pulsar: &pulsarpb.TestRepeatedFields{ + NullableDontOmitempty: []*pulsarpb.Streng{{Value: "foo"}}, + NonNullableOmitempty: []*pulsarpb.Streng{{Value: "foo"}}, + }, + }, + "unsupported_nullable": { + gogo: &gogopb.TestNullableFields{}, + pulsar: &pulsarpb.TestNullableFields{}, + errs: true, + }, + "unsupported_nullable_set": { + gogo: &gogopb.TestNullableFields{ + NullableDontOmitempty: &gogopb.Streng{Value: "foo"}, + NonNullableDontOmitempty: gogopb.Streng{Value: "foo"}, + }, + pulsar: &pulsarpb.TestNullableFields{ + NullableDontOmitempty: &pulsarpb.Streng{Value: "foo"}, + NonNullableDontOmitempty: &pulsarpb.Streng{Value: "foo"}, + }, + unequal: true, + }, + } + + for n, tc := range cases { + t.Run(n, func(t *testing.T) { + gogoBz, err := cdc.MarshalJSON(tc.gogo) + require.NoError(t, err) + pulsarBz, err := aj.Marshal(tc.pulsar) + if tc.errs { + require.Error(t, err) + return + } + require.NoError(t, err) + + fmt.Printf(" gogo: %s\npulsar: %s\n", string(gogoBz), string(pulsarBz)) + + if tc.unequal { + require.NotEqual(t, string(gogoBz), string(pulsarBz)) + } else { + require.Equal(t, string(gogoBz), string(pulsarBz)) + } + }) + } +} diff --git a/testutil/rapidproto/rapidproto.go b/testutil/rapidproto/rapidproto.go deleted file mode 100644 index 2922cbc688c7..000000000000 --- a/testutil/rapidproto/rapidproto.go +++ /dev/null @@ -1,221 +0,0 @@ -package rapidproto - -import ( - "fmt" - - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - "gotest.tools/v3/assert" - "pgregory.net/rapid" -) - -func MessageGenerator[T proto.Message](x T, options GeneratorOptions) *rapid.Generator[T] { - msgType := x.ProtoReflect().Type() - return rapid.Custom(func(t *rapid.T) T { - msg := msgType.New() - - options.setFields(t, msg, 0) - - return msg.Interface().(T) - }) -} - -type GeneratorOptions struct { - AnyTypeURLs []string - Resolver protoregistry.MessageTypeResolver -} - -const depthLimit = 10 - -func (opts GeneratorOptions) setFields(t *rapid.T, msg protoreflect.Message, depth int) bool { - // to avoid stack overflow we limit the depth of nested messages - if depth > depthLimit { - return false - } - - descriptor := msg.Descriptor() - fullName := descriptor.FullName() - switch fullName { - case timestampFullName: - opts.genTimestamp(t, msg) - return true - case durationFullName: - opts.genDuration(t, msg) - return true - case anyFullName: - return opts.genAny(t, msg, depth) - case fieldMaskFullName: - opts.genFieldMask(t, msg) - return true - default: - fields := descriptor.Fields() - n := fields.Len() - for i := 0; i < n; i++ { - field := fields.Get(i) - if !rapid.Bool().Draw(t, fmt.Sprintf("gen-%s", field.Name())) { - continue - } - - opts.setFieldValue(t, msg, field, depth) - } - return true - } -} - -const ( - timestampFullName = "google.protobuf.Timestamp" - durationFullName = "google.protobuf.Duration" - anyFullName = "google.protobuf.Any" - fieldMaskFullName = "google.protobuf.FieldMask" -) - -func (opts GeneratorOptions) setFieldValue(t *rapid.T, msg protoreflect.Message, field protoreflect.FieldDescriptor, depth int) { - name := string(field.Name()) - kind := field.Kind() - - switch { - case field.IsList(): - list := msg.Mutable(field).List() - n := rapid.IntRange(0, 10).Draw(t, fmt.Sprintf("%sN", name)) - for i := 0; i < n; i++ { - if kind == protoreflect.MessageKind || kind == protoreflect.GroupKind { - if !opts.setFields(t, list.AppendMutable().Message(), depth+1) { - list.Truncate(i) - } - } else { - list.Append(opts.genScalarFieldValue(t, field, fmt.Sprintf("%s%d", name, i))) - } - } - case field.IsMap(): - m := msg.Mutable(field).Map() - n := rapid.IntRange(0, 10).Draw(t, fmt.Sprintf("%sN", name)) - for i := 0; i < n; i++ { - keyField := field.MapKey() - valueField := field.MapValue() - valueKind := valueField.Kind() - key := opts.genScalarFieldValue(t, keyField, fmt.Sprintf("%s%d-key", name, i)) - if valueKind == protoreflect.MessageKind || valueKind == protoreflect.GroupKind { - if !opts.setFields(t, m.Mutable(key.MapKey()).Message(), depth+1) { - m.Clear(key.MapKey()) - } - } else { - value := opts.genScalarFieldValue(t, valueField, fmt.Sprintf("%s%d-key", name, i)) - m.Set(key.MapKey(), value) - } - } - default: - if kind == protoreflect.MessageKind || kind == protoreflect.GroupKind { - if !opts.setFields(t, msg.Mutable(field).Message(), depth+1) { - msg.Clear(field) - } - } else { - msg.Set(field, opts.genScalarFieldValue(t, field, name)) - } - } -} - -func (opts GeneratorOptions) genScalarFieldValue(t *rapid.T, field protoreflect.FieldDescriptor, name string) protoreflect.Value { - switch field.Kind() { - case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: - return protoreflect.ValueOfInt32(rapid.Int32().Draw(t, name)) - case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: - return protoreflect.ValueOfUint32(rapid.Uint32().Draw(t, name)) - case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: - return protoreflect.ValueOfInt64(rapid.Int64().Draw(t, name)) - case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: - return protoreflect.ValueOfUint64(rapid.Uint64().Draw(t, name)) - case protoreflect.BoolKind: - return protoreflect.ValueOfBool(rapid.Bool().Draw(t, name)) - case protoreflect.BytesKind: - return protoreflect.ValueOfBytes(rapid.SliceOf(rapid.Byte()).Draw(t, name)) - case protoreflect.FloatKind: - return protoreflect.ValueOfFloat32(rapid.Float32().Draw(t, name)) - case protoreflect.DoubleKind: - return protoreflect.ValueOfFloat64(rapid.Float64().Draw(t, name)) - case protoreflect.EnumKind: - enumValues := field.Enum().Values() - val := rapid.Int32Range(0, int32(enumValues.Len()-1)).Draw(t, name) - return protoreflect.ValueOfEnum(protoreflect.EnumNumber(val)) - case protoreflect.StringKind: - return protoreflect.ValueOfString(rapid.String().Draw(t, name)) - default: - t.Fatalf("unexpected %v", field) - return protoreflect.Value{} - } -} - -const ( - secondsName = "seconds" - nanosName = "nanos" -) - -func (opts GeneratorOptions) genTimestamp(t *rapid.T, msg protoreflect.Message) { - seconds := rapid.Int64Range(-9999999999, 9999999999).Draw(t, "seconds") - nanos := rapid.Int32Range(0, 999999999).Draw(t, "nanos") - setSecondsNanosFields(t, msg, seconds, nanos) -} - -func (opts GeneratorOptions) genDuration(t *rapid.T, msg protoreflect.Message) { - seconds := rapid.Int64Range(0, 315576000000).Draw(t, "seconds") - nanos := rapid.Int32Range(0, 999999999).Draw(t, "nanos") - setSecondsNanosFields(t, msg, seconds, nanos) -} - -func setSecondsNanosFields(t *rapid.T, message protoreflect.Message, seconds int64, nanos int32) { - fields := message.Descriptor().Fields() - - secondsField := fields.ByName(secondsName) - assert.Assert(t, secondsField != nil) - message.Set(secondsField, protoreflect.ValueOfInt64(seconds)) - - nanosField := fields.ByName(nanosName) - assert.Assert(t, nanosField != nil) - message.Set(nanosField, protoreflect.ValueOfInt32(nanos)) -} - -const ( - typeURLName = "type_url" - valueName = "value" -) - -func (opts GeneratorOptions) genAny(t *rapid.T, msg protoreflect.Message, depth int) bool { - if len(opts.AnyTypeURLs) == 0 { - return false - } - - fields := msg.Descriptor().Fields() - - typeURL := rapid.SampledFrom(opts.AnyTypeURLs).Draw(t, "type_url") - typ, err := opts.Resolver.FindMessageByURL(typeURL) - assert.NilError(t, err) - - typeURLField := fields.ByName(typeURLName) - assert.Assert(t, typeURLField != nil) - msg.Set(typeURLField, protoreflect.ValueOfString(typeURL)) - - valueMsg := typ.New() - opts.setFields(t, valueMsg, depth+1) - valueBz, err := proto.Marshal(valueMsg.Interface()) - assert.NilError(t, err) - - valueField := fields.ByName(valueName) - assert.Assert(t, valueField != nil) - msg.Set(valueField, protoreflect.ValueOfBytes(valueBz)) - - return true -} - -const ( - pathsName = "paths" -) - -func (opts GeneratorOptions) genFieldMask(t *rapid.T, msg protoreflect.Message) { - paths := rapid.SliceOfN(rapid.StringMatching("[a-z]+([.][a-z]+){0,2}"), 1, 5).Draw(t, "paths") - pathsField := msg.Descriptor().Fields().ByName(pathsName) - assert.Assert(t, pathsField != nil) - pathsList := msg.NewField(pathsField).List() - for _, path := range paths { - pathsList.Append(protoreflect.ValueOfString(path)) - } -} diff --git a/testutil/rapidproto/rapidproto_test.go b/testutil/rapidproto/rapidproto_test.go deleted file mode 100644 index 6be07c0bc963..000000000000 --- a/testutil/rapidproto/rapidproto_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package rapidproto_test - -import ( - "fmt" - "testing" - - "google.golang.org/protobuf/encoding/protojson" - "google.golang.org/protobuf/proto" - "gotest.tools/v3/assert" - "gotest.tools/v3/golden" - "pgregory.net/rapid" - - "github.com/cosmos/cosmos-proto/testpb" - - "github.com/cosmos/cosmos-sdk/testutil/rapidproto" -) - -// TestRegression checks that the generator still produces the same output -// for the same random seeds, assuming that this data has been hand expected -// to generally look good. -func TestRegression(t *testing.T) { - gen := rapidproto.MessageGenerator(&testpb.A{}, rapidproto.GeneratorOptions{}) - for i := 0; i < 5; i++ { - testRegressionSeed(t, i, gen) - } -} - -func testRegressionSeed[X proto.Message](t *testing.T, seed int, generator *rapid.Generator[X]) { - x := generator.Example(seed) - bz, err := protojson.Marshal(x) - assert.NilError(t, err) - golden.Assert(t, string(bz), fmt.Sprintf("seed%d.json", seed)) -} diff --git a/testutil/rapidproto/testdata/seed0.json b/testutil/rapidproto/testdata/seed0.json deleted file mode 100644 index fc8ba93a5450..000000000000 --- a/testutil/rapidproto/testdata/seed0.json +++ /dev/null @@ -1 +0,0 @@ -{"enum":"Two", "someBoolean":true, "INT32":6, "SINT32":-53, "INT64":"-261", "SFIXED32":3, "FIXED32":65302, "FIXED64":"45044", "STRING":"󳲠~Âaႃ#", "MESSAGE":{"x":"ʰ="}, "MAP":{"":{"x":"௹"}, "%󠇯º$&.":{"x":"-"}, "=A":{}, "AA|𞀠":{"x":"a\u0000ๆ"}}, "LIST":[{}], "ONEOFSTRING":"", "imported":{}} \ No newline at end of file diff --git a/testutil/rapidproto/testdata/seed1.json b/testutil/rapidproto/testdata/seed1.json deleted file mode 100644 index 881e8d32c433..000000000000 --- a/testutil/rapidproto/testdata/seed1.json +++ /dev/null @@ -1 +0,0 @@ -{"UINT32":177, "INT64":"-139958413", "SFIXED32":41418, "FIXED32":25381940, "FLOAT":-8.336453e+31, "SFIXED64":"-2503553836720", "DOUBLE":-0.03171187036377887, "STRING":"?˄~ע", "MESSAGE":{"x":"dDž#"}, "MAP":{"Ⱥa<":{"x":"+["}, "֑Ⱥ|@!`":{}}, "ONEOFSTRING":"\u0012\t?A", "imported":{}, "type":"A�=*ى~~‮Ⱥ*ᾈാȺAᶊ?"} \ No newline at end of file diff --git a/testutil/rapidproto/testdata/seed2.json b/testutil/rapidproto/testdata/seed2.json deleted file mode 100644 index 8a1986c45689..000000000000 --- a/testutil/rapidproto/testdata/seed2.json +++ /dev/null @@ -1 +0,0 @@ -{"INT32":-48, "UINT32":246, "INT64":"-21558176502", "SING64":"5030347", "UINT64":"28", "FIXED32":92, "DOUBLE":2.3547259926790202e-142, "STRING":"ಾ", "LIST":[{}, {}, {}, {}, {"x":" ᾚ DzA{˭҄\nA ^$?ᾦ,:<\"?_\u0014;|"}], "ONEOFSTRING":"𝟠Ÿ", "LISTENUM":["Two", "One", "One"]} \ No newline at end of file diff --git a/testutil/rapidproto/testdata/seed3.json b/testutil/rapidproto/testdata/seed3.json deleted file mode 100644 index 6b02c4152d59..000000000000 --- a/testutil/rapidproto/testdata/seed3.json +++ /dev/null @@ -1 +0,0 @@ -{"INT32":22525032, "SINT32":897, "INT64":"-301128487533312", "SFIXED64":"-71", "FIXED64":"14", "DOUBLE":-2.983041182946181, "STRING":"-A^'", "MESSAGE":{"x":"#ऻ;́\r‮⋁"}, "LIST":[{}, {}, {}, {}, {}], "ONEOFSTRING":"", "imported":{}, "type":"₩\u0000^৴~౽  NjAৈ􁇸⃠𝖜ೄ"} \ No newline at end of file diff --git a/testutil/rapidproto/testdata/seed4.json b/testutil/rapidproto/testdata/seed4.json deleted file mode 100644 index fe4be997095c..000000000000 --- a/testutil/rapidproto/testdata/seed4.json +++ /dev/null @@ -1 +0,0 @@ -{"SINT32":1, "INT64":"-9223372036854775808", "SING64":"1", "FLOAT":-0.00013906474, "SFIXED64":"71414010", "STRING":"ף̂", "MESSAGE":{"x":" "}, "LIST":[{}], "ONEOFSTRING":"#¯∑Ⱥ�", "LISTENUM":["One", "One", "Two", "Two", "One", "One", "One", "Two"], "imported":{}, "type":"\u001b<ʰ+`𑱐@\u001b*Dž‮\u0000#₻\u0000"} \ No newline at end of file diff --git a/x/tx/aminojson/.gitignore b/x/tx/aminojson/.gitignore new file mode 100644 index 000000000000..9309455bc5b4 --- /dev/null +++ b/x/tx/aminojson/.gitignore @@ -0,0 +1 @@ +testdata/rapid diff --git a/x/tx/aminojson/any.go b/x/tx/aminojson/any.go new file mode 100644 index 000000000000..68b1a9ec1024 --- /dev/null +++ b/x/tx/aminojson/any.go @@ -0,0 +1,37 @@ +package aminojson + +import ( + "fmt" + "io" + + "google.golang.org/protobuf/types/known/anypb" + + "github.com/pkg/errors" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" +) + +func (enc Encoder) marshalAny(message protoreflect.Message, writer io.Writer) error { + anyMsg := message.Interface().(*anypb.Any) + resolver := protoregistry.GlobalTypes + + typ, err := resolver.FindMessageByURL(anyMsg.TypeUrl) + if err != nil { + return errors.Wrapf(err, "can't resolve type URL %s", anyMsg.TypeUrl) + } + + valueMsg := typ.New() + err = proto.Unmarshal(anyMsg.Value, valueMsg.Interface()) + if err != nil { + return err + } + + _, named := getMessageAminoName(valueMsg) + if !named { + return fmt.Errorf("message %s is packed into an any field, so requires an amino.name annotation", + anyMsg.TypeUrl) + } + + return enc.beginMarshal(valueMsg, writer) +} diff --git a/x/tx/aminojson/encoder.go b/x/tx/aminojson/encoder.go new file mode 100644 index 000000000000..8fab6aba62e1 --- /dev/null +++ b/x/tx/aminojson/encoder.go @@ -0,0 +1,170 @@ +package aminojson + +import ( + "encoding/base64" + "encoding/json" + "fmt" + "io" + + "github.com/pkg/errors" + "google.golang.org/protobuf/reflect/protoreflect" + + authapi "cosmossdk.io/api/cosmos/auth/v1beta1" + "cosmossdk.io/api/cosmos/crypto/multisig" + "cosmossdk.io/math" +) + +// cosmosIntEncoder provides legacy compatible encoding for cosmos.Int types. In gogo messages these are sometimes +// represented by a `cosmos-sdk/types.Int` through the usage of the option: +// +// (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int" +// +// In pulsar message they represented as strings, which is the only format this encoder supports. +func cosmosIntEncoder(_ *Encoder, v protoreflect.Value, w io.Writer) error { + switch val := v.Interface().(type) { + case string: + if val == "" { + return jsonMarshal(w, "0") + } + return jsonMarshal(w, val) + case []byte: + if len(val) == 0 { + return jsonMarshal(w, "0") + } + var i math.Int + err := i.Unmarshal(val) + if err != nil { + return err + } + return jsonMarshal(w, i.String()) + default: + return fmt.Errorf("unsupported type %T", val) + } +} + +// cosmosDecEncoder provides legacy compatible encoding for cosmos.Dec and cosmos.Int types. These are sometimes +// represented as strings in pulsar messages and sometimes as bytes. This encoder handles both cases. +func cosmosDecEncoder(_ *Encoder, v protoreflect.Value, w io.Writer) error { + switch val := v.Interface().(type) { + case string: + if val == "" { + return jsonMarshal(w, "0") + } + return jsonMarshal(w, val) + case []byte: + if len(val) == 0 { + return jsonMarshal(w, "0") + } + var dec math.LegacyDec + err := dec.Unmarshal(val) + if err != nil { + return err + } + return jsonMarshal(w, dec.String()) + default: + return fmt.Errorf("unsupported type %T", val) + } +} + +// nullSliceAsEmptyEncoder replicates the behavior at: +// https://github.com/cosmos/cosmos-sdk/blob/be9bd7a8c1b41b115d58f4e76ee358e18a52c0af/types/coin.go#L199-L205 +func nullSliceAsEmptyEncoder(enc *Encoder, v protoreflect.Value, w io.Writer) error { + switch list := v.Interface().(type) { + case protoreflect.List: + if list.Len() == 0 { + _, err := w.Write([]byte("[]")) + return err + } + return enc.marshalList(list, w) + default: + return fmt.Errorf("unsupported type %T", list) + } +} + +// keyFieldEncoder replicates the behavior at described at: +// https://github.com/cosmos/cosmos-sdk/blob/b49f948b36bc991db5be431607b475633aed697e/proto/cosmos/crypto/secp256k1/keys.proto#L16 +// The message is treated if it were bytes directly without the key field specified. +func keyFieldEncoder(_ *Encoder, msg protoreflect.Message, w io.Writer) error { + keyField := msg.Descriptor().Fields().ByName("key") + if keyField == nil { + return errors.New(`message encoder for key_field: no field named "key" found`) + } + + bz := msg.Get(keyField).Bytes() + + if len(bz) == 0 { + _, err := fmt.Fprint(w, "null") + return err + } + + _, err := fmt.Fprintf(w, `"%s"`, base64.StdEncoding.EncodeToString(bz)) + return err + +} + +type moduleAccountPretty struct { + Address string `json:"address"` + PubKey string `json:"public_key"` + AccountNumber uint64 `json:"account_number"` + Sequence uint64 `json:"sequence"` + Name string `json:"name"` + Permissions []string `json:"permissions"` +} + +// moduleAccountEncoder replicates the behavior in +// https://github.com/cosmos/cosmos-sdk/blob/41a3dfeced2953beba3a7d11ec798d17ee19f506/x/auth/types/account.go#L230-L254 +func moduleAccountEncoder(_ *Encoder, msg protoreflect.Message, w io.Writer) error { + ma := msg.Interface().(*authapi.ModuleAccount) + pretty := moduleAccountPretty{ + PubKey: "", + Name: ma.Name, + Permissions: ma.Permissions, + } + if ma.BaseAccount != nil { + pretty.Address = ma.BaseAccount.Address + pretty.AccountNumber = ma.BaseAccount.AccountNumber + pretty.Sequence = ma.BaseAccount.Sequence + } else { + pretty.Address = "" + pretty.AccountNumber = 0 + pretty.Sequence = 0 + } + + bz, err := json.Marshal(pretty) + if err != nil { + return err + } + _, err = w.Write(bz) + return err +} + +// thresholdStringEncoder replicates the behavior at: +// https://github.com/cosmos/cosmos-sdk/blob/4a6a1e3cb8de459891cb0495052589673d14ef51/crypto/keys/multisig/amino.go#L35 +// also see: +// https://github.com/cosmos/cosmos-sdk/blob/b49f948b36bc991db5be431607b475633aed697e/proto/cosmos/crypto/multisig/keys.proto#L15/ +func thresholdStringEncoder(enc *Encoder, msg protoreflect.Message, w io.Writer) error { + pk, ok := msg.Interface().(*multisig.LegacyAminoPubKey) + if !ok { + return errors.New("thresholdStringEncoder: msg not a multisig.LegacyAminoPubKey") + } + _, err := w.Write([]byte(fmt.Sprintf(`{"threshold":"%d","pubkeys":`, pk.Threshold))) + if err != nil { + return err + } + + if len(pk.PublicKeys) == 0 { + _, err = w.Write([]byte(`[]}`)) + return err + } + + fields := msg.Descriptor().Fields() + pubkeysField := fields.ByName("public_keys") + pubkeys := msg.Get(pubkeysField).List() + + err = enc.marshalList(pubkeys, w) + if err != nil { + return err + } + _, err = w.Write([]byte(`}`)) + return err +} diff --git a/x/tx/aminojson/internal/Makefile b/x/tx/aminojson/internal/Makefile new file mode 100644 index 000000000000..cb1280a5c1f9 --- /dev/null +++ b/x/tx/aminojson/internal/Makefile @@ -0,0 +1,3 @@ +codegen: + @echo "Generating proto files" + buf generate \ No newline at end of file diff --git a/x/tx/aminojson/internal/buf.gen.yaml b/x/tx/aminojson/internal/buf.gen.yaml new file mode 100644 index 000000000000..86deca27ec11 --- /dev/null +++ b/x/tx/aminojson/internal/buf.gen.yaml @@ -0,0 +1,15 @@ +version: v1 +managed: + enabled: true + go_package_prefix: + default: cosmossdk.io/x/tx/aminojson/internal/testpb + except: + - buf.build/googleapis/googleapis + - buf.build/cosmos/gogo-proto + - buf.build/cosmos/cosmos-proto + override: + buf.build/cosmos/cosmos-sdk: cosmossdk.io/api +plugins: + - name: go-pulsar + out: . + opt: paths=source_relative diff --git a/x/tx/aminojson/internal/buf.lock b/x/tx/aminojson/internal/buf.lock new file mode 100644 index 000000000000..4dd297e431c1 --- /dev/null +++ b/x/tx/aminojson/internal/buf.lock @@ -0,0 +1,7 @@ +# Generated by buf. DO NOT EDIT. +version: v1 +deps: + - remote: buf.build + owner: cosmos + repository: cosmos-proto + commit: 1935555c206d4afb9e94615dfd0fad31 diff --git a/x/tx/aminojson/internal/buf.yaml b/x/tx/aminojson/internal/buf.yaml new file mode 100644 index 000000000000..2016baa2a8d7 --- /dev/null +++ b/x/tx/aminojson/internal/buf.yaml @@ -0,0 +1,11 @@ +version: v1 +deps: + - buf.build/cosmos/cosmos-proto +lint: + use: + - DEFAULT + except: + - PACKAGE_VERSION_SUFFIX +breaking: + ignore: + - testpb diff --git a/x/tx/aminojson/internal/testpb/test.proto b/x/tx/aminojson/internal/testpb/test.proto new file mode 100644 index 000000000000..479436f1c4da --- /dev/null +++ b/x/tx/aminojson/internal/testpb/test.proto @@ -0,0 +1,76 @@ +syntax = "proto3"; + +package testpb; + +import "amino/amino.proto"; +import "google/protobuf/any.proto"; +import "google/protobuf/timestamp.proto"; +import "google/protobuf/duration.proto"; +import "google/protobuf/struct.proto"; +import "google/protobuf/wrappers.proto"; +import "google/protobuf/field_mask.proto"; +import "google/protobuf/empty.proto"; + +message WithAMap{ + map str_map = 1; +} + +message WithAList{ + repeated string dont_omitempty_list = 1 [ (amino.dont_omitempty) = true ]; + repeated string list = 2; +} + +message ABitOfEverything { + option (amino.name) = "ABitOfEverything"; + + NestedMessage message = 1; + AnEnum enum = 2; + + repeated int32 repeated = 6; + + string str = 7; + bool bool = 8; + bytes bytes = 9; + int32 i32 = 10; + fixed32 f32 = 11; + uint32 u32 = 12; + sint32 si32 = 13; + sfixed32 sf32 = 14; + int64 i64 = 15; + fixed64 f64 = 16; + uint64 u64 = 17; + sint64 si64 = 18; + sfixed64 sf64 = 19; + + // The following types are not tested here because they are treated fundamentally differently in + // gogoproto. They are tested fully in /tests/integration/aminojson/aminojson_test.go + + // Any types are not tested here because they are treated fundamentally differently in gogoproto. + // In the go-admin/gogoproto paradigm a custom SDK type is used to wrap the Any type, which has no + // equivalent in code in pulsar generated types. + // + // google.protobuf.Any any = 22 + + // Also not tested due to gogoproto differences. In gogoproto, time.Time is used instead of + // google.protobuf.Timestamp. There is no equivalent in pulsar generated types. + // + // google.protobuf.Timestamp timestamp = 23; + + // Also not tested due to gogoproto differences. In gogoproto, time.Duration is used instead of + // google.protobuf.Duration. There is no equivalent in pulsar generated types. + // + // google.protobuf.Duration duration = 24; +} + +message NestedMessage { + option (amino.name) = "NestedMessage"; + + string foo = 1; + int32 bar = 2; +} + +enum AnEnum { + UNDEFINED = 0; + ONE = 1; + TWO = 2; +} \ No newline at end of file diff --git a/x/tx/aminojson/internal/testpb/test.pulsar.go b/x/tx/aminojson/internal/testpb/test.pulsar.go new file mode 100644 index 000000000000..ae8a54ee2571 --- /dev/null +++ b/x/tx/aminojson/internal/testpb/test.pulsar.go @@ -0,0 +1,3587 @@ +// Code generated by protoc-gen-go-pulsar. DO NOT EDIT. +package testpb + +import ( + _ "cosmossdk.io/api/amino" + binary "encoding/binary" + fmt "fmt" + runtime "github.com/cosmos/cosmos-proto/runtime" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoiface "google.golang.org/protobuf/runtime/protoiface" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + _ "google.golang.org/protobuf/types/known/anypb" + _ "google.golang.org/protobuf/types/known/durationpb" + _ "google.golang.org/protobuf/types/known/emptypb" + _ "google.golang.org/protobuf/types/known/fieldmaskpb" + _ "google.golang.org/protobuf/types/known/structpb" + _ "google.golang.org/protobuf/types/known/timestamppb" + _ "google.golang.org/protobuf/types/known/wrapperspb" + io "io" + reflect "reflect" + sort "sort" + sync "sync" +) + +var _ protoreflect.Map = (*_WithAMap_1_map)(nil) + +type _WithAMap_1_map struct { + m *map[string]string +} + +func (x *_WithAMap_1_map) Len() int { + if x.m == nil { + return 0 + } + return len(*x.m) +} + +func (x *_WithAMap_1_map) Range(f func(protoreflect.MapKey, protoreflect.Value) bool) { + if x.m == nil { + return + } + for k, v := range *x.m { + mapKey := (protoreflect.MapKey)(protoreflect.ValueOfString(k)) + mapValue := protoreflect.ValueOfString(v) + if !f(mapKey, mapValue) { + break + } + } +} + +func (x *_WithAMap_1_map) Has(key protoreflect.MapKey) bool { + if x.m == nil { + return false + } + keyUnwrapped := key.String() + concreteValue := keyUnwrapped + _, ok := (*x.m)[concreteValue] + return ok +} + +func (x *_WithAMap_1_map) Clear(key protoreflect.MapKey) { + if x.m == nil { + return + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + delete(*x.m, concreteKey) +} + +func (x *_WithAMap_1_map) Get(key protoreflect.MapKey) protoreflect.Value { + if x.m == nil { + return protoreflect.Value{} + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + v, ok := (*x.m)[concreteKey] + if !ok { + return protoreflect.Value{} + } + return protoreflect.ValueOfString(v) +} + +func (x *_WithAMap_1_map) Set(key protoreflect.MapKey, value protoreflect.Value) { + if !key.IsValid() || !value.IsValid() { + panic("invalid key or value provided") + } + keyUnwrapped := key.String() + concreteKey := keyUnwrapped + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + (*x.m)[concreteKey] = concreteValue +} + +func (x *_WithAMap_1_map) Mutable(key protoreflect.MapKey) protoreflect.Value { + panic("should not call Mutable on protoreflect.Map whose value is not of type protoreflect.Message") +} + +func (x *_WithAMap_1_map) NewValue() protoreflect.Value { + v := "" + return protoreflect.ValueOfString(v) +} + +func (x *_WithAMap_1_map) IsValid() bool { + return x.m != nil +} + +var ( + md_WithAMap protoreflect.MessageDescriptor + fd_WithAMap_str_map protoreflect.FieldDescriptor +) + +func init() { + file_testpb_test_proto_init() + md_WithAMap = File_testpb_test_proto.Messages().ByName("WithAMap") + fd_WithAMap_str_map = md_WithAMap.Fields().ByName("str_map") +} + +var _ protoreflect.Message = (*fastReflection_WithAMap)(nil) + +type fastReflection_WithAMap WithAMap + +func (x *WithAMap) ProtoReflect() protoreflect.Message { + return (*fastReflection_WithAMap)(x) +} + +func (x *WithAMap) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_test_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) +} + +var _fastReflection_WithAMap_messageType fastReflection_WithAMap_messageType +var _ protoreflect.MessageType = fastReflection_WithAMap_messageType{} + +type fastReflection_WithAMap_messageType struct{} + +func (x fastReflection_WithAMap_messageType) Zero() protoreflect.Message { + return (*fastReflection_WithAMap)(nil) +} +func (x fastReflection_WithAMap_messageType) New() protoreflect.Message { + return new(fastReflection_WithAMap) +} +func (x fastReflection_WithAMap_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_WithAMap +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_WithAMap) Descriptor() protoreflect.MessageDescriptor { + return md_WithAMap +} + +// 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_WithAMap) Type() protoreflect.MessageType { + return _fastReflection_WithAMap_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_WithAMap) New() protoreflect.Message { + return new(fastReflection_WithAMap) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_WithAMap) Interface() protoreflect.ProtoMessage { + return (*WithAMap)(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_WithAMap) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if len(x.StrMap) != 0 { + value := protoreflect.ValueOfMap(&_WithAMap_1_map{m: &x.StrMap}) + if !f(fd_WithAMap_str_map, 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_WithAMap) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.WithAMap.str_map": + return len(x.StrMap) != 0 + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAMap")) + } + panic(fmt.Errorf("message testpb.WithAMap 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_WithAMap) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.WithAMap.str_map": + x.StrMap = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAMap")) + } + panic(fmt.Errorf("message testpb.WithAMap 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_WithAMap) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.WithAMap.str_map": + if len(x.StrMap) == 0 { + return protoreflect.ValueOfMap(&_WithAMap_1_map{}) + } + mapValue := &_WithAMap_1_map{m: &x.StrMap} + return protoreflect.ValueOfMap(mapValue) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAMap")) + } + panic(fmt.Errorf("message testpb.WithAMap 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_WithAMap) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.WithAMap.str_map": + mv := value.Map() + cmv := mv.(*_WithAMap_1_map) + x.StrMap = *cmv.m + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAMap")) + } + panic(fmt.Errorf("message testpb.WithAMap 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_WithAMap) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.WithAMap.str_map": + if x.StrMap == nil { + x.StrMap = make(map[string]string) + } + value := &_WithAMap_1_map{m: &x.StrMap} + return protoreflect.ValueOfMap(value) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAMap")) + } + panic(fmt.Errorf("message testpb.WithAMap 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_WithAMap) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.WithAMap.str_map": + m := make(map[string]string) + return protoreflect.ValueOfMap(&_WithAMap_1_map{m: &m}) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAMap")) + } + panic(fmt.Errorf("message testpb.WithAMap 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_WithAMap) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.WithAMap", 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_WithAMap) 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_WithAMap) 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_WithAMap) 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_WithAMap) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*WithAMap) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if len(x.StrMap) > 0 { + SiZeMaP := func(k string, v string) { + mapEntrySize := 1 + len(k) + runtime.Sov(uint64(len(k))) + 1 + len(v) + runtime.Sov(uint64(len(v))) + n += mapEntrySize + 1 + runtime.Sov(uint64(mapEntrySize)) + } + if options.Deterministic { + sortme := make([]string, 0, len(x.StrMap)) + for k := range x.StrMap { + sortme = append(sortme, k) + } + sort.Strings(sortme) + for _, k := range sortme { + v := x.StrMap[k] + SiZeMaP(k, v) + } + } else { + for k, v := range x.StrMap { + SiZeMaP(k, v) + } + } + } + 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().(*WithAMap) + 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 len(x.StrMap) > 0 { + MaRsHaLmAp := func(k string, v string) (protoiface.MarshalOutput, error) { + baseI := i + i -= len(v) + copy(dAtA[i:], v) + i = runtime.EncodeVarint(dAtA, i, uint64(len(v))) + i-- + dAtA[i] = 0x12 + i -= len(k) + copy(dAtA[i:], k) + i = runtime.EncodeVarint(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = runtime.EncodeVarint(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0xa + return protoiface.MarshalOutput{}, nil + } + if options.Deterministic { + keysForStrMap := make([]string, 0, len(x.StrMap)) + for k := range x.StrMap { + keysForStrMap = append(keysForStrMap, string(k)) + } + sort.Slice(keysForStrMap, func(i, j int) bool { + return keysForStrMap[i] < keysForStrMap[j] + }) + for iNdEx := len(keysForStrMap) - 1; iNdEx >= 0; iNdEx-- { + v := x.StrMap[string(keysForStrMap[iNdEx])] + out, err := MaRsHaLmAp(keysForStrMap[iNdEx], v) + if err != nil { + return out, err + } + } + } else { + for k := range x.StrMap { + v := x.StrMap[k] + out, err := MaRsHaLmAp(k, v) + if err != nil { + return out, err + } + } + } + } + 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().(*WithAMap) + 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: WithAMap: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: WithAMap: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field StrMap", 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.StrMap == nil { + x.StrMap = make(map[string]string) + } + var mapkey string + var mapvalue string + for iNdEx < postIndex { + entryPreIndex := 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) + if fieldNum == 1 { + var stringLenmapkey 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++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postStringIndexmapkey > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var stringLenmapvalue 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++ + stringLenmapvalue |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapvalue := int(stringLenmapvalue) + if intStringLenmapvalue < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postStringIndexmapvalue := iNdEx + intStringLenmapvalue + if postStringIndexmapvalue < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + if postStringIndexmapvalue > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + mapvalue = string(dAtA[iNdEx:postStringIndexmapvalue]) + iNdEx = postStringIndexmapvalue + } else { + iNdEx = entryPreIndex + 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) > postIndex { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + x.StrMap[mapkey] = mapvalue + 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, + } +} + +var _ protoreflect.List = (*_WithAList_1_list)(nil) + +type _WithAList_1_list struct { + list *[]string +} + +func (x *_WithAList_1_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_WithAList_1_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfString((*x.list)[i]) +} + +func (x *_WithAList_1_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + (*x.list)[i] = concreteValue +} + +func (x *_WithAList_1_list) Append(value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + *x.list = append(*x.list, concreteValue) +} + +func (x *_WithAList_1_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message WithAList at list field DontOmitemptyList as it is not of Message kind")) +} + +func (x *_WithAList_1_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_WithAList_1_list) NewElement() protoreflect.Value { + v := "" + return protoreflect.ValueOfString(v) +} + +func (x *_WithAList_1_list) IsValid() bool { + return x.list != nil +} + +var _ protoreflect.List = (*_WithAList_2_list)(nil) + +type _WithAList_2_list struct { + list *[]string +} + +func (x *_WithAList_2_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_WithAList_2_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfString((*x.list)[i]) +} + +func (x *_WithAList_2_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + (*x.list)[i] = concreteValue +} + +func (x *_WithAList_2_list) Append(value protoreflect.Value) { + valueUnwrapped := value.String() + concreteValue := valueUnwrapped + *x.list = append(*x.list, concreteValue) +} + +func (x *_WithAList_2_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message WithAList at list field List as it is not of Message kind")) +} + +func (x *_WithAList_2_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_WithAList_2_list) NewElement() protoreflect.Value { + v := "" + return protoreflect.ValueOfString(v) +} + +func (x *_WithAList_2_list) IsValid() bool { + return x.list != nil +} + +var ( + md_WithAList protoreflect.MessageDescriptor + fd_WithAList_dont_omitempty_list protoreflect.FieldDescriptor + fd_WithAList_list protoreflect.FieldDescriptor +) + +func init() { + file_testpb_test_proto_init() + md_WithAList = File_testpb_test_proto.Messages().ByName("WithAList") + fd_WithAList_dont_omitempty_list = md_WithAList.Fields().ByName("dont_omitempty_list") + fd_WithAList_list = md_WithAList.Fields().ByName("list") +} + +var _ protoreflect.Message = (*fastReflection_WithAList)(nil) + +type fastReflection_WithAList WithAList + +func (x *WithAList) ProtoReflect() protoreflect.Message { + return (*fastReflection_WithAList)(x) +} + +func (x *WithAList) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_test_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) +} + +var _fastReflection_WithAList_messageType fastReflection_WithAList_messageType +var _ protoreflect.MessageType = fastReflection_WithAList_messageType{} + +type fastReflection_WithAList_messageType struct{} + +func (x fastReflection_WithAList_messageType) Zero() protoreflect.Message { + return (*fastReflection_WithAList)(nil) +} +func (x fastReflection_WithAList_messageType) New() protoreflect.Message { + return new(fastReflection_WithAList) +} +func (x fastReflection_WithAList_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_WithAList +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_WithAList) Descriptor() protoreflect.MessageDescriptor { + return md_WithAList +} + +// 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_WithAList) Type() protoreflect.MessageType { + return _fastReflection_WithAList_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_WithAList) New() protoreflect.Message { + return new(fastReflection_WithAList) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_WithAList) Interface() protoreflect.ProtoMessage { + return (*WithAList)(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_WithAList) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if len(x.DontOmitemptyList) != 0 { + value := protoreflect.ValueOfList(&_WithAList_1_list{list: &x.DontOmitemptyList}) + if !f(fd_WithAList_dont_omitempty_list, value) { + return + } + } + if len(x.List) != 0 { + value := protoreflect.ValueOfList(&_WithAList_2_list{list: &x.List}) + if !f(fd_WithAList_list, 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_WithAList) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.WithAList.dont_omitempty_list": + return len(x.DontOmitemptyList) != 0 + case "testpb.WithAList.list": + return len(x.List) != 0 + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAList")) + } + panic(fmt.Errorf("message testpb.WithAList 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_WithAList) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.WithAList.dont_omitempty_list": + x.DontOmitemptyList = nil + case "testpb.WithAList.list": + x.List = nil + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAList")) + } + panic(fmt.Errorf("message testpb.WithAList 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_WithAList) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.WithAList.dont_omitempty_list": + if len(x.DontOmitemptyList) == 0 { + return protoreflect.ValueOfList(&_WithAList_1_list{}) + } + listValue := &_WithAList_1_list{list: &x.DontOmitemptyList} + return protoreflect.ValueOfList(listValue) + case "testpb.WithAList.list": + if len(x.List) == 0 { + return protoreflect.ValueOfList(&_WithAList_2_list{}) + } + listValue := &_WithAList_2_list{list: &x.List} + return protoreflect.ValueOfList(listValue) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAList")) + } + panic(fmt.Errorf("message testpb.WithAList 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_WithAList) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.WithAList.dont_omitempty_list": + lv := value.List() + clv := lv.(*_WithAList_1_list) + x.DontOmitemptyList = *clv.list + case "testpb.WithAList.list": + lv := value.List() + clv := lv.(*_WithAList_2_list) + x.List = *clv.list + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAList")) + } + panic(fmt.Errorf("message testpb.WithAList 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_WithAList) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.WithAList.dont_omitempty_list": + if x.DontOmitemptyList == nil { + x.DontOmitemptyList = []string{} + } + value := &_WithAList_1_list{list: &x.DontOmitemptyList} + return protoreflect.ValueOfList(value) + case "testpb.WithAList.list": + if x.List == nil { + x.List = []string{} + } + value := &_WithAList_2_list{list: &x.List} + return protoreflect.ValueOfList(value) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAList")) + } + panic(fmt.Errorf("message testpb.WithAList 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_WithAList) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.WithAList.dont_omitempty_list": + list := []string{} + return protoreflect.ValueOfList(&_WithAList_1_list{list: &list}) + case "testpb.WithAList.list": + list := []string{} + return protoreflect.ValueOfList(&_WithAList_2_list{list: &list}) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.WithAList")) + } + panic(fmt.Errorf("message testpb.WithAList 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_WithAList) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.WithAList", 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_WithAList) 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_WithAList) 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_WithAList) 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_WithAList) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*WithAList) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + if len(x.DontOmitemptyList) > 0 { + for _, s := range x.DontOmitemptyList { + l = len(s) + n += 1 + l + runtime.Sov(uint64(l)) + } + } + if len(x.List) > 0 { + for _, s := range x.List { + l = len(s) + 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().(*WithAList) + 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 len(x.List) > 0 { + for iNdEx := len(x.List) - 1; iNdEx >= 0; iNdEx-- { + i -= len(x.List[iNdEx]) + copy(dAtA[i:], x.List[iNdEx]) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.List[iNdEx]))) + i-- + dAtA[i] = 0x12 + } + } + if len(x.DontOmitemptyList) > 0 { + for iNdEx := len(x.DontOmitemptyList) - 1; iNdEx >= 0; iNdEx-- { + i -= len(x.DontOmitemptyList[iNdEx]) + copy(dAtA[i:], x.DontOmitemptyList[iNdEx]) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.DontOmitemptyList[iNdEx]))) + i-- + dAtA[i] = 0xa + } + } + 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().(*WithAList) + 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: WithAList: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: WithAList: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field DontOmitemptyList", 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.DontOmitemptyList = append(x.DontOmitemptyList, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 2: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field List", 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.List = append(x.List, string(dAtA[iNdEx:postIndex])) + 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, + } +} + +var _ protoreflect.List = (*_ABitOfEverything_6_list)(nil) + +type _ABitOfEverything_6_list struct { + list *[]int32 +} + +func (x *_ABitOfEverything_6_list) Len() int { + if x.list == nil { + return 0 + } + return len(*x.list) +} + +func (x *_ABitOfEverything_6_list) Get(i int) protoreflect.Value { + return protoreflect.ValueOfInt32((*x.list)[i]) +} + +func (x *_ABitOfEverything_6_list) Set(i int, value protoreflect.Value) { + valueUnwrapped := value.Int() + concreteValue := (int32)(valueUnwrapped) + (*x.list)[i] = concreteValue +} + +func (x *_ABitOfEverything_6_list) Append(value protoreflect.Value) { + valueUnwrapped := value.Int() + concreteValue := (int32)(valueUnwrapped) + *x.list = append(*x.list, concreteValue) +} + +func (x *_ABitOfEverything_6_list) AppendMutable() protoreflect.Value { + panic(fmt.Errorf("AppendMutable can not be called on message ABitOfEverything at list field Repeated as it is not of Message kind")) +} + +func (x *_ABitOfEverything_6_list) Truncate(n int) { + *x.list = (*x.list)[:n] +} + +func (x *_ABitOfEverything_6_list) NewElement() protoreflect.Value { + v := int32(0) + return protoreflect.ValueOfInt32(v) +} + +func (x *_ABitOfEverything_6_list) IsValid() bool { + return x.list != nil +} + +var ( + md_ABitOfEverything protoreflect.MessageDescriptor + fd_ABitOfEverything_message protoreflect.FieldDescriptor + fd_ABitOfEverything_enum protoreflect.FieldDescriptor + fd_ABitOfEverything_repeated protoreflect.FieldDescriptor + fd_ABitOfEverything_str protoreflect.FieldDescriptor + fd_ABitOfEverything_bool protoreflect.FieldDescriptor + fd_ABitOfEverything_bytes protoreflect.FieldDescriptor + fd_ABitOfEverything_i32 protoreflect.FieldDescriptor + fd_ABitOfEverything_f32 protoreflect.FieldDescriptor + fd_ABitOfEverything_u32 protoreflect.FieldDescriptor + fd_ABitOfEverything_si32 protoreflect.FieldDescriptor + fd_ABitOfEverything_sf32 protoreflect.FieldDescriptor + fd_ABitOfEverything_i64 protoreflect.FieldDescriptor + fd_ABitOfEverything_f64 protoreflect.FieldDescriptor + fd_ABitOfEverything_u64 protoreflect.FieldDescriptor + fd_ABitOfEverything_si64 protoreflect.FieldDescriptor + fd_ABitOfEverything_sf64 protoreflect.FieldDescriptor +) + +func init() { + file_testpb_test_proto_init() + md_ABitOfEverything = File_testpb_test_proto.Messages().ByName("ABitOfEverything") + fd_ABitOfEverything_message = md_ABitOfEverything.Fields().ByName("message") + fd_ABitOfEverything_enum = md_ABitOfEverything.Fields().ByName("enum") + fd_ABitOfEverything_repeated = md_ABitOfEverything.Fields().ByName("repeated") + fd_ABitOfEverything_str = md_ABitOfEverything.Fields().ByName("str") + fd_ABitOfEverything_bool = md_ABitOfEverything.Fields().ByName("bool") + fd_ABitOfEverything_bytes = md_ABitOfEverything.Fields().ByName("bytes") + fd_ABitOfEverything_i32 = md_ABitOfEverything.Fields().ByName("i32") + fd_ABitOfEverything_f32 = md_ABitOfEverything.Fields().ByName("f32") + fd_ABitOfEverything_u32 = md_ABitOfEverything.Fields().ByName("u32") + fd_ABitOfEverything_si32 = md_ABitOfEverything.Fields().ByName("si32") + fd_ABitOfEverything_sf32 = md_ABitOfEverything.Fields().ByName("sf32") + fd_ABitOfEverything_i64 = md_ABitOfEverything.Fields().ByName("i64") + fd_ABitOfEverything_f64 = md_ABitOfEverything.Fields().ByName("f64") + fd_ABitOfEverything_u64 = md_ABitOfEverything.Fields().ByName("u64") + fd_ABitOfEverything_si64 = md_ABitOfEverything.Fields().ByName("si64") + fd_ABitOfEverything_sf64 = md_ABitOfEverything.Fields().ByName("sf64") +} + +var _ protoreflect.Message = (*fastReflection_ABitOfEverything)(nil) + +type fastReflection_ABitOfEverything ABitOfEverything + +func (x *ABitOfEverything) ProtoReflect() protoreflect.Message { + return (*fastReflection_ABitOfEverything)(x) +} + +func (x *ABitOfEverything) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_test_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) +} + +var _fastReflection_ABitOfEverything_messageType fastReflection_ABitOfEverything_messageType +var _ protoreflect.MessageType = fastReflection_ABitOfEverything_messageType{} + +type fastReflection_ABitOfEverything_messageType struct{} + +func (x fastReflection_ABitOfEverything_messageType) Zero() protoreflect.Message { + return (*fastReflection_ABitOfEverything)(nil) +} +func (x fastReflection_ABitOfEverything_messageType) New() protoreflect.Message { + return new(fastReflection_ABitOfEverything) +} +func (x fastReflection_ABitOfEverything_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_ABitOfEverything +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_ABitOfEverything) Descriptor() protoreflect.MessageDescriptor { + return md_ABitOfEverything +} + +// 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_ABitOfEverything) Type() protoreflect.MessageType { + return _fastReflection_ABitOfEverything_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_ABitOfEverything) New() protoreflect.Message { + return new(fastReflection_ABitOfEverything) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_ABitOfEverything) Interface() protoreflect.ProtoMessage { + return (*ABitOfEverything)(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_ABitOfEverything) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Message != nil { + value := protoreflect.ValueOfMessage(x.Message.ProtoReflect()) + if !f(fd_ABitOfEverything_message, value) { + return + } + } + if x.Enum != 0 { + value := protoreflect.ValueOfEnum((protoreflect.EnumNumber)(x.Enum)) + if !f(fd_ABitOfEverything_enum, value) { + return + } + } + if len(x.Repeated) != 0 { + value := protoreflect.ValueOfList(&_ABitOfEverything_6_list{list: &x.Repeated}) + if !f(fd_ABitOfEverything_repeated, value) { + return + } + } + if x.Str != "" { + value := protoreflect.ValueOfString(x.Str) + if !f(fd_ABitOfEverything_str, value) { + return + } + } + if x.Bool != false { + value := protoreflect.ValueOfBool(x.Bool) + if !f(fd_ABitOfEverything_bool, value) { + return + } + } + if len(x.Bytes) != 0 { + value := protoreflect.ValueOfBytes(x.Bytes) + if !f(fd_ABitOfEverything_bytes, value) { + return + } + } + if x.I32 != int32(0) { + value := protoreflect.ValueOfInt32(x.I32) + if !f(fd_ABitOfEverything_i32, value) { + return + } + } + if x.F32 != uint32(0) { + value := protoreflect.ValueOfUint32(x.F32) + if !f(fd_ABitOfEverything_f32, value) { + return + } + } + if x.U32 != uint32(0) { + value := protoreflect.ValueOfUint32(x.U32) + if !f(fd_ABitOfEverything_u32, value) { + return + } + } + if x.Si32 != int32(0) { + value := protoreflect.ValueOfInt32(x.Si32) + if !f(fd_ABitOfEverything_si32, value) { + return + } + } + if x.Sf32 != int32(0) { + value := protoreflect.ValueOfInt32(x.Sf32) + if !f(fd_ABitOfEverything_sf32, value) { + return + } + } + if x.I64 != int64(0) { + value := protoreflect.ValueOfInt64(x.I64) + if !f(fd_ABitOfEverything_i64, value) { + return + } + } + if x.F64 != uint64(0) { + value := protoreflect.ValueOfUint64(x.F64) + if !f(fd_ABitOfEverything_f64, value) { + return + } + } + if x.U64 != uint64(0) { + value := protoreflect.ValueOfUint64(x.U64) + if !f(fd_ABitOfEverything_u64, value) { + return + } + } + if x.Si64 != int64(0) { + value := protoreflect.ValueOfInt64(x.Si64) + if !f(fd_ABitOfEverything_si64, value) { + return + } + } + if x.Sf64 != int64(0) { + value := protoreflect.ValueOfInt64(x.Sf64) + if !f(fd_ABitOfEverything_sf64, 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_ABitOfEverything) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.ABitOfEverything.message": + return x.Message != nil + case "testpb.ABitOfEverything.enum": + return x.Enum != 0 + case "testpb.ABitOfEverything.repeated": + return len(x.Repeated) != 0 + case "testpb.ABitOfEverything.str": + return x.Str != "" + case "testpb.ABitOfEverything.bool": + return x.Bool != false + case "testpb.ABitOfEverything.bytes": + return len(x.Bytes) != 0 + case "testpb.ABitOfEverything.i32": + return x.I32 != int32(0) + case "testpb.ABitOfEverything.f32": + return x.F32 != uint32(0) + case "testpb.ABitOfEverything.u32": + return x.U32 != uint32(0) + case "testpb.ABitOfEverything.si32": + return x.Si32 != int32(0) + case "testpb.ABitOfEverything.sf32": + return x.Sf32 != int32(0) + case "testpb.ABitOfEverything.i64": + return x.I64 != int64(0) + case "testpb.ABitOfEverything.f64": + return x.F64 != uint64(0) + case "testpb.ABitOfEverything.u64": + return x.U64 != uint64(0) + case "testpb.ABitOfEverything.si64": + return x.Si64 != int64(0) + case "testpb.ABitOfEverything.sf64": + return x.Sf64 != int64(0) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ABitOfEverything")) + } + panic(fmt.Errorf("message testpb.ABitOfEverything 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_ABitOfEverything) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.ABitOfEverything.message": + x.Message = nil + case "testpb.ABitOfEverything.enum": + x.Enum = 0 + case "testpb.ABitOfEverything.repeated": + x.Repeated = nil + case "testpb.ABitOfEverything.str": + x.Str = "" + case "testpb.ABitOfEverything.bool": + x.Bool = false + case "testpb.ABitOfEverything.bytes": + x.Bytes = nil + case "testpb.ABitOfEverything.i32": + x.I32 = int32(0) + case "testpb.ABitOfEverything.f32": + x.F32 = uint32(0) + case "testpb.ABitOfEverything.u32": + x.U32 = uint32(0) + case "testpb.ABitOfEverything.si32": + x.Si32 = int32(0) + case "testpb.ABitOfEverything.sf32": + x.Sf32 = int32(0) + case "testpb.ABitOfEverything.i64": + x.I64 = int64(0) + case "testpb.ABitOfEverything.f64": + x.F64 = uint64(0) + case "testpb.ABitOfEverything.u64": + x.U64 = uint64(0) + case "testpb.ABitOfEverything.si64": + x.Si64 = int64(0) + case "testpb.ABitOfEverything.sf64": + x.Sf64 = int64(0) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ABitOfEverything")) + } + panic(fmt.Errorf("message testpb.ABitOfEverything 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_ABitOfEverything) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.ABitOfEverything.message": + value := x.Message + return protoreflect.ValueOfMessage(value.ProtoReflect()) + case "testpb.ABitOfEverything.enum": + value := x.Enum + return protoreflect.ValueOfEnum((protoreflect.EnumNumber)(value)) + case "testpb.ABitOfEverything.repeated": + if len(x.Repeated) == 0 { + return protoreflect.ValueOfList(&_ABitOfEverything_6_list{}) + } + listValue := &_ABitOfEverything_6_list{list: &x.Repeated} + return protoreflect.ValueOfList(listValue) + case "testpb.ABitOfEverything.str": + value := x.Str + return protoreflect.ValueOfString(value) + case "testpb.ABitOfEverything.bool": + value := x.Bool + return protoreflect.ValueOfBool(value) + case "testpb.ABitOfEverything.bytes": + value := x.Bytes + return protoreflect.ValueOfBytes(value) + case "testpb.ABitOfEverything.i32": + value := x.I32 + return protoreflect.ValueOfInt32(value) + case "testpb.ABitOfEverything.f32": + value := x.F32 + return protoreflect.ValueOfUint32(value) + case "testpb.ABitOfEverything.u32": + value := x.U32 + return protoreflect.ValueOfUint32(value) + case "testpb.ABitOfEverything.si32": + value := x.Si32 + return protoreflect.ValueOfInt32(value) + case "testpb.ABitOfEverything.sf32": + value := x.Sf32 + return protoreflect.ValueOfInt32(value) + case "testpb.ABitOfEverything.i64": + value := x.I64 + return protoreflect.ValueOfInt64(value) + case "testpb.ABitOfEverything.f64": + value := x.F64 + return protoreflect.ValueOfUint64(value) + case "testpb.ABitOfEverything.u64": + value := x.U64 + return protoreflect.ValueOfUint64(value) + case "testpb.ABitOfEverything.si64": + value := x.Si64 + return protoreflect.ValueOfInt64(value) + case "testpb.ABitOfEverything.sf64": + value := x.Sf64 + return protoreflect.ValueOfInt64(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ABitOfEverything")) + } + panic(fmt.Errorf("message testpb.ABitOfEverything 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_ABitOfEverything) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.ABitOfEverything.message": + x.Message = value.Message().Interface().(*NestedMessage) + case "testpb.ABitOfEverything.enum": + x.Enum = (AnEnum)(value.Enum()) + case "testpb.ABitOfEverything.repeated": + lv := value.List() + clv := lv.(*_ABitOfEverything_6_list) + x.Repeated = *clv.list + case "testpb.ABitOfEverything.str": + x.Str = value.Interface().(string) + case "testpb.ABitOfEverything.bool": + x.Bool = value.Bool() + case "testpb.ABitOfEverything.bytes": + x.Bytes = value.Bytes() + case "testpb.ABitOfEverything.i32": + x.I32 = int32(value.Int()) + case "testpb.ABitOfEverything.f32": + x.F32 = uint32(value.Uint()) + case "testpb.ABitOfEverything.u32": + x.U32 = uint32(value.Uint()) + case "testpb.ABitOfEverything.si32": + x.Si32 = int32(value.Int()) + case "testpb.ABitOfEverything.sf32": + x.Sf32 = int32(value.Int()) + case "testpb.ABitOfEverything.i64": + x.I64 = value.Int() + case "testpb.ABitOfEverything.f64": + x.F64 = value.Uint() + case "testpb.ABitOfEverything.u64": + x.U64 = value.Uint() + case "testpb.ABitOfEverything.si64": + x.Si64 = value.Int() + case "testpb.ABitOfEverything.sf64": + x.Sf64 = value.Int() + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ABitOfEverything")) + } + panic(fmt.Errorf("message testpb.ABitOfEverything 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_ABitOfEverything) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.ABitOfEverything.message": + if x.Message == nil { + x.Message = new(NestedMessage) + } + return protoreflect.ValueOfMessage(x.Message.ProtoReflect()) + case "testpb.ABitOfEverything.repeated": + if x.Repeated == nil { + x.Repeated = []int32{} + } + value := &_ABitOfEverything_6_list{list: &x.Repeated} + return protoreflect.ValueOfList(value) + case "testpb.ABitOfEverything.enum": + panic(fmt.Errorf("field enum of message testpb.ABitOfEverything is not mutable")) + case "testpb.ABitOfEverything.str": + panic(fmt.Errorf("field str of message testpb.ABitOfEverything is not mutable")) + case "testpb.ABitOfEverything.bool": + panic(fmt.Errorf("field bool of message testpb.ABitOfEverything is not mutable")) + case "testpb.ABitOfEverything.bytes": + panic(fmt.Errorf("field bytes of message testpb.ABitOfEverything is not mutable")) + case "testpb.ABitOfEverything.i32": + panic(fmt.Errorf("field i32 of message testpb.ABitOfEverything is not mutable")) + case "testpb.ABitOfEverything.f32": + panic(fmt.Errorf("field f32 of message testpb.ABitOfEverything is not mutable")) + case "testpb.ABitOfEverything.u32": + panic(fmt.Errorf("field u32 of message testpb.ABitOfEverything is not mutable")) + case "testpb.ABitOfEverything.si32": + panic(fmt.Errorf("field si32 of message testpb.ABitOfEverything is not mutable")) + case "testpb.ABitOfEverything.sf32": + panic(fmt.Errorf("field sf32 of message testpb.ABitOfEverything is not mutable")) + case "testpb.ABitOfEverything.i64": + panic(fmt.Errorf("field i64 of message testpb.ABitOfEverything is not mutable")) + case "testpb.ABitOfEverything.f64": + panic(fmt.Errorf("field f64 of message testpb.ABitOfEverything is not mutable")) + case "testpb.ABitOfEverything.u64": + panic(fmt.Errorf("field u64 of message testpb.ABitOfEverything is not mutable")) + case "testpb.ABitOfEverything.si64": + panic(fmt.Errorf("field si64 of message testpb.ABitOfEverything is not mutable")) + case "testpb.ABitOfEverything.sf64": + panic(fmt.Errorf("field sf64 of message testpb.ABitOfEverything is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ABitOfEverything")) + } + panic(fmt.Errorf("message testpb.ABitOfEverything 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_ABitOfEverything) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.ABitOfEverything.message": + m := new(NestedMessage) + return protoreflect.ValueOfMessage(m.ProtoReflect()) + case "testpb.ABitOfEverything.enum": + return protoreflect.ValueOfEnum(0) + case "testpb.ABitOfEverything.repeated": + list := []int32{} + return protoreflect.ValueOfList(&_ABitOfEverything_6_list{list: &list}) + case "testpb.ABitOfEverything.str": + return protoreflect.ValueOfString("") + case "testpb.ABitOfEverything.bool": + return protoreflect.ValueOfBool(false) + case "testpb.ABitOfEverything.bytes": + return protoreflect.ValueOfBytes(nil) + case "testpb.ABitOfEverything.i32": + return protoreflect.ValueOfInt32(int32(0)) + case "testpb.ABitOfEverything.f32": + return protoreflect.ValueOfUint32(uint32(0)) + case "testpb.ABitOfEverything.u32": + return protoreflect.ValueOfUint32(uint32(0)) + case "testpb.ABitOfEverything.si32": + return protoreflect.ValueOfInt32(int32(0)) + case "testpb.ABitOfEverything.sf32": + return protoreflect.ValueOfInt32(int32(0)) + case "testpb.ABitOfEverything.i64": + return protoreflect.ValueOfInt64(int64(0)) + case "testpb.ABitOfEverything.f64": + return protoreflect.ValueOfUint64(uint64(0)) + case "testpb.ABitOfEverything.u64": + return protoreflect.ValueOfUint64(uint64(0)) + case "testpb.ABitOfEverything.si64": + return protoreflect.ValueOfInt64(int64(0)) + case "testpb.ABitOfEverything.sf64": + return protoreflect.ValueOfInt64(int64(0)) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.ABitOfEverything")) + } + panic(fmt.Errorf("message testpb.ABitOfEverything 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_ABitOfEverything) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.ABitOfEverything", 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_ABitOfEverything) 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_ABitOfEverything) 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_ABitOfEverything) 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_ABitOfEverything) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*ABitOfEverything) + 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.Message != nil { + l = options.Size(x.Message) + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.Enum != 0 { + n += 1 + runtime.Sov(uint64(x.Enum)) + } + if len(x.Repeated) > 0 { + l = 0 + for _, e := range x.Repeated { + l += runtime.Sov(uint64(e)) + } + n += 1 + runtime.Sov(uint64(l)) + l + } + l = len(x.Str) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.Bool { + n += 2 + } + l = len(x.Bytes) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.I32 != 0 { + n += 1 + runtime.Sov(uint64(x.I32)) + } + if x.F32 != 0 { + n += 5 + } + if x.U32 != 0 { + n += 1 + runtime.Sov(uint64(x.U32)) + } + if x.Si32 != 0 { + n += 1 + runtime.Soz(uint64(x.Si32)) + } + if x.Sf32 != 0 { + n += 5 + } + if x.I64 != 0 { + n += 1 + runtime.Sov(uint64(x.I64)) + } + if x.F64 != 0 { + n += 10 + } + if x.U64 != 0 { + n += 2 + runtime.Sov(uint64(x.U64)) + } + if x.Si64 != 0 { + n += 2 + runtime.Soz(uint64(x.Si64)) + } + if x.Sf64 != 0 { + n += 10 + } + 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().(*ABitOfEverything) + 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.Sf64 != 0 { + i -= 8 + binary.LittleEndian.PutUint64(dAtA[i:], uint64(x.Sf64)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x99 + } + if x.Si64 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64((uint64(x.Si64)<<1)^uint64((x.Si64>>63)))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x90 + } + if x.U64 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.U64)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x88 + } + if x.F64 != 0 { + i -= 8 + binary.LittleEndian.PutUint64(dAtA[i:], uint64(x.F64)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x81 + } + if x.I64 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.I64)) + i-- + dAtA[i] = 0x78 + } + if x.Sf32 != 0 { + i -= 4 + binary.LittleEndian.PutUint32(dAtA[i:], uint32(x.Sf32)) + i-- + dAtA[i] = 0x75 + } + if x.Si32 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64((uint32(x.Si32)<<1)^uint32((x.Si32>>31)))) + i-- + dAtA[i] = 0x68 + } + if x.U32 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.U32)) + i-- + dAtA[i] = 0x60 + } + if x.F32 != 0 { + i -= 4 + binary.LittleEndian.PutUint32(dAtA[i:], uint32(x.F32)) + i-- + dAtA[i] = 0x5d + } + if x.I32 != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.I32)) + i-- + dAtA[i] = 0x50 + } + if len(x.Bytes) > 0 { + i -= len(x.Bytes) + copy(dAtA[i:], x.Bytes) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Bytes))) + i-- + dAtA[i] = 0x4a + } + if x.Bool { + i-- + if x.Bool { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x40 + } + if len(x.Str) > 0 { + i -= len(x.Str) + copy(dAtA[i:], x.Str) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Str))) + i-- + dAtA[i] = 0x3a + } + if len(x.Repeated) > 0 { + var pksize2 int + for _, num := range x.Repeated { + pksize2 += runtime.Sov(uint64(num)) + } + i -= pksize2 + j1 := i + for _, num1 := range x.Repeated { + num := uint64(num1) + for num >= 1<<7 { + dAtA[j1] = uint8(uint64(num)&0x7f | 0x80) + num >>= 7 + j1++ + } + dAtA[j1] = uint8(num) + j1++ + } + i = runtime.EncodeVarint(dAtA, i, uint64(pksize2)) + i-- + dAtA[i] = 0x32 + } + if x.Enum != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.Enum)) + i-- + dAtA[i] = 0x10 + } + if x.Message != nil { + encoded, err := options.Marshal(x.Message) + 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] = 0xa + } + 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().(*ABitOfEverything) + 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: ABitOfEverything: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: ABitOfEverything: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Message", 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.Message == nil { + x.Message = &NestedMessage{} + } + if err := options.Unmarshal(dAtA[iNdEx:postIndex], x.Message); err != nil { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Enum", wireType) + } + x.Enum = 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.Enum |= AnEnum(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType == 0 { + var v int32 + 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++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Repeated = append(x.Repeated, v) + } else if wireType == 2 { + var packedLen 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++ + packedLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if packedLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + packedLen + 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 + } + var elementCount int + var count int + for _, integer := range dAtA[iNdEx:postIndex] { + if integer < 128 { + count++ + } + } + elementCount = count + if elementCount != 0 && len(x.Repeated) == 0 { + x.Repeated = make([]int32, 0, elementCount) + } + for iNdEx < postIndex { + var v int32 + 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++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Repeated = append(x.Repeated, v) + } + } else { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Repeated", wireType) + } + case 7: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Str", 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.Str = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 8: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bool", wireType) + } + var v 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++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + x.Bool = bool(v != 0) + case 9: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bytes", wireType) + } + var byteLen 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++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, runtime.ErrInvalidLength + } + postIndex := iNdEx + byteLen + 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.Bytes = append(x.Bytes[:0], dAtA[iNdEx:postIndex]...) + if x.Bytes == nil { + x.Bytes = []byte{} + } + iNdEx = postIndex + case 10: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field I32", wireType) + } + x.I32 = 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.I32 |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 11: + if wireType != 5 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field F32", wireType) + } + x.F32 = 0 + if (iNdEx + 4) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.F32 = uint32(binary.LittleEndian.Uint32(dAtA[iNdEx:])) + iNdEx += 4 + case 12: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field U32", wireType) + } + x.U32 = 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.U32 |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 13: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Si32", wireType) + } + var v int32 + 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++ + v |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31)) + x.Si32 = v + case 14: + if wireType != 5 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Sf32", wireType) + } + x.Sf32 = 0 + if (iNdEx + 4) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Sf32 = int32(binary.LittleEndian.Uint32(dAtA[iNdEx:])) + iNdEx += 4 + case 15: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field I64", wireType) + } + x.I64 = 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.I64 |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 16: + if wireType != 1 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field F64", wireType) + } + x.F64 = 0 + if (iNdEx + 8) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.F64 = uint64(binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + case 17: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field U64", wireType) + } + x.U64 = 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.U64 |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 18: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Si64", wireType) + } + var v 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++ + v |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + v = (v >> 1) ^ uint64((int64(v&1)<<63)>>63) + x.Si64 = int64(v) + case 19: + if wireType != 1 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Sf64", wireType) + } + x.Sf64 = 0 + if (iNdEx + 8) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + x.Sf64 = int64(binary.LittleEndian.Uint64(dAtA[iNdEx:])) + iNdEx += 8 + 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, + } +} + +var ( + md_NestedMessage protoreflect.MessageDescriptor + fd_NestedMessage_foo protoreflect.FieldDescriptor + fd_NestedMessage_bar protoreflect.FieldDescriptor +) + +func init() { + file_testpb_test_proto_init() + md_NestedMessage = File_testpb_test_proto.Messages().ByName("NestedMessage") + fd_NestedMessage_foo = md_NestedMessage.Fields().ByName("foo") + fd_NestedMessage_bar = md_NestedMessage.Fields().ByName("bar") +} + +var _ protoreflect.Message = (*fastReflection_NestedMessage)(nil) + +type fastReflection_NestedMessage NestedMessage + +func (x *NestedMessage) ProtoReflect() protoreflect.Message { + return (*fastReflection_NestedMessage)(x) +} + +func (x *NestedMessage) slowProtoReflect() protoreflect.Message { + mi := &file_testpb_test_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_NestedMessage_messageType fastReflection_NestedMessage_messageType +var _ protoreflect.MessageType = fastReflection_NestedMessage_messageType{} + +type fastReflection_NestedMessage_messageType struct{} + +func (x fastReflection_NestedMessage_messageType) Zero() protoreflect.Message { + return (*fastReflection_NestedMessage)(nil) +} +func (x fastReflection_NestedMessage_messageType) New() protoreflect.Message { + return new(fastReflection_NestedMessage) +} +func (x fastReflection_NestedMessage_messageType) Descriptor() protoreflect.MessageDescriptor { + return md_NestedMessage +} + +// Descriptor returns message descriptor, which contains only the protobuf +// type information for the message. +func (x *fastReflection_NestedMessage) Descriptor() protoreflect.MessageDescriptor { + return md_NestedMessage +} + +// 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_NestedMessage) Type() protoreflect.MessageType { + return _fastReflection_NestedMessage_messageType +} + +// New returns a newly allocated and mutable empty message. +func (x *fastReflection_NestedMessage) New() protoreflect.Message { + return new(fastReflection_NestedMessage) +} + +// Interface unwraps the message reflection interface and +// returns the underlying ProtoMessage interface. +func (x *fastReflection_NestedMessage) Interface() protoreflect.ProtoMessage { + return (*NestedMessage)(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_NestedMessage) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) { + if x.Foo != "" { + value := protoreflect.ValueOfString(x.Foo) + if !f(fd_NestedMessage_foo, value) { + return + } + } + if x.Bar != int32(0) { + value := protoreflect.ValueOfInt32(x.Bar) + if !f(fd_NestedMessage_bar, 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_NestedMessage) Has(fd protoreflect.FieldDescriptor) bool { + switch fd.FullName() { + case "testpb.NestedMessage.foo": + return x.Foo != "" + case "testpb.NestedMessage.bar": + return x.Bar != int32(0) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.NestedMessage")) + } + panic(fmt.Errorf("message testpb.NestedMessage 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_NestedMessage) Clear(fd protoreflect.FieldDescriptor) { + switch fd.FullName() { + case "testpb.NestedMessage.foo": + x.Foo = "" + case "testpb.NestedMessage.bar": + x.Bar = int32(0) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.NestedMessage")) + } + panic(fmt.Errorf("message testpb.NestedMessage 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_NestedMessage) Get(descriptor protoreflect.FieldDescriptor) protoreflect.Value { + switch descriptor.FullName() { + case "testpb.NestedMessage.foo": + value := x.Foo + return protoreflect.ValueOfString(value) + case "testpb.NestedMessage.bar": + value := x.Bar + return protoreflect.ValueOfInt32(value) + default: + if descriptor.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.NestedMessage")) + } + panic(fmt.Errorf("message testpb.NestedMessage 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_NestedMessage) Set(fd protoreflect.FieldDescriptor, value protoreflect.Value) { + switch fd.FullName() { + case "testpb.NestedMessage.foo": + x.Foo = value.Interface().(string) + case "testpb.NestedMessage.bar": + x.Bar = int32(value.Int()) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.NestedMessage")) + } + panic(fmt.Errorf("message testpb.NestedMessage 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_NestedMessage) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.NestedMessage.foo": + panic(fmt.Errorf("field foo of message testpb.NestedMessage is not mutable")) + case "testpb.NestedMessage.bar": + panic(fmt.Errorf("field bar of message testpb.NestedMessage is not mutable")) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.NestedMessage")) + } + panic(fmt.Errorf("message testpb.NestedMessage 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_NestedMessage) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value { + switch fd.FullName() { + case "testpb.NestedMessage.foo": + return protoreflect.ValueOfString("") + case "testpb.NestedMessage.bar": + return protoreflect.ValueOfInt32(int32(0)) + default: + if fd.IsExtension() { + panic(fmt.Errorf("proto3 declared messages do not support extensions: testpb.NestedMessage")) + } + panic(fmt.Errorf("message testpb.NestedMessage 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_NestedMessage) WhichOneof(d protoreflect.OneofDescriptor) protoreflect.FieldDescriptor { + switch d.FullName() { + default: + panic(fmt.Errorf("%s is not a oneof field in testpb.NestedMessage", 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_NestedMessage) 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_NestedMessage) 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_NestedMessage) 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_NestedMessage) ProtoMethods() *protoiface.Methods { + size := func(input protoiface.SizeInput) protoiface.SizeOutput { + x := input.Message.Interface().(*NestedMessage) + if x == nil { + return protoiface.SizeOutput{ + NoUnkeyedLiterals: input.NoUnkeyedLiterals, + Size: 0, + } + } + options := runtime.SizeInputToOptions(input) + _ = options + var n int + var l int + _ = l + l = len(x.Foo) + if l > 0 { + n += 1 + l + runtime.Sov(uint64(l)) + } + if x.Bar != 0 { + n += 1 + runtime.Sov(uint64(x.Bar)) + } + 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().(*NestedMessage) + 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.Bar != 0 { + i = runtime.EncodeVarint(dAtA, i, uint64(x.Bar)) + i-- + dAtA[i] = 0x10 + } + if len(x.Foo) > 0 { + i -= len(x.Foo) + copy(dAtA[i:], x.Foo) + i = runtime.EncodeVarint(dAtA, i, uint64(len(x.Foo))) + i-- + dAtA[i] = 0xa + } + 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().(*NestedMessage) + 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: NestedMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: NestedMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Foo", 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.Foo = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field Bar", wireType) + } + x.Bar = 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.Bar |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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) +// source: testpb/test.proto + +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 AnEnum int32 + +const ( + AnEnum_UNDEFINED AnEnum = 0 + AnEnum_ONE AnEnum = 1 + AnEnum_TWO AnEnum = 2 +) + +// Enum value maps for AnEnum. +var ( + AnEnum_name = map[int32]string{ + 0: "UNDEFINED", + 1: "ONE", + 2: "TWO", + } + AnEnum_value = map[string]int32{ + "UNDEFINED": 0, + "ONE": 1, + "TWO": 2, + } +) + +func (x AnEnum) Enum() *AnEnum { + p := new(AnEnum) + *p = x + return p +} + +func (x AnEnum) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (AnEnum) Descriptor() protoreflect.EnumDescriptor { + return file_testpb_test_proto_enumTypes[0].Descriptor() +} + +func (AnEnum) Type() protoreflect.EnumType { + return &file_testpb_test_proto_enumTypes[0] +} + +func (x AnEnum) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use AnEnum.Descriptor instead. +func (AnEnum) EnumDescriptor() ([]byte, []int) { + return file_testpb_test_proto_rawDescGZIP(), []int{0} +} + +type WithAMap struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + StrMap map[string]string `protobuf:"bytes,1,rep,name=str_map,json=strMap,proto3" json:"str_map,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *WithAMap) Reset() { + *x = WithAMap{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_test_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *WithAMap) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*WithAMap) ProtoMessage() {} + +// Deprecated: Use WithAMap.ProtoReflect.Descriptor instead. +func (*WithAMap) Descriptor() ([]byte, []int) { + return file_testpb_test_proto_rawDescGZIP(), []int{0} +} + +func (x *WithAMap) GetStrMap() map[string]string { + if x != nil { + return x.StrMap + } + return nil +} + +type WithAList struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + DontOmitemptyList []string `protobuf:"bytes,1,rep,name=dont_omitempty_list,json=dontOmitemptyList,proto3" json:"dont_omitempty_list,omitempty"` + List []string `protobuf:"bytes,2,rep,name=list,proto3" json:"list,omitempty"` +} + +func (x *WithAList) Reset() { + *x = WithAList{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_test_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *WithAList) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*WithAList) ProtoMessage() {} + +// Deprecated: Use WithAList.ProtoReflect.Descriptor instead. +func (*WithAList) Descriptor() ([]byte, []int) { + return file_testpb_test_proto_rawDescGZIP(), []int{1} +} + +func (x *WithAList) GetDontOmitemptyList() []string { + if x != nil { + return x.DontOmitemptyList + } + return nil +} + +func (x *WithAList) GetList() []string { + if x != nil { + return x.List + } + return nil +} + +type ABitOfEverything struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message *NestedMessage `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` + Enum AnEnum `protobuf:"varint,2,opt,name=enum,proto3,enum=testpb.AnEnum" json:"enum,omitempty"` + Repeated []int32 `protobuf:"varint,6,rep,packed,name=repeated,proto3" json:"repeated,omitempty"` + Str string `protobuf:"bytes,7,opt,name=str,proto3" json:"str,omitempty"` + Bool bool `protobuf:"varint,8,opt,name=bool,proto3" json:"bool,omitempty"` + Bytes []byte `protobuf:"bytes,9,opt,name=bytes,proto3" json:"bytes,omitempty"` + I32 int32 `protobuf:"varint,10,opt,name=i32,proto3" json:"i32,omitempty"` + F32 uint32 `protobuf:"fixed32,11,opt,name=f32,proto3" json:"f32,omitempty"` + U32 uint32 `protobuf:"varint,12,opt,name=u32,proto3" json:"u32,omitempty"` + Si32 int32 `protobuf:"zigzag32,13,opt,name=si32,proto3" json:"si32,omitempty"` + Sf32 int32 `protobuf:"fixed32,14,opt,name=sf32,proto3" json:"sf32,omitempty"` + I64 int64 `protobuf:"varint,15,opt,name=i64,proto3" json:"i64,omitempty"` + F64 uint64 `protobuf:"fixed64,16,opt,name=f64,proto3" json:"f64,omitempty"` + U64 uint64 `protobuf:"varint,17,opt,name=u64,proto3" json:"u64,omitempty"` + Si64 int64 `protobuf:"zigzag64,18,opt,name=si64,proto3" json:"si64,omitempty"` + Sf64 int64 `protobuf:"fixed64,19,opt,name=sf64,proto3" json:"sf64,omitempty"` +} + +func (x *ABitOfEverything) Reset() { + *x = ABitOfEverything{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_test_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ABitOfEverything) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ABitOfEverything) ProtoMessage() {} + +// Deprecated: Use ABitOfEverything.ProtoReflect.Descriptor instead. +func (*ABitOfEverything) Descriptor() ([]byte, []int) { + return file_testpb_test_proto_rawDescGZIP(), []int{2} +} + +func (x *ABitOfEverything) GetMessage() *NestedMessage { + if x != nil { + return x.Message + } + return nil +} + +func (x *ABitOfEverything) GetEnum() AnEnum { + if x != nil { + return x.Enum + } + return AnEnum_UNDEFINED +} + +func (x *ABitOfEverything) GetRepeated() []int32 { + if x != nil { + return x.Repeated + } + return nil +} + +func (x *ABitOfEverything) GetStr() string { + if x != nil { + return x.Str + } + return "" +} + +func (x *ABitOfEverything) GetBool() bool { + if x != nil { + return x.Bool + } + return false +} + +func (x *ABitOfEverything) GetBytes() []byte { + if x != nil { + return x.Bytes + } + return nil +} + +func (x *ABitOfEverything) GetI32() int32 { + if x != nil { + return x.I32 + } + return 0 +} + +func (x *ABitOfEverything) GetF32() uint32 { + if x != nil { + return x.F32 + } + return 0 +} + +func (x *ABitOfEverything) GetU32() uint32 { + if x != nil { + return x.U32 + } + return 0 +} + +func (x *ABitOfEverything) GetSi32() int32 { + if x != nil { + return x.Si32 + } + return 0 +} + +func (x *ABitOfEverything) GetSf32() int32 { + if x != nil { + return x.Sf32 + } + return 0 +} + +func (x *ABitOfEverything) GetI64() int64 { + if x != nil { + return x.I64 + } + return 0 +} + +func (x *ABitOfEverything) GetF64() uint64 { + if x != nil { + return x.F64 + } + return 0 +} + +func (x *ABitOfEverything) GetU64() uint64 { + if x != nil { + return x.U64 + } + return 0 +} + +func (x *ABitOfEverything) GetSi64() int64 { + if x != nil { + return x.Si64 + } + return 0 +} + +func (x *ABitOfEverything) GetSf64() int64 { + if x != nil { + return x.Sf64 + } + return 0 +} + +type NestedMessage struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Foo string `protobuf:"bytes,1,opt,name=foo,proto3" json:"foo,omitempty"` + Bar int32 `protobuf:"varint,2,opt,name=bar,proto3" json:"bar,omitempty"` +} + +func (x *NestedMessage) Reset() { + *x = NestedMessage{} + if protoimpl.UnsafeEnabled { + mi := &file_testpb_test_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *NestedMessage) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NestedMessage) ProtoMessage() {} + +// Deprecated: Use NestedMessage.ProtoReflect.Descriptor instead. +func (*NestedMessage) Descriptor() ([]byte, []int) { + return file_testpb_test_proto_rawDescGZIP(), []int{3} +} + +func (x *NestedMessage) GetFoo() string { + if x != nil { + return x.Foo + } + return "" +} + +func (x *NestedMessage) GetBar() int32 { + if x != nil { + return x.Bar + } + return 0 +} + +var File_testpb_test_proto protoreflect.FileDescriptor + +var file_testpb_test_proto_rawDesc = []byte{ + 0x0a, 0x11, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x06, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x1a, 0x11, 0x61, 0x6d, 0x69, + 0x6e, 0x6f, 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x19, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, + 0x61, 0x6e, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 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, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x73, 0x74, 0x72, 0x75, + 0x63, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x77, 0x72, 0x61, 0x70, 0x70, 0x65, + 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, + 0x6d, 0x61, 0x73, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, + 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x7c, 0x0a, 0x08, 0x57, 0x69, 0x74, 0x68, 0x41, + 0x4d, 0x61, 0x70, 0x12, 0x35, 0x0a, 0x07, 0x73, 0x74, 0x72, 0x5f, 0x6d, 0x61, 0x70, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x57, 0x69, + 0x74, 0x68, 0x41, 0x4d, 0x61, 0x70, 0x2e, 0x53, 0x74, 0x72, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x52, 0x06, 0x73, 0x74, 0x72, 0x4d, 0x61, 0x70, 0x1a, 0x39, 0x0a, 0x0b, 0x53, 0x74, + 0x72, 0x4d, 0x61, 0x70, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x56, 0x0a, 0x09, 0x57, 0x69, 0x74, 0x68, 0x41, 0x4c, 0x69, + 0x73, 0x74, 0x12, 0x35, 0x0a, 0x13, 0x64, 0x6f, 0x6e, 0x74, 0x5f, 0x6f, 0x6d, 0x69, 0x74, 0x65, + 0x6d, 0x70, 0x74, 0x79, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x42, + 0x05, 0xa8, 0xe7, 0xb0, 0x2a, 0x01, 0x52, 0x11, 0x64, 0x6f, 0x6e, 0x74, 0x4f, 0x6d, 0x69, 0x74, + 0x65, 0x6d, 0x70, 0x74, 0x79, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x69, 0x73, + 0x74, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x92, 0x03, + 0x0a, 0x10, 0x41, 0x42, 0x69, 0x74, 0x4f, 0x66, 0x45, 0x76, 0x65, 0x72, 0x79, 0x74, 0x68, 0x69, + 0x6e, 0x67, 0x12, 0x2f, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x4e, 0x65, 0x73, + 0x74, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x12, 0x22, 0x0a, 0x04, 0x65, 0x6e, 0x75, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0e, 0x32, 0x0e, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x6e, 0x45, 0x6e, 0x75, + 0x6d, 0x52, 0x04, 0x65, 0x6e, 0x75, 0x6d, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x70, 0x65, 0x61, + 0x74, 0x65, 0x64, 0x18, 0x06, 0x20, 0x03, 0x28, 0x05, 0x52, 0x08, 0x72, 0x65, 0x70, 0x65, 0x61, + 0x74, 0x65, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x74, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x73, 0x74, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x6f, 0x6c, 0x18, 0x08, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x04, 0x62, 0x6f, 0x6f, 0x6c, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x79, 0x74, + 0x65, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x12, + 0x10, 0x0a, 0x03, 0x69, 0x33, 0x32, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x69, 0x33, + 0x32, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x33, 0x32, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x07, 0x52, 0x03, + 0x66, 0x33, 0x32, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x33, 0x32, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x03, 0x75, 0x33, 0x32, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x33, 0x32, 0x18, 0x0d, 0x20, + 0x01, 0x28, 0x11, 0x52, 0x04, 0x73, 0x69, 0x33, 0x32, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x66, 0x33, + 0x32, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0f, 0x52, 0x04, 0x73, 0x66, 0x33, 0x32, 0x12, 0x10, 0x0a, + 0x03, 0x69, 0x36, 0x34, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x69, 0x36, 0x34, 0x12, + 0x10, 0x0a, 0x03, 0x66, 0x36, 0x34, 0x18, 0x10, 0x20, 0x01, 0x28, 0x06, 0x52, 0x03, 0x66, 0x36, + 0x34, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x36, 0x34, 0x18, 0x11, 0x20, 0x01, 0x28, 0x04, 0x52, 0x03, + 0x75, 0x36, 0x34, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x36, 0x34, 0x18, 0x12, 0x20, 0x01, 0x28, + 0x12, 0x52, 0x04, 0x73, 0x69, 0x36, 0x34, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x66, 0x36, 0x34, 0x18, + 0x13, 0x20, 0x01, 0x28, 0x10, 0x52, 0x04, 0x73, 0x66, 0x36, 0x34, 0x3a, 0x15, 0x8a, 0xe7, 0xb0, + 0x2a, 0x10, 0x41, 0x42, 0x69, 0x74, 0x4f, 0x66, 0x45, 0x76, 0x65, 0x72, 0x79, 0x74, 0x68, 0x69, + 0x6e, 0x67, 0x22, 0x47, 0x0a, 0x0d, 0x4e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 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, 0x12, 0x8a, 0xe7, 0xb0, 0x2a, 0x0d, 0x4e, 0x65, + 0x73, 0x74, 0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2a, 0x29, 0x0a, 0x06, 0x41, + 0x6e, 0x45, 0x6e, 0x75, 0x6d, 0x12, 0x0d, 0x0a, 0x09, 0x55, 0x4e, 0x44, 0x45, 0x46, 0x49, 0x4e, + 0x45, 0x44, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x4f, 0x4e, 0x45, 0x10, 0x01, 0x12, 0x07, 0x0a, + 0x03, 0x54, 0x57, 0x4f, 0x10, 0x02, 0x42, 0x83, 0x01, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x74, + 0x65, 0x73, 0x74, 0x70, 0x62, 0x42, 0x09, 0x54, 0x65, 0x73, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, + 0x50, 0x01, 0x5a, 0x32, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, + 0x2f, 0x78, 0x2f, 0x74, 0x78, 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x6a, 0x73, 0x6f, 0x6e, 0x2f, + 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x74, 0x65, 0x73, 0x74, 0x70, 0x62, 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 ( + file_testpb_test_proto_rawDescOnce sync.Once + file_testpb_test_proto_rawDescData = file_testpb_test_proto_rawDesc +) + +func file_testpb_test_proto_rawDescGZIP() []byte { + file_testpb_test_proto_rawDescOnce.Do(func() { + file_testpb_test_proto_rawDescData = protoimpl.X.CompressGZIP(file_testpb_test_proto_rawDescData) + }) + return file_testpb_test_proto_rawDescData +} + +var file_testpb_test_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_testpb_test_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_testpb_test_proto_goTypes = []interface{}{ + (AnEnum)(0), // 0: testpb.AnEnum + (*WithAMap)(nil), // 1: testpb.WithAMap + (*WithAList)(nil), // 2: testpb.WithAList + (*ABitOfEverything)(nil), // 3: testpb.ABitOfEverything + (*NestedMessage)(nil), // 4: testpb.NestedMessage + nil, // 5: testpb.WithAMap.StrMapEntry +} +var file_testpb_test_proto_depIdxs = []int32{ + 5, // 0: testpb.WithAMap.str_map:type_name -> testpb.WithAMap.StrMapEntry + 4, // 1: testpb.ABitOfEverything.message:type_name -> testpb.NestedMessage + 0, // 2: testpb.ABitOfEverything.enum:type_name -> testpb.AnEnum + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_testpb_test_proto_init() } +func file_testpb_test_proto_init() { + if File_testpb_test_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_testpb_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*WithAMap); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_test_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*WithAList); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_test_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ABitOfEverything); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_testpb_test_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*NestedMessage); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_testpb_test_proto_rawDesc, + NumEnums: 1, + NumMessages: 5, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_testpb_test_proto_goTypes, + DependencyIndexes: file_testpb_test_proto_depIdxs, + EnumInfos: file_testpb_test_proto_enumTypes, + MessageInfos: file_testpb_test_proto_msgTypes, + }.Build() + File_testpb_test_proto = out.File + file_testpb_test_proto_rawDesc = nil + file_testpb_test_proto_goTypes = nil + file_testpb_test_proto_depIdxs = nil +} diff --git a/x/tx/aminojson/json_marshal.go b/x/tx/aminojson/json_marshal.go new file mode 100644 index 000000000000..49c2e7f08cab --- /dev/null +++ b/x/tx/aminojson/json_marshal.go @@ -0,0 +1,300 @@ +package aminojson + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + + "github.com/pkg/errors" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" +) + +// MessageEncoder is a function that can encode a protobuf protoreflect.Message to JSON. +type MessageEncoder func(*Encoder, protoreflect.Message, io.Writer) error + +// FieldEncoder is a function that can encode a protobuf protoreflect.Value to JSON. +type FieldEncoder func(*Encoder, protoreflect.Value, io.Writer) error + +// Encoder is a JSON encoder that uses the Amino JSON encoding rules for protobuf messages. +type Encoder struct { + // maps cosmos_proto.scalar -> field encoder + scalarEncoders map[string]FieldEncoder + messageEncoders map[string]MessageEncoder + fieldEncoders map[string]FieldEncoder +} + +// NewAminoJSON returns a new Encoder capable of serializing protobuf messages to JSON using the Amino JSON encoding +// rules. +func NewAminoJSON() Encoder { + enc := Encoder{ + scalarEncoders: map[string]FieldEncoder{ + "cosmos.Dec": cosmosDecEncoder, + "cosmos.Int": cosmosIntEncoder, + }, + messageEncoders: map[string]MessageEncoder{ + "key_field": keyFieldEncoder, + "module_account": moduleAccountEncoder, + "threshold_string": thresholdStringEncoder, + }, + fieldEncoders: map[string]FieldEncoder{ + "legacy_coins": nullSliceAsEmptyEncoder, + "cosmos_dec_bytes": cosmosDecEncoder, + }, + } + return enc +} + +// DefineMessageEncoding defines a custom encoding for a protobuf message. The `name` field must match a usage of +// an (amino.message_encoding) option in the protobuf message as in the following example. This encoding will be +// used instead of the default encoding for all usages of the tagged message. +// +// message ModuleAccount { +// option (amino.name) = "cosmos-sdk/ModuleAccount"; +// option (amino.message_encoding) = "module_account"; +// ... +// } +func (enc Encoder) DefineMessageEncoding(name string, encoder MessageEncoder) Encoder { + if enc.messageEncoders == nil { + enc.messageEncoders = map[string]MessageEncoder{} + } + enc.messageEncoders[name] = encoder + return enc +} + +// DefineFieldEncoding defines a custom encoding for a protobuf field. The `name` field must match a usage of +// an (amino.encoding) option in the protobuf message as in the following example. This encoding will be used +// instead of the default encoding for all usages of the tagged field. +// +// message Balance { +// repeated cosmos.base.v1beta1.Coin coins = 2 [ +// (amino.encoding) = "legacy_coins", +// (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", +// (gogoproto.nullable) = false, +// (amino.dont_omitempty) = true +// ]; +// ... +// } +func (enc Encoder) DefineFieldEncoding(name string, encoder FieldEncoder) Encoder { + if enc.fieldEncoders == nil { + enc.fieldEncoders = map[string]FieldEncoder{} + } + enc.fieldEncoders[name] = encoder + return enc +} + +// Marshal serializes a protobuf message to JSON. +func (enc Encoder) Marshal(message proto.Message) ([]byte, error) { + buf := &bytes.Buffer{} + err := enc.beginMarshal(message.ProtoReflect(), buf) + return buf.Bytes(), err +} + +func (enc Encoder) beginMarshal(msg protoreflect.Message, writer io.Writer) error { + name, named := getMessageAminoName(msg) + if named { + _, err := writer.Write([]byte(fmt.Sprintf(`{"type":"%s","value":`, name))) + if err != nil { + return err + } + } + + err := enc.marshal(protoreflect.ValueOfMessage(msg), writer) + if err != nil { + return err + } + + if named { + _, err = writer.Write([]byte("}")) + if err != nil { + return err + } + } + + return nil +} + +func (enc Encoder) marshal(value protoreflect.Value, writer io.Writer) error { + switch val := value.Interface().(type) { + case protoreflect.Message: + err := enc.marshalMessage(val, writer) + return err + + case protoreflect.Map: + return errors.New("maps are not supported") + + case protoreflect.List: + if !val.IsValid() { + _, err := writer.Write([]byte("null")) + return err + } + return enc.marshalList(val, writer) + + case string, bool, int32, uint32, []byte, protoreflect.EnumNumber: + return jsonMarshal(writer, val) + + case uint64, int64: + _, err := fmt.Fprintf(writer, `"%d"`, val) // quoted + return err + + default: + return errors.Errorf("unknown type %T", val) + } +} + +func (enc Encoder) marshalMessage(msg protoreflect.Message, writer io.Writer) error { + if msg == nil { + return errors.New("nil message") + } + + switch msg.Descriptor().FullName() { + case timestampFullName: + // replicate https://github.com/tendermint/go-amino/blob/8e779b71f40d175cd1302d3cd41a75b005225a7a/json-encode.go#L45-L51 + return marshalTimestamp(msg, writer) + case durationFullName: + return marshalDuration(msg, writer) + case anyFullName: + return enc.marshalAny(msg, writer) + } + + if encoder := enc.getMessageEncoder(msg); encoder != nil { + err := encoder(&enc, msg, writer) + return err + } + + _, err := writer.Write([]byte("{")) + if err != nil { + return err + } + + fields := msg.Descriptor().Fields() + first := true + emptyOneOfWritten := map[string]bool{} + for i := 0; i < fields.Len(); i++ { + f := fields.Get(i) + v := msg.Get(f) + name := getAminoFieldName(f) + oneof := f.ContainingOneof() + isOneOf := oneof != nil + oneofFieldName, oneofTypeName, err := getOneOfNames(f) + if err != nil && isOneOf { + return err + } + writeNil := false + + if !msg.Has(f) { + // msg.WhichOneof(oneof) == nil: no field of the oneof has been set + // !emptyOneOfWritten: we haven't written a null for this oneof yet (only write one null per empty oneof) + if isOneOf && msg.WhichOneof(oneof) == nil && !emptyOneOfWritten[oneofFieldName] { + name = oneofFieldName + writeNil = true + emptyOneOfWritten[oneofFieldName] = true + } else if omitEmpty(f) { + continue + } else if f.Kind() == protoreflect.MessageKind && + f.Cardinality() != protoreflect.Repeated && + !v.Message().IsValid() { + return errors.Errorf("not supported: dont_omit_empty=true on invalid (nil?) message field: %s", name) + } + } + + if !first { + _, err = writer.Write([]byte(",")) + if err != nil { + return err + } + } + + if isOneOf && !writeNil { + _, err = writer.Write([]byte(fmt.Sprintf(`"%s":{"type":"%s","value":{`, + oneofFieldName, oneofTypeName))) + if err != nil { + return err + } + } + + err = jsonMarshal(writer, name) + if err != nil { + return err + } + + _, err = writer.Write([]byte(":")) + if err != nil { + return err + } + + // encode value + if encoder := enc.getFieldEncoding(f); encoder != nil { + err = encoder(&enc, v, writer) + if err != nil { + return err + } + } else if writeNil { + _, err = writer.Write([]byte("null")) + if err != nil { + return err + } + } else { + err = enc.marshal(v, writer) + if err != nil { + return err + } + } + + if isOneOf && !writeNil { + _, err = writer.Write([]byte("}}")) + if err != nil { + return err + } + } + + first = false + } + + _, err = writer.Write([]byte("}")) + return err +} + +func jsonMarshal(w io.Writer, v interface{}) error { + blob, err := json.Marshal(v) + if err != nil { + return err + } + _, err = w.Write(blob) + return err +} + +func (enc Encoder) marshalList(list protoreflect.List, writer io.Writer) error { + n := list.Len() + + _, err := writer.Write([]byte("[")) + if err != nil { + return err + } + + first := true + for i := 0; i < n; i++ { + if !first { + _, err := writer.Write([]byte(",")) + if err != nil { + return err + } + } + first = false + + err = enc.marshal(list.Get(i), writer) + if err != nil { + return err + } + } + + _, err = writer.Write([]byte("]")) + return err +} + +const ( + timestampFullName protoreflect.FullName = "google.protobuf.Timestamp" + durationFullName protoreflect.FullName = "google.protobuf.Duration" + anyFullName protoreflect.FullName = "google.protobuf.Any" +) diff --git a/x/tx/aminojson/json_marshal_test.go b/x/tx/aminojson/json_marshal_test.go new file mode 100644 index 000000000000..d0333de3b3a2 --- /dev/null +++ b/x/tx/aminojson/json_marshal_test.go @@ -0,0 +1,133 @@ +package aminojson_test + +import ( + "reflect" + "testing" + + "github.com/cosmos/cosmos-proto/rapidproto" + "github.com/stretchr/testify/require" + "github.com/tendermint/go-amino" + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/proto" + "pgregory.net/rapid" + + "gotest.tools/v3/assert" + + "cosmossdk.io/x/tx/aminojson" + + "cosmossdk.io/x/tx/aminojson/internal/testpb" +) + +func marshalLegacy(msg proto.Message) ([]byte, error) { + cdc := amino.NewCodec() + cdc.RegisterConcrete(&testpb.ABitOfEverything{}, "ABitOfEverything", nil) + cdc.RegisterConcrete(&testpb.NestedMessage{}, "NestedMessage", nil) + return cdc.MarshalJSON(msg) +} + +func TestAminoJSON_EdgeCases(t *testing.T) { + + cdc := amino.NewCodec() + cdc.RegisterConcrete(&testpb.ABitOfEverything{}, "ABitOfEverything", nil) + cdc.RegisterConcrete(&testpb.NestedMessage{}, "NestedMessage", nil) + aj := aminojson.NewAminoJSON() + + cases := map[string]struct { + msg proto.Message + shouldErr bool + }{ + "empty": {msg: &testpb.ABitOfEverything{}}, + "single map": {msg: &testpb.WithAMap{StrMap: map[string]string{"foo": "bar"}}, shouldErr: true}, + } + for name, tc := range cases { + t.Run(name, func(t *testing.T) { + bz, err := aj.Marshal(tc.msg) + + if tc.shouldErr { + require.Error(t, err) + return + } + + require.NoError(t, err) + + rv := reflect.New(reflect.TypeOf(tc.msg).Elem()).Elem() + msg2 := rv.Addr().Interface().(proto.Message) + + legacyBz, err := cdc.MarshalJSON(tc.msg) + assert.NilError(t, err) + + require.Equal(t, string(legacyBz), string(bz)) + + goProtoJSON, err := protojson.Marshal(tc.msg) + err = cdc.UnmarshalJSON(bz, msg2) + assert.NilError(t, err, "unmarshal failed: %s vs %s", legacyBz, goProtoJSON) + }) + } +} + +func TestAminoJSON(t *testing.T) { + cdc := amino.NewCodec() + cdc.RegisterConcrete(&testpb.ABitOfEverything{}, "ABitOfEverything", nil) + cdc.RegisterConcrete(&testpb.NestedMessage{}, "NestedMessage", nil) + + msg := &testpb.ABitOfEverything{ + Message: &testpb.NestedMessage{ + Foo: "test", + Bar: 0, // this is the default value and should be omitted from output + }, + Enum: testpb.AnEnum_ONE, + Repeated: []int32{3, -7, 2, 6, 4}, + Str: `abcxyz"foo"def`, + Bool: true, + Bytes: []byte{0, 1, 2, 3}, + I32: -15, + F32: 1001, + U32: 1200, + Si32: -376, + Sf32: -1000, + I64: 14578294827584932, + F64: 9572348124213523654, + U64: 4759492485, + Si64: -59268425823934, + Sf64: -659101379604211154, + } + bz, err := aminojson.NewAminoJSON().Marshal(msg) + assert.NilError(t, err) + legacyBz, err := cdc.MarshalJSON(msg) + assert.NilError(t, err) + require.Equal(t, string(legacyBz), string(bz)) +} + +func TestRapid(t *testing.T) { + gen := rapidproto.MessageGenerator(&testpb.ABitOfEverything{}, rapidproto.GeneratorOptions{}) + rapid.Check(t, func(t *rapid.T) { + msg := gen.Draw(t, "msg") + bz, err := aminojson.NewAminoJSON().Marshal(msg) + assert.NilError(t, err) + checkInvariants(t, msg, bz) + }) +} + +func checkInvariants(t *rapid.T, message proto.Message, marshaledBytes []byte) { + checkLegacyParity(t, message, marshaledBytes) + checkRoundTrip(t, message, marshaledBytes) +} + +func checkLegacyParity(t *rapid.T, message proto.Message, marshaledBytes []byte) { + legacyBz, err := marshalLegacy(message) + assert.NilError(t, err) + require.Equal(t, string(legacyBz), string(marshaledBytes), "%s vs legacy: %s", string(marshaledBytes), + string(legacyBz)) +} + +func checkRoundTrip(t *rapid.T, message proto.Message, marshaledBytes []byte) { + cdc := amino.NewCodec() + cdc.RegisterConcrete(&testpb.ABitOfEverything{}, "ABitOfEverything", nil) + cdc.RegisterConcrete(&testpb.NestedMessage{}, "NestedMessage", nil) + + message2 := message.ProtoReflect().New().Interface() + goProtoJSON, err := cdc.MarshalJSON(message) + assert.NilError(t, err) + err = cdc.UnmarshalJSON(marshaledBytes, message2) + assert.NilError(t, err, "%s vs %s", string(marshaledBytes), string(goProtoJSON)) +} diff --git a/x/tx/aminojson/options.go b/x/tx/aminojson/options.go new file mode 100644 index 000000000000..51498d0a8b6c --- /dev/null +++ b/x/tx/aminojson/options.go @@ -0,0 +1,90 @@ +package aminojson + +import ( + cosmos_proto "github.com/cosmos/cosmos-proto" + "github.com/iancoleman/strcase" + "github.com/pkg/errors" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" + + "cosmossdk.io/api/amino" +) + +// getMessageAminoName returns the amino name of a message if it has been set by the `amino.name` option. +// If the message does not have an amino name, then the function returns false. +func getMessageAminoName(msg protoreflect.Message) (string, bool) { + opts := msg.Descriptor().Options() + if proto.HasExtension(opts, amino.E_Name) { + name := proto.GetExtension(opts, amino.E_Name) + return name.(string), true + } + return "", false +} + +// omitEmpty returns true if the field should be omitted if empty. Empty field omission is the default behavior. +func omitEmpty(field protoreflect.FieldDescriptor) bool { + opts := field.Options() + if proto.HasExtension(opts, amino.E_DontOmitempty) { + dontOmitEmpty := proto.GetExtension(opts, amino.E_DontOmitempty).(bool) + return !dontOmitEmpty + } + return true +} + +// getAminoFieldName returns the amino field name of a field if it has been set by the `amino.field_name` option. +// If the field does not have an amino field name, then the function returns the protobuf field name. +func getAminoFieldName(field protoreflect.FieldDescriptor) string { + opts := field.Options() + if proto.HasExtension(opts, amino.E_FieldName) { + return proto.GetExtension(opts, amino.E_FieldName).(string) + } + return string(field.Name()) +} + +func getOneOfNames(field protoreflect.FieldDescriptor) (string, string, error) { + opts := field.Options() + oneOf := field.ContainingOneof() + if oneOf == nil { + return "", "", errors.Errorf("field %s must be within a oneof", field.Name()) + } + + fieldName := strcase.ToCamel(string(oneOf.Name())) + var typeName string + + if proto.HasExtension(opts, amino.E_OneofName) { + typeName = proto.GetExtension(opts, amino.E_OneofName).(string) + } else { + return "", "", errors.Errorf("field %s within a oneof must have the amino.oneof_type_name option set", + field.Name()) + } + + return fieldName, typeName, nil +} + +func (enc Encoder) getMessageEncoder(message protoreflect.Message) MessageEncoder { + opts := message.Descriptor().Options() + if proto.HasExtension(opts, amino.E_MessageEncoding) { + encoding := proto.GetExtension(opts, amino.E_MessageEncoding).(string) + if fn, ok := enc.messageEncoders[encoding]; ok { + return fn + } + } + return nil +} + +func (enc Encoder) getFieldEncoding(field protoreflect.FieldDescriptor) FieldEncoder { + opts := field.Options() + if proto.HasExtension(opts, amino.E_Encoding) { + encoding := proto.GetExtension(opts, amino.E_Encoding).(string) + if fn, ok := enc.fieldEncoders[encoding]; ok { + return fn + } + } + if proto.HasExtension(opts, cosmos_proto.E_Scalar) { + scalar := proto.GetExtension(opts, cosmos_proto.E_Scalar).(string) + if fn, ok := enc.scalarEncoders[scalar]; ok { + return fn + } + } + return nil +} diff --git a/x/tx/aminojson/time.go b/x/tx/aminojson/time.go new file mode 100644 index 000000000000..c141de0eff4c --- /dev/null +++ b/x/tx/aminojson/time.go @@ -0,0 +1,73 @@ +package aminojson + +import ( + "fmt" + "google.golang.org/protobuf/reflect/protoreflect" + "io" + "math" + "time" +) + +const ( + secondsName protoreflect.Name = "seconds" + nanosName protoreflect.Name = "nanos" +) + +func marshalTimestamp(message protoreflect.Message, writer io.Writer) error { + fields := message.Descriptor().Fields() + secondsField := fields.ByName(secondsName) + if secondsField == nil { + return fmt.Errorf("expected seconds field") + } + + nanosField := fields.ByName(nanosName) + if nanosField == nil { + return fmt.Errorf("expected nanos field") + } + + seconds := message.Get(secondsField).Int() + nanos := message.Get(nanosField).Int() + if nanos < 0 { + return fmt.Errorf("nanos must be non-negative on timestamp %v", message) + } + + t := time.Unix(seconds, nanos).UTC() + var str string + if nanos == 0 { + str = t.Format(time.RFC3339) + } else { + str = t.Format(time.RFC3339Nano) + } + + _, err := fmt.Fprintf(writer, `"%s"`, str) + return err +} + +// MaxDurationSeconds the maximum number of seconds (when expressed as nanoseconds) which can fit in an int64. +// gogoproto encodes google.protobuf.Duration as a time.Duration, which is 64-bit signed integer. +const MaxDurationSeconds = int64(math.MaxInt64/int(1e9)) - 1 + +func marshalDuration(message protoreflect.Message, writer io.Writer) error { + fields := message.Descriptor().Fields() + secondsField := fields.ByName(secondsName) + if secondsField == nil { + return fmt.Errorf("expected seconds field") + } + + // todo + // check signs are consistent + seconds := message.Get(secondsField).Int() + if seconds > MaxDurationSeconds { + return fmt.Errorf("%d seconds would overflow an int64 when represented as nanoseconds", seconds) + } + + nanosField := fields.ByName(nanosName) + if nanosField == nil { + return fmt.Errorf("expected nanos field") + } + + nanos := message.Get(nanosField).Int() + totalNanos := nanos + (seconds * 1e9) + _, err := writer.Write([]byte(fmt.Sprintf(`"%d"`, totalNanos))) + return err +} diff --git a/x/tx/go.mod b/x/tx/go.mod index 3ba154dbf5d7..7d3e345b8127 100644 --- a/x/tx/go.mod +++ b/x/tx/go.mod @@ -8,8 +8,13 @@ require ( cosmossdk.io/math v1.0.0-beta.6 github.com/cosmos/cosmos-proto v1.0.0-beta.2 github.com/google/go-cmp v0.5.9 + github.com/iancoleman/strcase v0.2.0 + github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.1 - google.golang.org/protobuf v1.28.1 + github.com/tendermint/go-amino v0.16.0 + google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8 + gotest.tools/v3 v3.4.0 + pgregory.net/rapid v0.5.5 ) require ( diff --git a/x/tx/go.sum b/x/tx/go.sum index d20be28d956b..049324397a69 100644 --- a/x/tx/go.sum +++ b/x/tx/go.sum @@ -11,45 +11,85 @@ github.com/cosmos/gogoproto v1.4.6/go.mod h1:VS/ASYmPgv6zkPKLjR9EB91lwbLHOzaGCir github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck= +github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= +github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= +github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2lyGa2E= +github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20230203172020-98cc5a0785f9 h1:frX3nT9RkKybPnjyI+yvZh6ZucTZatCCEm9D47sZ2zo= golang.org/x/exp v0.0.0-20230203172020-98cc5a0785f9/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20230202175211-008b39050e57 h1:vArvWooPH749rNHpBGgVl+U9B9dATjiEhJzcWGlovNs= google.golang.org/genproto v0.0.0-20230202175211-008b39050e57/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= google.golang.org/grpc v1.53.0 h1:LAv2ds7cmFV/XTS3XG1NneeENYrXGmorPxsBbptIjNc= google.golang.org/grpc v1.53.0/go.mod h1:OnIrk0ipVdj4N5d9IUoFUx72/VlD7+jUsHwZgwSMQpw= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= -google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8 h1:KR8+MyP7/qOlV+8Af01LtjL04bu7on42eVsxT4EyBQk= +google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= +gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= +pgregory.net/rapid v0.5.5 h1:jkgx1TjbQPD/feRoK+S/mXw9e1uj6WilpHrXJowi6oA= +pgregory.net/rapid v0.5.5/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=