├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── cosmos.pb.go ├── cosmos.proto ├── go.mod ├── go.sum ├── interfacetype └── interfacetype.go ├── protoc-gen-gocosmos └── main.go └── test ├── abc.pb.go ├── abc.proto ├── iface └── iface.go ├── iface_test.go └── impl.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Go template 3 | # Binaries for programs and plugins 4 | *.exe 5 | *.exe~ 6 | *.dll 7 | *.so 8 | *.dylib 9 | 10 | # Test binary, built with `go test -c` 11 | *.test 12 | 13 | # Output of the go coverage tool, specifically when used with LiteIDE 14 | *.out 15 | 16 | # Dependency directories (remove the comment below to include it) 17 | # vendor/ 18 | 19 | .idea 20 | *.iml 21 | 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2021 Regen Network Development, Inc. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: proto-gen test 2 | 3 | all: proto-gen test 4 | 5 | proto-gen: 6 | go get github.com/gogo/protobuf/protoc-gen-gogoslick 7 | protoc --gogoslick_out=Mgoogle/protobuf/descriptor.proto=github.com/gogo/protobuf/protoc-gen-gogo/descriptor,paths=source_relative:. cosmos.proto 8 | 9 | test: 10 | go install ./protoc-gen-gocosmos 11 | protoc -I=. --gocosmos_out=plugins=interfacetype,Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types:. test/abc.proto 12 | go test ./test 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cosmos-proto 2 | 3 | THIS PACKAGE IS DEPRECATED AND NOT USED ANY MORE. 4 | 5 | `protoc-gen-gocosmos` app was moved to [github.com/cosmos/gogoproto](https://github.com/cosmos/gogoproto). 6 | 7 | 8 | ## Summary 9 | 10 | Extensions to [gogoprotobuf](https://github.com/gogo/protobuf) for Cosmos. 11 | 12 | ## `accepts_interface` 13 | 14 | An informational extension to be added to `google.protobuf.Any` fields to indicate 15 | which interface that field accepts. The interface name should be independent of 16 | any programming language and either be unqualified to indicate the current package 17 | of fully-qualified to indicate another protobuf package. 18 | 19 | Example: 20 | 21 | ```proto 22 | message SomeContainer { 23 | google.protobuf.Any some_interface = 1 [(cosmos_proto.accepts_interface) = "SomeInterface"]; 24 | } 25 | 26 | message AnotherContainer { 27 | google.protobuf.Any another_interface = 1 [(cosmos_proto.accepts_interface) = "another.package.AnotherInterface"]; 28 | } 29 | ``` 30 | 31 | ## `implements_interface` 32 | 33 | An informational extension to be added to messages to indicate which interface 34 | that message implements. The interface name should be independent of 35 | any programming language and either be unqualified to indicate the current package 36 | of fully-qualified to indicate another protobuf package. 37 | 38 | ```proto 39 | message A { 40 | option (cosmos_proto.implements_interface) = "SomeInterface"; 41 | int64 x = 1; 42 | } 43 | 44 | message B { 45 | option (cosmos_proto.implements_interface) = "another.package.AnotherInterface"; 46 | double x = 1; 47 | } 48 | ``` 49 | 50 | ## `interface_type` 51 | 52 | *See [test](test/) for a full example.* 53 | 54 | The `cosmos_proto.interface_type` message option generates a getter and 55 | setter from the provided go interface. Messages which use this option must 56 | consist of a single `oneof` and no other fields. 57 | 58 | Given this example `.proto` file: 59 | 60 | ```proto 61 | message ABC { 62 | option (cosmos_proto.interface_type) = "my_package.Msg"; 63 | oneof abc { 64 | A a = 1; 65 | B b = 2; 66 | C c = 3; 67 | } 68 | } 69 | 70 | message A { int32 x = 1; } 71 | 72 | message B { uint32 y = 1; } 73 | 74 | message C { bool z = 1; } 75 | ``` 76 | 77 | The `ABC` struct will satisfy the following interface: 78 | ```go 79 | type MsgCodec interface { 80 | GetMsg() Msg 81 | SetMsg(value Msg) error 82 | } 83 | ``` 84 | 85 | The types `A`, `B`, and `C` must of course have implementations of `Msg`. 86 | 87 | ### Handling Non-Pointer Interfaces 88 | 89 | By default `interface_type` generates `Set` handlers for both pointer and non-pointer 90 | implementations of an interface (i.e. both `*A` and `A`). This means all interfaces 91 | must be implemented for the non-pointer version of a struct. To disable the non-pointer 92 | cases (so that just `*A` and not `A` needs to implement the interface), the interface 93 | type name can be prepended with a `*`, ex: `option (cosmos_proto.interface_type) = "*my_package.Msg";`. 94 | 95 | -------------------------------------------------------------------------------- /cosmos.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gogo. DO NOT EDIT. 2 | // source: cosmos.proto 3 | 4 | package cosmos_proto 5 | 6 | import ( 7 | fmt "fmt" 8 | proto "github.com/gogo/protobuf/proto" 9 | descriptor "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" 10 | math "math" 11 | ) 12 | 13 | // Reference imports to suppress errors if they are not otherwise used. 14 | var _ = proto.Marshal 15 | var _ = fmt.Errorf 16 | var _ = math.Inf 17 | 18 | // This is a compile-time assertion to ensure that this generated file 19 | // is compatible with the proto package it is being compiled against. 20 | // A compilation error at this line likely means your copy of the 21 | // proto package needs to be updated. 22 | const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package 23 | 24 | var E_InterfaceType = &proto.ExtensionDesc{ 25 | ExtendedType: (*descriptor.MessageOptions)(nil), 26 | ExtensionType: (*string)(nil), 27 | Field: 93001, 28 | Name: "cosmos_proto.interface_type", 29 | Tag: "bytes,93001,opt,name=interface_type", 30 | Filename: "cosmos.proto", 31 | } 32 | 33 | var E_ImplementsInterface = &proto.ExtensionDesc{ 34 | ExtendedType: (*descriptor.MessageOptions)(nil), 35 | ExtensionType: (*string)(nil), 36 | Field: 93002, 37 | Name: "cosmos_proto.implements_interface", 38 | Tag: "bytes,93002,opt,name=implements_interface", 39 | Filename: "cosmos.proto", 40 | } 41 | 42 | var E_AcceptsInterface = &proto.ExtensionDesc{ 43 | ExtendedType: (*descriptor.FieldOptions)(nil), 44 | ExtensionType: (*string)(nil), 45 | Field: 93001, 46 | Name: "cosmos_proto.accepts_interface", 47 | Tag: "bytes,93001,opt,name=accepts_interface", 48 | Filename: "cosmos.proto", 49 | } 50 | 51 | func init() { 52 | proto.RegisterExtension(E_InterfaceType) 53 | proto.RegisterExtension(E_ImplementsInterface) 54 | proto.RegisterExtension(E_AcceptsInterface) 55 | } 56 | 57 | func init() { proto.RegisterFile("cosmos.proto", fileDescriptor_fc3480149abc1849) } 58 | 59 | var fileDescriptor_fc3480149abc1849 = []byte{ 60 | // 276 bytes of a gzipped FileDescriptorProto 61 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0xce, 0x2f, 0xce, 62 | 0xcd, 0x2f, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x82, 0xf2, 0xe2, 0xc1, 0x3c, 0x29, 0x85, 63 | 0xf4, 0xfc, 0xfc, 0xf4, 0x9c, 0x54, 0x7d, 0x30, 0x2f, 0xa9, 0x34, 0x4d, 0x3f, 0x25, 0xb5, 0x38, 64 | 0xb9, 0x28, 0xb3, 0xa0, 0x24, 0xbf, 0x08, 0xa2, 0xde, 0xca, 0x83, 0x8b, 0x2f, 0x33, 0xaf, 0x24, 65 | 0xb5, 0x28, 0x2d, 0x31, 0x39, 0x35, 0xbe, 0xa4, 0xb2, 0x20, 0x55, 0x48, 0x5e, 0x0f, 0xa2, 0x49, 66 | 0x0f, 0xa6, 0x49, 0xcf, 0x37, 0xb5, 0xb8, 0x38, 0x31, 0x3d, 0xd5, 0xbf, 0xa0, 0x24, 0x33, 0x3f, 67 | 0xaf, 0x58, 0xe2, 0xe4, 0x35, 0x56, 0x05, 0x46, 0x0d, 0xce, 0x20, 0x5e, 0xb8, 0xc6, 0x90, 0xca, 68 | 0x82, 0x54, 0xab, 0x10, 0x2e, 0x91, 0xcc, 0xdc, 0x82, 0x9c, 0xd4, 0xdc, 0xd4, 0xbc, 0x92, 0xe2, 69 | 0x78, 0xb8, 0x1c, 0x61, 0xf3, 0x4e, 0x41, 0xcd, 0x13, 0x46, 0x68, 0xf7, 0x84, 0xe9, 0xb6, 0xf2, 70 | 0xe1, 0x12, 0x4c, 0x4c, 0x4e, 0x4e, 0x2d, 0x40, 0x31, 0x52, 0x16, 0xc3, 0x48, 0xb7, 0xcc, 0xd4, 71 | 0x9c, 0x14, 0x74, 0x07, 0x0a, 0x40, 0x75, 0xc2, 0x4d, 0x73, 0x8a, 0xbe, 0xf0, 0x50, 0x8e, 0xe1, 72 | 0xc6, 0x43, 0x39, 0x86, 0x0f, 0x0f, 0xe5, 0x18, 0x1b, 0x1e, 0xc9, 0x31, 0xae, 0x78, 0x24, 0xc7, 73 | 0x78, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0xbe, 0x78, 0x24, 74 | 0xc7, 0xf0, 0xe1, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, 0x1e, 0xcb, 0x31, 0xdc, 0x78, 75 | 0x2c, 0xc7, 0x10, 0xa5, 0x9a, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f, 0xab, 0x5f, 76 | 0x94, 0x9a, 0x9e, 0x9a, 0xa7, 0x9b, 0x97, 0x5a, 0x52, 0x9e, 0x5f, 0x94, 0xad, 0x0f, 0x09, 0x6c, 77 | 0x5d, 0x88, 0x33, 0xd8, 0xc0, 0x94, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xcb, 0xda, 0xc2, 0xd2, 78 | 0x91, 0x01, 0x00, 0x00, 79 | } 80 | -------------------------------------------------------------------------------- /cosmos.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package cosmos_proto; 3 | 4 | import "google/protobuf/descriptor.proto"; 5 | 6 | option go_package = "github.com/regen-network/cosmos-proto"; 7 | 8 | extend google.protobuf.MessageOptions { 9 | string interface_type = 93001; 10 | 11 | string implements_interface = 93002; 12 | } 13 | 14 | extend google.protobuf.FieldOptions { 15 | string accepts_interface = 93001; 16 | } 17 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/regen-network/cosmos-proto 2 | 3 | go 1.13 4 | 5 | require ( 6 | github.com/gogo/protobuf v1.3.2 7 | github.com/stretchr/testify v1.4.0 8 | ) 9 | 10 | replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 11 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 3 | github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= 4 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 5 | github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= 6 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 7 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 9 | github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 10 | github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= 11 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= 12 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 13 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 14 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 15 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 16 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 17 | github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls= 18 | github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= 19 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 20 | github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= 21 | github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= 22 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 23 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 24 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 25 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 26 | github.com/regen-network/protobuf v1.3.2-alpha.regen.4 h1:c9jEnU+xm6vqyrQe3M94UFWqiXxRIKKnqBOh2EACmBE= 27 | github.com/regen-network/protobuf v1.3.2-alpha.regen.4/go.mod h1:/J8/bR1T/NXyIdQDLUaq15LjNE83nRzkyrLAMcPewig= 28 | github.com/regen-network/protobuf v1.3.3-alpha.regen.1 h1:OHEc+q5iIAXpqiqFKeLpu5NwTIkVXUs48vFMwzqpqY4= 29 | github.com/regen-network/protobuf v1.3.3-alpha.regen.1/go.mod h1:2DjTFR1HhMQhiWC5sZ4OhQ3+NtdbZ6oBDKQwq5Ou+FI= 30 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 31 | github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= 32 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 33 | github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 34 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 35 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 36 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 37 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 38 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 39 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 40 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 41 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 42 | golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= 43 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 44 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 45 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 46 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 47 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 48 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 49 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 50 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 51 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 52 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 53 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 54 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 55 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 56 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 57 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 58 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 59 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 60 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 61 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 62 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 63 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 64 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 65 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 66 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 67 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 68 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 69 | golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 70 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 71 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 72 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 73 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 74 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 75 | golang.org/x/tools v0.0.0-20200110213125-a7a6caa82ab2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= 76 | golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 77 | golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= 78 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 79 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 80 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 81 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 82 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 83 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 84 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 85 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 86 | google.golang.org/genproto v0.0.0-20200324203455-a04cca1dde73/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 87 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 88 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= 89 | google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= 90 | google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 91 | google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= 92 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 93 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 94 | gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= 95 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 96 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 97 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 98 | -------------------------------------------------------------------------------- /interfacetype/interfacetype.go: -------------------------------------------------------------------------------- 1 | package interfacetype 2 | 3 | import ( 4 | "fmt" 5 | "github.com/gogo/protobuf/proto" 6 | "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" 7 | "github.com/gogo/protobuf/protoc-gen-gogo/generator" 8 | "github.com/regen-network/cosmos-proto" 9 | "strings" 10 | ) 11 | 12 | type interfacetype struct { 13 | *generator.Generator 14 | generator.PluginImports 15 | } 16 | 17 | func NewInterfaceType() *interfacetype { 18 | return &interfacetype{} 19 | } 20 | 21 | func (p *interfacetype) Name() string { 22 | return "interfacetype" 23 | } 24 | 25 | func (p *interfacetype) Init(g *generator.Generator) { 26 | p.Generator = g 27 | } 28 | 29 | func GetInterfaceType(message *descriptor.DescriptorProto) string { 30 | if message == nil { 31 | return "" 32 | } 33 | if message.Options != nil { 34 | v, err := proto.GetExtension(message.Options, cosmos_proto.E_InterfaceType) 35 | if err == nil && v.(*string) != nil { 36 | return *(v.(*string)) 37 | } 38 | } 39 | return "" 40 | } 41 | 42 | func (p *interfacetype) Generate(file *generator.FileDescriptor) { 43 | p.PluginImports = generator.NewPluginImports(p.Generator) 44 | 45 | for _, message := range file.Messages() { 46 | iface := GetInterfaceType(message.DescriptorProto) 47 | if len(iface) == 0 { 48 | continue 49 | } 50 | handleNonPointer := true 51 | if iface[0] == '*' { 52 | iface = iface[1:] 53 | handleNonPointer = false 54 | } 55 | if len(message.OneofDecl) != 1 { 56 | panic("interfacetype only supports messages with exactly one oneof declaration") 57 | } 58 | for _, field := range message.Field { 59 | if idx := field.OneofIndex; idx == nil || *idx != 0 { 60 | panic("all fields in interfacetype message must belong to the oneof") 61 | } 62 | } 63 | 64 | ifacePackage, ifaceName := splitCPackageType(iface) 65 | ifaceRef := ifaceName 66 | if len(ifacePackage) != 0 { 67 | imp := p.PluginImports.NewImport(ifacePackage).Use() 68 | ifaceRef = fmt.Sprintf("%s.%s", imp, ifaceName) 69 | } 70 | 71 | ccTypeName := generator.CamelCaseSlice(message.TypeName()) 72 | p.P(`func (this *`, ccTypeName, `) Get`, ifaceName, `() `, ifaceRef, ` {`) 73 | p.In() 74 | for _, field := range message.Field { 75 | fieldname := p.GetOneOfFieldName(message, field) 76 | if fieldname == "Value" { 77 | panic("cannot have a onlyone message " + ccTypeName + " with a field named Value") 78 | } 79 | p.P(`if x := this.Get`, fieldname, `(); x != nil {`) 80 | p.In() 81 | p.P(`return x`) 82 | p.Out() 83 | p.P(`}`) 84 | } 85 | p.P(`return nil`) 86 | p.Out() 87 | p.P(`}`) 88 | p.P(``) 89 | p.P(`func (this *`, ccTypeName, `) Set`, ifaceName, `(value `, ifaceRef, `) error {`) 90 | p.In() 91 | p.P(`if value == nil {`) 92 | p.In() 93 | p.P(`this.`, p.GetFieldName(message, message.Field[0]), ` = nil`) 94 | p.P(`return nil`) 95 | p.Out() 96 | p.P("}") 97 | p.P(`switch vt := value.(type) {`) 98 | p.In() 99 | for _, field := range message.Field { 100 | oneofName := p.GetFieldName(message, field) 101 | structName := p.OneOfTypeName(message, field) 102 | goTyp, _ := p.GoType(message, field) 103 | p.P(`case `, goTyp, `:`) 104 | p.In() 105 | p.P(`this.`, oneofName, ` = &`, structName, `{vt}`) 106 | p.P("return nil") 107 | p.Out() 108 | if handleNonPointer { 109 | // Handle non-pointer case 110 | if goTyp[0] == '*' { 111 | p.P(`case `, goTyp[1:], `:`) 112 | p.In() 113 | p.P(`this.`, oneofName, ` = &`, structName, `{&vt}`) 114 | p.P("return nil") 115 | p.Out() 116 | } 117 | } 118 | } 119 | p.P(`}`) 120 | p.P(`return fmt.Errorf("can't encode value of type %T as message `, ccTypeName, `", value)`) 121 | p.Out() 122 | p.P(`}`) 123 | p.P(``) 124 | } 125 | } 126 | 127 | func splitCPackageType(ctype string) (packageName string, typ string) { 128 | ss := strings.Split(ctype, ".") 129 | if len(ss) == 1 { 130 | return "", ctype 131 | } 132 | packageName = strings.Join(ss[0:len(ss)-1], ".") 133 | typeName := ss[len(ss)-1] 134 | return packageName, typeName 135 | } 136 | 137 | func init() { 138 | generator.RegisterPlugin(NewInterfaceType()) 139 | } 140 | -------------------------------------------------------------------------------- /protoc-gen-gocosmos/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/gogo/protobuf/vanity" 5 | "github.com/gogo/protobuf/vanity/command" 6 | _ "github.com/regen-network/cosmos-proto/interfacetype" 7 | ) 8 | 9 | func main() { 10 | req := command.Read() 11 | files := req.GetProtoFile() 12 | files = vanity.FilterFiles(files, vanity.NotGoogleProtobufDescriptorProto) 13 | 14 | vanity.ForEachFile(files, vanity.TurnOnMarshalerAll) 15 | vanity.ForEachFile(files, vanity.TurnOnSizerAll) 16 | vanity.ForEachFile(files, vanity.TurnOnUnmarshalerAll) 17 | 18 | vanity.ForEachFieldInFilesExcludingExtensions(vanity.OnlyProto2(files), vanity.TurnOffNullableForNativeTypesWithoutDefaultsOnly) 19 | vanity.ForEachFile(files, vanity.TurnOffGoUnrecognizedAll) 20 | vanity.ForEachFile(files, vanity.TurnOffGoUnkeyedAll) 21 | vanity.ForEachFile(files, vanity.TurnOffGoSizecacheAll) 22 | 23 | resp := command.Generate(req) 24 | command.Write(resp) 25 | } 26 | -------------------------------------------------------------------------------- /test/abc.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-gogo. DO NOT EDIT. 2 | // source: test/abc.proto 3 | 4 | package test 5 | 6 | import ( 7 | fmt "fmt" 8 | proto "github.com/gogo/protobuf/proto" 9 | types "github.com/gogo/protobuf/types" 10 | _ "github.com/regen-network/cosmos-proto" 11 | github_com_regen_network_cosmos_proto_test_iface "github.com/regen-network/cosmos-proto/test/iface" 12 | io "io" 13 | math "math" 14 | math_bits "math/bits" 15 | ) 16 | 17 | // Reference imports to suppress errors if they are not otherwise used. 18 | var _ = proto.Marshal 19 | var _ = fmt.Errorf 20 | var _ = math.Inf 21 | 22 | // This is a compile-time assertion to ensure that this generated file 23 | // is compatible with the proto package it is being compiled against. 24 | // A compilation error at this line likely means your copy of the 25 | // proto package needs to be updated. 26 | const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package 27 | 28 | type ABC struct { 29 | // Types that are valid to be assigned to Sum: 30 | // *ABC_A 31 | // *ABC_B 32 | // *ABC_C 33 | Sum isABC_Sum `protobuf_oneof:"sum"` 34 | } 35 | 36 | func (m *ABC) Reset() { *m = ABC{} } 37 | func (m *ABC) String() string { return proto.CompactTextString(m) } 38 | func (*ABC) ProtoMessage() {} 39 | func (*ABC) Descriptor() ([]byte, []int) { 40 | return fileDescriptor_edbe9e0eab89a1a7, []int{0} 41 | } 42 | func (m *ABC) XXX_Unmarshal(b []byte) error { 43 | return m.Unmarshal(b) 44 | } 45 | func (m *ABC) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 46 | if deterministic { 47 | return xxx_messageInfo_ABC.Marshal(b, m, deterministic) 48 | } else { 49 | b = b[:cap(b)] 50 | n, err := m.MarshalToSizedBuffer(b) 51 | if err != nil { 52 | return nil, err 53 | } 54 | return b[:n], nil 55 | } 56 | } 57 | func (m *ABC) XXX_Merge(src proto.Message) { 58 | xxx_messageInfo_ABC.Merge(m, src) 59 | } 60 | func (m *ABC) XXX_Size() int { 61 | return m.Size() 62 | } 63 | func (m *ABC) XXX_DiscardUnknown() { 64 | xxx_messageInfo_ABC.DiscardUnknown(m) 65 | } 66 | 67 | var xxx_messageInfo_ABC proto.InternalMessageInfo 68 | 69 | type isABC_Sum interface { 70 | isABC_Sum() 71 | MarshalTo([]byte) (int, error) 72 | Size() int 73 | } 74 | 75 | type ABC_A struct { 76 | A *A `protobuf:"bytes,1,opt,name=a,proto3,oneof" json:"a,omitempty"` 77 | } 78 | type ABC_B struct { 79 | B *B `protobuf:"bytes,2,opt,name=b,proto3,oneof" json:"b,omitempty"` 80 | } 81 | type ABC_C struct { 82 | C *C `protobuf:"bytes,3,opt,name=c,proto3,oneof" json:"c,omitempty"` 83 | } 84 | 85 | func (*ABC_A) isABC_Sum() {} 86 | func (*ABC_B) isABC_Sum() {} 87 | func (*ABC_C) isABC_Sum() {} 88 | 89 | func (m *ABC) GetSum() isABC_Sum { 90 | if m != nil { 91 | return m.Sum 92 | } 93 | return nil 94 | } 95 | 96 | func (m *ABC) GetA() *A { 97 | if x, ok := m.GetSum().(*ABC_A); ok { 98 | return x.A 99 | } 100 | return nil 101 | } 102 | 103 | func (m *ABC) GetB() *B { 104 | if x, ok := m.GetSum().(*ABC_B); ok { 105 | return x.B 106 | } 107 | return nil 108 | } 109 | 110 | func (m *ABC) GetC() *C { 111 | if x, ok := m.GetSum().(*ABC_C); ok { 112 | return x.C 113 | } 114 | return nil 115 | } 116 | 117 | // XXX_OneofWrappers is for the internal use of the proto package. 118 | func (*ABC) XXX_OneofWrappers() []interface{} { 119 | return []interface{}{ 120 | (*ABC_A)(nil), 121 | (*ABC_B)(nil), 122 | (*ABC_C)(nil), 123 | } 124 | } 125 | 126 | type ABCNonPointer struct { 127 | // Types that are valid to be assigned to Sum: 128 | // *ABCNonPointer_A 129 | // *ABCNonPointer_B 130 | // *ABCNonPointer_C 131 | Sum isABCNonPointer_Sum `protobuf_oneof:"sum"` 132 | } 133 | 134 | func (m *ABCNonPointer) Reset() { *m = ABCNonPointer{} } 135 | func (m *ABCNonPointer) String() string { return proto.CompactTextString(m) } 136 | func (*ABCNonPointer) ProtoMessage() {} 137 | func (*ABCNonPointer) Descriptor() ([]byte, []int) { 138 | return fileDescriptor_edbe9e0eab89a1a7, []int{1} 139 | } 140 | func (m *ABCNonPointer) XXX_Unmarshal(b []byte) error { 141 | return m.Unmarshal(b) 142 | } 143 | func (m *ABCNonPointer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 144 | if deterministic { 145 | return xxx_messageInfo_ABCNonPointer.Marshal(b, m, deterministic) 146 | } else { 147 | b = b[:cap(b)] 148 | n, err := m.MarshalToSizedBuffer(b) 149 | if err != nil { 150 | return nil, err 151 | } 152 | return b[:n], nil 153 | } 154 | } 155 | func (m *ABCNonPointer) XXX_Merge(src proto.Message) { 156 | xxx_messageInfo_ABCNonPointer.Merge(m, src) 157 | } 158 | func (m *ABCNonPointer) XXX_Size() int { 159 | return m.Size() 160 | } 161 | func (m *ABCNonPointer) XXX_DiscardUnknown() { 162 | xxx_messageInfo_ABCNonPointer.DiscardUnknown(m) 163 | } 164 | 165 | var xxx_messageInfo_ABCNonPointer proto.InternalMessageInfo 166 | 167 | type isABCNonPointer_Sum interface { 168 | isABCNonPointer_Sum() 169 | MarshalTo([]byte) (int, error) 170 | Size() int 171 | } 172 | 173 | type ABCNonPointer_A struct { 174 | A *A `protobuf:"bytes,1,opt,name=a,proto3,oneof" json:"a,omitempty"` 175 | } 176 | type ABCNonPointer_B struct { 177 | B *B `protobuf:"bytes,2,opt,name=b,proto3,oneof" json:"b,omitempty"` 178 | } 179 | type ABCNonPointer_C struct { 180 | C *C `protobuf:"bytes,3,opt,name=c,proto3,oneof" json:"c,omitempty"` 181 | } 182 | 183 | func (*ABCNonPointer_A) isABCNonPointer_Sum() {} 184 | func (*ABCNonPointer_B) isABCNonPointer_Sum() {} 185 | func (*ABCNonPointer_C) isABCNonPointer_Sum() {} 186 | 187 | func (m *ABCNonPointer) GetSum() isABCNonPointer_Sum { 188 | if m != nil { 189 | return m.Sum 190 | } 191 | return nil 192 | } 193 | 194 | func (m *ABCNonPointer) GetA() *A { 195 | if x, ok := m.GetSum().(*ABCNonPointer_A); ok { 196 | return x.A 197 | } 198 | return nil 199 | } 200 | 201 | func (m *ABCNonPointer) GetB() *B { 202 | if x, ok := m.GetSum().(*ABCNonPointer_B); ok { 203 | return x.B 204 | } 205 | return nil 206 | } 207 | 208 | func (m *ABCNonPointer) GetC() *C { 209 | if x, ok := m.GetSum().(*ABCNonPointer_C); ok { 210 | return x.C 211 | } 212 | return nil 213 | } 214 | 215 | // XXX_OneofWrappers is for the internal use of the proto package. 216 | func (*ABCNonPointer) XXX_OneofWrappers() []interface{} { 217 | return []interface{}{ 218 | (*ABCNonPointer_A)(nil), 219 | (*ABCNonPointer_B)(nil), 220 | (*ABCNonPointer_C)(nil), 221 | } 222 | } 223 | 224 | type A struct { 225 | X int32 `protobuf:"varint,1,opt,name=x,proto3" json:"x,omitempty"` 226 | } 227 | 228 | func (m *A) Reset() { *m = A{} } 229 | func (m *A) String() string { return proto.CompactTextString(m) } 230 | func (*A) ProtoMessage() {} 231 | func (*A) Descriptor() ([]byte, []int) { 232 | return fileDescriptor_edbe9e0eab89a1a7, []int{2} 233 | } 234 | func (m *A) XXX_Unmarshal(b []byte) error { 235 | return m.Unmarshal(b) 236 | } 237 | func (m *A) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 238 | if deterministic { 239 | return xxx_messageInfo_A.Marshal(b, m, deterministic) 240 | } else { 241 | b = b[:cap(b)] 242 | n, err := m.MarshalToSizedBuffer(b) 243 | if err != nil { 244 | return nil, err 245 | } 246 | return b[:n], nil 247 | } 248 | } 249 | func (m *A) XXX_Merge(src proto.Message) { 250 | xxx_messageInfo_A.Merge(m, src) 251 | } 252 | func (m *A) XXX_Size() int { 253 | return m.Size() 254 | } 255 | func (m *A) XXX_DiscardUnknown() { 256 | xxx_messageInfo_A.DiscardUnknown(m) 257 | } 258 | 259 | var xxx_messageInfo_A proto.InternalMessageInfo 260 | 261 | func (m *A) GetX() int32 { 262 | if m != nil { 263 | return m.X 264 | } 265 | return 0 266 | } 267 | 268 | type B struct { 269 | Y uint32 `protobuf:"varint,1,opt,name=y,proto3" json:"y,omitempty"` 270 | } 271 | 272 | func (m *B) Reset() { *m = B{} } 273 | func (m *B) String() string { return proto.CompactTextString(m) } 274 | func (*B) ProtoMessage() {} 275 | func (*B) Descriptor() ([]byte, []int) { 276 | return fileDescriptor_edbe9e0eab89a1a7, []int{3} 277 | } 278 | func (m *B) XXX_Unmarshal(b []byte) error { 279 | return m.Unmarshal(b) 280 | } 281 | func (m *B) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 282 | if deterministic { 283 | return xxx_messageInfo_B.Marshal(b, m, deterministic) 284 | } else { 285 | b = b[:cap(b)] 286 | n, err := m.MarshalToSizedBuffer(b) 287 | if err != nil { 288 | return nil, err 289 | } 290 | return b[:n], nil 291 | } 292 | } 293 | func (m *B) XXX_Merge(src proto.Message) { 294 | xxx_messageInfo_B.Merge(m, src) 295 | } 296 | func (m *B) XXX_Size() int { 297 | return m.Size() 298 | } 299 | func (m *B) XXX_DiscardUnknown() { 300 | xxx_messageInfo_B.DiscardUnknown(m) 301 | } 302 | 303 | var xxx_messageInfo_B proto.InternalMessageInfo 304 | 305 | func (m *B) GetY() uint32 { 306 | if m != nil { 307 | return m.Y 308 | } 309 | return 0 310 | } 311 | 312 | type C struct { 313 | Z bool `protobuf:"varint,1,opt,name=z,proto3" json:"z,omitempty"` 314 | } 315 | 316 | func (m *C) Reset() { *m = C{} } 317 | func (m *C) String() string { return proto.CompactTextString(m) } 318 | func (*C) ProtoMessage() {} 319 | func (*C) Descriptor() ([]byte, []int) { 320 | return fileDescriptor_edbe9e0eab89a1a7, []int{4} 321 | } 322 | func (m *C) XXX_Unmarshal(b []byte) error { 323 | return m.Unmarshal(b) 324 | } 325 | func (m *C) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 326 | if deterministic { 327 | return xxx_messageInfo_C.Marshal(b, m, deterministic) 328 | } else { 329 | b = b[:cap(b)] 330 | n, err := m.MarshalToSizedBuffer(b) 331 | if err != nil { 332 | return nil, err 333 | } 334 | return b[:n], nil 335 | } 336 | } 337 | func (m *C) XXX_Merge(src proto.Message) { 338 | xxx_messageInfo_C.Merge(m, src) 339 | } 340 | func (m *C) XXX_Size() int { 341 | return m.Size() 342 | } 343 | func (m *C) XXX_DiscardUnknown() { 344 | xxx_messageInfo_C.DiscardUnknown(m) 345 | } 346 | 347 | var xxx_messageInfo_C proto.InternalMessageInfo 348 | 349 | func (m *C) GetZ() bool { 350 | if m != nil { 351 | return m.Z 352 | } 353 | return false 354 | } 355 | 356 | type SomeContainer struct { 357 | SomeInterface *types.Any `protobuf:"bytes,1,opt,name=some_interface,json=someInterface,proto3" json:"some_interface,omitempty"` 358 | } 359 | 360 | func (m *SomeContainer) Reset() { *m = SomeContainer{} } 361 | func (m *SomeContainer) String() string { return proto.CompactTextString(m) } 362 | func (*SomeContainer) ProtoMessage() {} 363 | func (*SomeContainer) Descriptor() ([]byte, []int) { 364 | return fileDescriptor_edbe9e0eab89a1a7, []int{5} 365 | } 366 | func (m *SomeContainer) XXX_Unmarshal(b []byte) error { 367 | return m.Unmarshal(b) 368 | } 369 | func (m *SomeContainer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 370 | if deterministic { 371 | return xxx_messageInfo_SomeContainer.Marshal(b, m, deterministic) 372 | } else { 373 | b = b[:cap(b)] 374 | n, err := m.MarshalToSizedBuffer(b) 375 | if err != nil { 376 | return nil, err 377 | } 378 | return b[:n], nil 379 | } 380 | } 381 | func (m *SomeContainer) XXX_Merge(src proto.Message) { 382 | xxx_messageInfo_SomeContainer.Merge(m, src) 383 | } 384 | func (m *SomeContainer) XXX_Size() int { 385 | return m.Size() 386 | } 387 | func (m *SomeContainer) XXX_DiscardUnknown() { 388 | xxx_messageInfo_SomeContainer.DiscardUnknown(m) 389 | } 390 | 391 | var xxx_messageInfo_SomeContainer proto.InternalMessageInfo 392 | 393 | func (m *SomeContainer) GetSomeInterface() *types.Any { 394 | if m != nil { 395 | return m.SomeInterface 396 | } 397 | return nil 398 | } 399 | 400 | type SomeImpl1 struct { 401 | X int64 `protobuf:"varint,1,opt,name=x,proto3" json:"x,omitempty"` 402 | } 403 | 404 | func (m *SomeImpl1) Reset() { *m = SomeImpl1{} } 405 | func (m *SomeImpl1) String() string { return proto.CompactTextString(m) } 406 | func (*SomeImpl1) ProtoMessage() {} 407 | func (*SomeImpl1) Descriptor() ([]byte, []int) { 408 | return fileDescriptor_edbe9e0eab89a1a7, []int{6} 409 | } 410 | func (m *SomeImpl1) XXX_Unmarshal(b []byte) error { 411 | return m.Unmarshal(b) 412 | } 413 | func (m *SomeImpl1) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 414 | if deterministic { 415 | return xxx_messageInfo_SomeImpl1.Marshal(b, m, deterministic) 416 | } else { 417 | b = b[:cap(b)] 418 | n, err := m.MarshalToSizedBuffer(b) 419 | if err != nil { 420 | return nil, err 421 | } 422 | return b[:n], nil 423 | } 424 | } 425 | func (m *SomeImpl1) XXX_Merge(src proto.Message) { 426 | xxx_messageInfo_SomeImpl1.Merge(m, src) 427 | } 428 | func (m *SomeImpl1) XXX_Size() int { 429 | return m.Size() 430 | } 431 | func (m *SomeImpl1) XXX_DiscardUnknown() { 432 | xxx_messageInfo_SomeImpl1.DiscardUnknown(m) 433 | } 434 | 435 | var xxx_messageInfo_SomeImpl1 proto.InternalMessageInfo 436 | 437 | func (m *SomeImpl1) GetX() int64 { 438 | if m != nil { 439 | return m.X 440 | } 441 | return 0 442 | } 443 | 444 | type SomeImpl2 struct { 445 | Y string `protobuf:"bytes,2,opt,name=y,proto3" json:"y,omitempty"` 446 | } 447 | 448 | func (m *SomeImpl2) Reset() { *m = SomeImpl2{} } 449 | func (m *SomeImpl2) String() string { return proto.CompactTextString(m) } 450 | func (*SomeImpl2) ProtoMessage() {} 451 | func (*SomeImpl2) Descriptor() ([]byte, []int) { 452 | return fileDescriptor_edbe9e0eab89a1a7, []int{7} 453 | } 454 | func (m *SomeImpl2) XXX_Unmarshal(b []byte) error { 455 | return m.Unmarshal(b) 456 | } 457 | func (m *SomeImpl2) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { 458 | if deterministic { 459 | return xxx_messageInfo_SomeImpl2.Marshal(b, m, deterministic) 460 | } else { 461 | b = b[:cap(b)] 462 | n, err := m.MarshalToSizedBuffer(b) 463 | if err != nil { 464 | return nil, err 465 | } 466 | return b[:n], nil 467 | } 468 | } 469 | func (m *SomeImpl2) XXX_Merge(src proto.Message) { 470 | xxx_messageInfo_SomeImpl2.Merge(m, src) 471 | } 472 | func (m *SomeImpl2) XXX_Size() int { 473 | return m.Size() 474 | } 475 | func (m *SomeImpl2) XXX_DiscardUnknown() { 476 | xxx_messageInfo_SomeImpl2.DiscardUnknown(m) 477 | } 478 | 479 | var xxx_messageInfo_SomeImpl2 proto.InternalMessageInfo 480 | 481 | func (m *SomeImpl2) GetY() string { 482 | if m != nil { 483 | return m.Y 484 | } 485 | return "" 486 | } 487 | 488 | func init() { 489 | proto.RegisterType((*ABC)(nil), "test.abc.ABC") 490 | proto.RegisterType((*ABCNonPointer)(nil), "test.abc.ABCNonPointer") 491 | proto.RegisterType((*A)(nil), "test.abc.A") 492 | proto.RegisterType((*B)(nil), "test.abc.B") 493 | proto.RegisterType((*C)(nil), "test.abc.C") 494 | proto.RegisterType((*SomeContainer)(nil), "test.abc.SomeContainer") 495 | proto.RegisterType((*SomeImpl1)(nil), "test.abc.SomeImpl1") 496 | proto.RegisterType((*SomeImpl2)(nil), "test.abc.SomeImpl2") 497 | } 498 | 499 | func init() { proto.RegisterFile("test/abc.proto", fileDescriptor_edbe9e0eab89a1a7) } 500 | 501 | var fileDescriptor_edbe9e0eab89a1a7 = []byte{ 502 | // 377 bytes of a gzipped FileDescriptorProto 503 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x91, 0xc1, 0x4a, 0xc3, 0x40, 504 | 0x10, 0x86, 0x33, 0xc6, 0x4a, 0xbb, 0x6d, 0x0a, 0x0d, 0x1e, 0x6a, 0x85, 0x20, 0x39, 0x89, 0x98, 505 | 0x0d, 0x56, 0x05, 0xed, 0x2d, 0xc9, 0x45, 0x0f, 0x16, 0x89, 0x37, 0x2f, 0x25, 0x09, 0xdb, 0x18, 506 | 0x6c, 0x76, 0x4b, 0x92, 0x62, 0xd3, 0xa7, 0xf0, 0x05, 0xbc, 0xfb, 0x00, 0x7d, 0x08, 0xe9, 0xa9, 507 | 0x78, 0xf2, 0x28, 0xed, 0x8b, 0xc8, 0x6e, 0x2c, 0x96, 0xe2, 0x4d, 0x3c, 0xce, 0xff, 0x4d, 0x36, 508 | 0xdf, 0xcc, 0xa0, 0x7a, 0x46, 0xd2, 0xcc, 0xf4, 0xfc, 0x00, 0x0f, 0x13, 0x96, 0x31, 0xb5, 0xcc, 509 | 0x6b, 0xec, 0xf9, 0x41, 0xab, 0x16, 0xb0, 0x34, 0x66, 0x69, 0x91, 0xb7, 0xf6, 0x42, 0xc6, 0xc2, 510 | 0x01, 0x31, 0x45, 0xe5, 0x8f, 0xfa, 0xa6, 0x47, 0xf3, 0x02, 0xe9, 0x2f, 0x80, 0x64, 0xcb, 0x76, 511 | 0xd4, 0x7d, 0x04, 0x5e, 0x13, 0x0e, 0xe0, 0xb0, 0xda, 0xae, 0xe2, 0xd5, 0x33, 0xd8, 0xba, 0x92, 512 | 0x5c, 0xf0, 0x38, 0xf4, 0x9b, 0x5b, 0x9b, 0xd0, 0xe6, 0xd0, 0xe7, 0x30, 0x68, 0xca, 0x9b, 0xd0, 513 | 0xe1, 0x30, 0xe8, 0x5c, 0xcc, 0xa6, 0xc6, 0x59, 0x18, 0x65, 0x0f, 0x23, 0x1f, 0x07, 0x2c, 0x36, 514 | 0x13, 0x12, 0x12, 0x6a, 0x50, 0x92, 0x3d, 0xb1, 0xe4, 0xd1, 0x2c, 0x24, 0x0d, 0x61, 0x62, 0x8a, 515 | 0x59, 0xa2, 0xbe, 0x17, 0x10, 0x7c, 0x93, 0x86, 0x76, 0x09, 0xc9, 0xe9, 0x28, 0xd6, 0x5f, 0x01, 516 | 0x29, 0x96, 0xed, 0x74, 0x19, 0xbd, 0x65, 0x11, 0xcd, 0x48, 0xf2, 0x5f, 0xa6, 0x97, 0xb3, 0xa9, 517 | 0x71, 0x7e, 0xf4, 0x17, 0xd5, 0x06, 0x02, 0x4b, 0xad, 0x21, 0x18, 0x0b, 0xbb, 0x92, 0x0b, 0x63, 518 | 0x1e, 0xd9, 0x3c, 0xca, 0x45, 0xa4, 0xb8, 0x90, 0xf3, 0xc8, 0xe1, 0xd1, 0x44, 0x44, 0x65, 0x17, 519 | 0x26, 0x7a, 0x0f, 0x29, 0x77, 0x2c, 0x26, 0x0e, 0xa3, 0x99, 0x17, 0x51, 0x92, 0xa8, 0x5d, 0x54, 520 | 0x4f, 0x59, 0x4c, 0x7a, 0x62, 0x60, 0xfe, 0x9b, 0xef, 0x79, 0x77, 0x71, 0x71, 0x48, 0xbc, 0x3a, 521 | 0x24, 0xb6, 0x68, 0x6e, 0x37, 0x66, 0x53, 0x43, 0x3c, 0x70, 0xbd, 0x6a, 0x77, 0x95, 0x74, 0xbd, 522 | 0xd4, 0x8f, 0x51, 0x45, 0xf0, 0x78, 0x38, 0x38, 0xf9, 0x31, 0x94, 0x5d, 0x18, 0x77, 0x1a, 0xef, 523 | 0x9b, 0x1f, 0xaf, 0x77, 0xb7, 0x0b, 0x79, 0xbe, 0xd0, 0x8a, 0x0b, 0xf9, 0x2f, 0xdd, 0xb6, 0xf6, 524 | 0xb6, 0xd0, 0x60, 0xbe, 0xd0, 0xe0, 0x73, 0xa1, 0xc1, 0xf3, 0x52, 0x93, 0xe6, 0x4b, 0x4d, 0xfa, 525 | 0x58, 0x6a, 0xd2, 0xfd, 0x36, 0x5f, 0x93, 0xbf, 0x23, 0x5c, 0x4f, 0xbf, 0x02, 0x00, 0x00, 0xff, 526 | 0xff, 0xa6, 0xd8, 0xf4, 0x51, 0xac, 0x02, 0x00, 0x00, 527 | } 528 | 529 | func (this *ABC) GetMsg() github_com_regen_network_cosmos_proto_test_iface.Msg { 530 | if x := this.GetA(); x != nil { 531 | return x 532 | } 533 | if x := this.GetB(); x != nil { 534 | return x 535 | } 536 | if x := this.GetC(); x != nil { 537 | return x 538 | } 539 | return nil 540 | } 541 | 542 | func (this *ABC) SetMsg(value github_com_regen_network_cosmos_proto_test_iface.Msg) error { 543 | if value == nil { 544 | this.Sum = nil 545 | return nil 546 | } 547 | switch vt := value.(type) { 548 | case *A: 549 | this.Sum = &ABC_A{vt} 550 | return nil 551 | case A: 552 | this.Sum = &ABC_A{&vt} 553 | return nil 554 | case *B: 555 | this.Sum = &ABC_B{vt} 556 | return nil 557 | case B: 558 | this.Sum = &ABC_B{&vt} 559 | return nil 560 | case *C: 561 | this.Sum = &ABC_C{vt} 562 | return nil 563 | case C: 564 | this.Sum = &ABC_C{&vt} 565 | return nil 566 | } 567 | return fmt.Errorf("can't encode value of type %T as message ABC", value) 568 | } 569 | 570 | func (this *ABCNonPointer) GetMsg() github_com_regen_network_cosmos_proto_test_iface.Msg { 571 | if x := this.GetA(); x != nil { 572 | return x 573 | } 574 | if x := this.GetB(); x != nil { 575 | return x 576 | } 577 | if x := this.GetC(); x != nil { 578 | return x 579 | } 580 | return nil 581 | } 582 | 583 | func (this *ABCNonPointer) SetMsg(value github_com_regen_network_cosmos_proto_test_iface.Msg) error { 584 | if value == nil { 585 | this.Sum = nil 586 | return nil 587 | } 588 | switch vt := value.(type) { 589 | case *A: 590 | this.Sum = &ABCNonPointer_A{vt} 591 | return nil 592 | case *B: 593 | this.Sum = &ABCNonPointer_B{vt} 594 | return nil 595 | case *C: 596 | this.Sum = &ABCNonPointer_C{vt} 597 | return nil 598 | } 599 | return fmt.Errorf("can't encode value of type %T as message ABCNonPointer", value) 600 | } 601 | 602 | func (m *ABC) Marshal() (dAtA []byte, err error) { 603 | size := m.Size() 604 | dAtA = make([]byte, size) 605 | n, err := m.MarshalToSizedBuffer(dAtA[:size]) 606 | if err != nil { 607 | return nil, err 608 | } 609 | return dAtA[:n], nil 610 | } 611 | 612 | func (m *ABC) MarshalTo(dAtA []byte) (int, error) { 613 | size := m.Size() 614 | return m.MarshalToSizedBuffer(dAtA[:size]) 615 | } 616 | 617 | func (m *ABC) MarshalToSizedBuffer(dAtA []byte) (int, error) { 618 | i := len(dAtA) 619 | _ = i 620 | var l int 621 | _ = l 622 | if m.Sum != nil { 623 | { 624 | size := m.Sum.Size() 625 | i -= size 626 | if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { 627 | return 0, err 628 | } 629 | } 630 | } 631 | return len(dAtA) - i, nil 632 | } 633 | 634 | func (m *ABC_A) MarshalTo(dAtA []byte) (int, error) { 635 | size := m.Size() 636 | return m.MarshalToSizedBuffer(dAtA[:size]) 637 | } 638 | 639 | func (m *ABC_A) MarshalToSizedBuffer(dAtA []byte) (int, error) { 640 | i := len(dAtA) 641 | if m.A != nil { 642 | { 643 | size, err := m.A.MarshalToSizedBuffer(dAtA[:i]) 644 | if err != nil { 645 | return 0, err 646 | } 647 | i -= size 648 | i = encodeVarintAbc(dAtA, i, uint64(size)) 649 | } 650 | i-- 651 | dAtA[i] = 0xa 652 | } 653 | return len(dAtA) - i, nil 654 | } 655 | func (m *ABC_B) MarshalTo(dAtA []byte) (int, error) { 656 | size := m.Size() 657 | return m.MarshalToSizedBuffer(dAtA[:size]) 658 | } 659 | 660 | func (m *ABC_B) MarshalToSizedBuffer(dAtA []byte) (int, error) { 661 | i := len(dAtA) 662 | if m.B != nil { 663 | { 664 | size, err := m.B.MarshalToSizedBuffer(dAtA[:i]) 665 | if err != nil { 666 | return 0, err 667 | } 668 | i -= size 669 | i = encodeVarintAbc(dAtA, i, uint64(size)) 670 | } 671 | i-- 672 | dAtA[i] = 0x12 673 | } 674 | return len(dAtA) - i, nil 675 | } 676 | func (m *ABC_C) MarshalTo(dAtA []byte) (int, error) { 677 | size := m.Size() 678 | return m.MarshalToSizedBuffer(dAtA[:size]) 679 | } 680 | 681 | func (m *ABC_C) MarshalToSizedBuffer(dAtA []byte) (int, error) { 682 | i := len(dAtA) 683 | if m.C != nil { 684 | { 685 | size, err := m.C.MarshalToSizedBuffer(dAtA[:i]) 686 | if err != nil { 687 | return 0, err 688 | } 689 | i -= size 690 | i = encodeVarintAbc(dAtA, i, uint64(size)) 691 | } 692 | i-- 693 | dAtA[i] = 0x1a 694 | } 695 | return len(dAtA) - i, nil 696 | } 697 | func (m *ABCNonPointer) Marshal() (dAtA []byte, err error) { 698 | size := m.Size() 699 | dAtA = make([]byte, size) 700 | n, err := m.MarshalToSizedBuffer(dAtA[:size]) 701 | if err != nil { 702 | return nil, err 703 | } 704 | return dAtA[:n], nil 705 | } 706 | 707 | func (m *ABCNonPointer) MarshalTo(dAtA []byte) (int, error) { 708 | size := m.Size() 709 | return m.MarshalToSizedBuffer(dAtA[:size]) 710 | } 711 | 712 | func (m *ABCNonPointer) MarshalToSizedBuffer(dAtA []byte) (int, error) { 713 | i := len(dAtA) 714 | _ = i 715 | var l int 716 | _ = l 717 | if m.Sum != nil { 718 | { 719 | size := m.Sum.Size() 720 | i -= size 721 | if _, err := m.Sum.MarshalTo(dAtA[i:]); err != nil { 722 | return 0, err 723 | } 724 | } 725 | } 726 | return len(dAtA) - i, nil 727 | } 728 | 729 | func (m *ABCNonPointer_A) MarshalTo(dAtA []byte) (int, error) { 730 | size := m.Size() 731 | return m.MarshalToSizedBuffer(dAtA[:size]) 732 | } 733 | 734 | func (m *ABCNonPointer_A) MarshalToSizedBuffer(dAtA []byte) (int, error) { 735 | i := len(dAtA) 736 | if m.A != nil { 737 | { 738 | size, err := m.A.MarshalToSizedBuffer(dAtA[:i]) 739 | if err != nil { 740 | return 0, err 741 | } 742 | i -= size 743 | i = encodeVarintAbc(dAtA, i, uint64(size)) 744 | } 745 | i-- 746 | dAtA[i] = 0xa 747 | } 748 | return len(dAtA) - i, nil 749 | } 750 | func (m *ABCNonPointer_B) MarshalTo(dAtA []byte) (int, error) { 751 | size := m.Size() 752 | return m.MarshalToSizedBuffer(dAtA[:size]) 753 | } 754 | 755 | func (m *ABCNonPointer_B) MarshalToSizedBuffer(dAtA []byte) (int, error) { 756 | i := len(dAtA) 757 | if m.B != nil { 758 | { 759 | size, err := m.B.MarshalToSizedBuffer(dAtA[:i]) 760 | if err != nil { 761 | return 0, err 762 | } 763 | i -= size 764 | i = encodeVarintAbc(dAtA, i, uint64(size)) 765 | } 766 | i-- 767 | dAtA[i] = 0x12 768 | } 769 | return len(dAtA) - i, nil 770 | } 771 | func (m *ABCNonPointer_C) MarshalTo(dAtA []byte) (int, error) { 772 | size := m.Size() 773 | return m.MarshalToSizedBuffer(dAtA[:size]) 774 | } 775 | 776 | func (m *ABCNonPointer_C) MarshalToSizedBuffer(dAtA []byte) (int, error) { 777 | i := len(dAtA) 778 | if m.C != nil { 779 | { 780 | size, err := m.C.MarshalToSizedBuffer(dAtA[:i]) 781 | if err != nil { 782 | return 0, err 783 | } 784 | i -= size 785 | i = encodeVarintAbc(dAtA, i, uint64(size)) 786 | } 787 | i-- 788 | dAtA[i] = 0x1a 789 | } 790 | return len(dAtA) - i, nil 791 | } 792 | func (m *A) Marshal() (dAtA []byte, err error) { 793 | size := m.Size() 794 | dAtA = make([]byte, size) 795 | n, err := m.MarshalToSizedBuffer(dAtA[:size]) 796 | if err != nil { 797 | return nil, err 798 | } 799 | return dAtA[:n], nil 800 | } 801 | 802 | func (m *A) MarshalTo(dAtA []byte) (int, error) { 803 | size := m.Size() 804 | return m.MarshalToSizedBuffer(dAtA[:size]) 805 | } 806 | 807 | func (m *A) MarshalToSizedBuffer(dAtA []byte) (int, error) { 808 | i := len(dAtA) 809 | _ = i 810 | var l int 811 | _ = l 812 | if m.X != 0 { 813 | i = encodeVarintAbc(dAtA, i, uint64(m.X)) 814 | i-- 815 | dAtA[i] = 0x8 816 | } 817 | return len(dAtA) - i, nil 818 | } 819 | 820 | func (m *B) Marshal() (dAtA []byte, err error) { 821 | size := m.Size() 822 | dAtA = make([]byte, size) 823 | n, err := m.MarshalToSizedBuffer(dAtA[:size]) 824 | if err != nil { 825 | return nil, err 826 | } 827 | return dAtA[:n], nil 828 | } 829 | 830 | func (m *B) MarshalTo(dAtA []byte) (int, error) { 831 | size := m.Size() 832 | return m.MarshalToSizedBuffer(dAtA[:size]) 833 | } 834 | 835 | func (m *B) MarshalToSizedBuffer(dAtA []byte) (int, error) { 836 | i := len(dAtA) 837 | _ = i 838 | var l int 839 | _ = l 840 | if m.Y != 0 { 841 | i = encodeVarintAbc(dAtA, i, uint64(m.Y)) 842 | i-- 843 | dAtA[i] = 0x8 844 | } 845 | return len(dAtA) - i, nil 846 | } 847 | 848 | func (m *C) Marshal() (dAtA []byte, err error) { 849 | size := m.Size() 850 | dAtA = make([]byte, size) 851 | n, err := m.MarshalToSizedBuffer(dAtA[:size]) 852 | if err != nil { 853 | return nil, err 854 | } 855 | return dAtA[:n], nil 856 | } 857 | 858 | func (m *C) MarshalTo(dAtA []byte) (int, error) { 859 | size := m.Size() 860 | return m.MarshalToSizedBuffer(dAtA[:size]) 861 | } 862 | 863 | func (m *C) MarshalToSizedBuffer(dAtA []byte) (int, error) { 864 | i := len(dAtA) 865 | _ = i 866 | var l int 867 | _ = l 868 | if m.Z { 869 | i-- 870 | if m.Z { 871 | dAtA[i] = 1 872 | } else { 873 | dAtA[i] = 0 874 | } 875 | i-- 876 | dAtA[i] = 0x8 877 | } 878 | return len(dAtA) - i, nil 879 | } 880 | 881 | func (m *SomeContainer) Marshal() (dAtA []byte, err error) { 882 | size := m.Size() 883 | dAtA = make([]byte, size) 884 | n, err := m.MarshalToSizedBuffer(dAtA[:size]) 885 | if err != nil { 886 | return nil, err 887 | } 888 | return dAtA[:n], nil 889 | } 890 | 891 | func (m *SomeContainer) MarshalTo(dAtA []byte) (int, error) { 892 | size := m.Size() 893 | return m.MarshalToSizedBuffer(dAtA[:size]) 894 | } 895 | 896 | func (m *SomeContainer) MarshalToSizedBuffer(dAtA []byte) (int, error) { 897 | i := len(dAtA) 898 | _ = i 899 | var l int 900 | _ = l 901 | if m.SomeInterface != nil { 902 | { 903 | size, err := m.SomeInterface.MarshalToSizedBuffer(dAtA[:i]) 904 | if err != nil { 905 | return 0, err 906 | } 907 | i -= size 908 | i = encodeVarintAbc(dAtA, i, uint64(size)) 909 | } 910 | i-- 911 | dAtA[i] = 0xa 912 | } 913 | return len(dAtA) - i, nil 914 | } 915 | 916 | func (m *SomeImpl1) Marshal() (dAtA []byte, err error) { 917 | size := m.Size() 918 | dAtA = make([]byte, size) 919 | n, err := m.MarshalToSizedBuffer(dAtA[:size]) 920 | if err != nil { 921 | return nil, err 922 | } 923 | return dAtA[:n], nil 924 | } 925 | 926 | func (m *SomeImpl1) MarshalTo(dAtA []byte) (int, error) { 927 | size := m.Size() 928 | return m.MarshalToSizedBuffer(dAtA[:size]) 929 | } 930 | 931 | func (m *SomeImpl1) MarshalToSizedBuffer(dAtA []byte) (int, error) { 932 | i := len(dAtA) 933 | _ = i 934 | var l int 935 | _ = l 936 | if m.X != 0 { 937 | i = encodeVarintAbc(dAtA, i, uint64(m.X)) 938 | i-- 939 | dAtA[i] = 0x8 940 | } 941 | return len(dAtA) - i, nil 942 | } 943 | 944 | func (m *SomeImpl2) Marshal() (dAtA []byte, err error) { 945 | size := m.Size() 946 | dAtA = make([]byte, size) 947 | n, err := m.MarshalToSizedBuffer(dAtA[:size]) 948 | if err != nil { 949 | return nil, err 950 | } 951 | return dAtA[:n], nil 952 | } 953 | 954 | func (m *SomeImpl2) MarshalTo(dAtA []byte) (int, error) { 955 | size := m.Size() 956 | return m.MarshalToSizedBuffer(dAtA[:size]) 957 | } 958 | 959 | func (m *SomeImpl2) MarshalToSizedBuffer(dAtA []byte) (int, error) { 960 | i := len(dAtA) 961 | _ = i 962 | var l int 963 | _ = l 964 | if len(m.Y) > 0 { 965 | i -= len(m.Y) 966 | copy(dAtA[i:], m.Y) 967 | i = encodeVarintAbc(dAtA, i, uint64(len(m.Y))) 968 | i-- 969 | dAtA[i] = 0x12 970 | } 971 | return len(dAtA) - i, nil 972 | } 973 | 974 | func encodeVarintAbc(dAtA []byte, offset int, v uint64) int { 975 | offset -= sovAbc(v) 976 | base := offset 977 | for v >= 1<<7 { 978 | dAtA[offset] = uint8(v&0x7f | 0x80) 979 | v >>= 7 980 | offset++ 981 | } 982 | dAtA[offset] = uint8(v) 983 | return base 984 | } 985 | func (m *ABC) Size() (n int) { 986 | if m == nil { 987 | return 0 988 | } 989 | var l int 990 | _ = l 991 | if m.Sum != nil { 992 | n += m.Sum.Size() 993 | } 994 | return n 995 | } 996 | 997 | func (m *ABC_A) Size() (n int) { 998 | if m == nil { 999 | return 0 1000 | } 1001 | var l int 1002 | _ = l 1003 | if m.A != nil { 1004 | l = m.A.Size() 1005 | n += 1 + l + sovAbc(uint64(l)) 1006 | } 1007 | return n 1008 | } 1009 | func (m *ABC_B) Size() (n int) { 1010 | if m == nil { 1011 | return 0 1012 | } 1013 | var l int 1014 | _ = l 1015 | if m.B != nil { 1016 | l = m.B.Size() 1017 | n += 1 + l + sovAbc(uint64(l)) 1018 | } 1019 | return n 1020 | } 1021 | func (m *ABC_C) Size() (n int) { 1022 | if m == nil { 1023 | return 0 1024 | } 1025 | var l int 1026 | _ = l 1027 | if m.C != nil { 1028 | l = m.C.Size() 1029 | n += 1 + l + sovAbc(uint64(l)) 1030 | } 1031 | return n 1032 | } 1033 | func (m *ABCNonPointer) Size() (n int) { 1034 | if m == nil { 1035 | return 0 1036 | } 1037 | var l int 1038 | _ = l 1039 | if m.Sum != nil { 1040 | n += m.Sum.Size() 1041 | } 1042 | return n 1043 | } 1044 | 1045 | func (m *ABCNonPointer_A) Size() (n int) { 1046 | if m == nil { 1047 | return 0 1048 | } 1049 | var l int 1050 | _ = l 1051 | if m.A != nil { 1052 | l = m.A.Size() 1053 | n += 1 + l + sovAbc(uint64(l)) 1054 | } 1055 | return n 1056 | } 1057 | func (m *ABCNonPointer_B) Size() (n int) { 1058 | if m == nil { 1059 | return 0 1060 | } 1061 | var l int 1062 | _ = l 1063 | if m.B != nil { 1064 | l = m.B.Size() 1065 | n += 1 + l + sovAbc(uint64(l)) 1066 | } 1067 | return n 1068 | } 1069 | func (m *ABCNonPointer_C) Size() (n int) { 1070 | if m == nil { 1071 | return 0 1072 | } 1073 | var l int 1074 | _ = l 1075 | if m.C != nil { 1076 | l = m.C.Size() 1077 | n += 1 + l + sovAbc(uint64(l)) 1078 | } 1079 | return n 1080 | } 1081 | func (m *A) Size() (n int) { 1082 | if m == nil { 1083 | return 0 1084 | } 1085 | var l int 1086 | _ = l 1087 | if m.X != 0 { 1088 | n += 1 + sovAbc(uint64(m.X)) 1089 | } 1090 | return n 1091 | } 1092 | 1093 | func (m *B) Size() (n int) { 1094 | if m == nil { 1095 | return 0 1096 | } 1097 | var l int 1098 | _ = l 1099 | if m.Y != 0 { 1100 | n += 1 + sovAbc(uint64(m.Y)) 1101 | } 1102 | return n 1103 | } 1104 | 1105 | func (m *C) Size() (n int) { 1106 | if m == nil { 1107 | return 0 1108 | } 1109 | var l int 1110 | _ = l 1111 | if m.Z { 1112 | n += 2 1113 | } 1114 | return n 1115 | } 1116 | 1117 | func (m *SomeContainer) Size() (n int) { 1118 | if m == nil { 1119 | return 0 1120 | } 1121 | var l int 1122 | _ = l 1123 | if m.SomeInterface != nil { 1124 | l = m.SomeInterface.Size() 1125 | n += 1 + l + sovAbc(uint64(l)) 1126 | } 1127 | return n 1128 | } 1129 | 1130 | func (m *SomeImpl1) Size() (n int) { 1131 | if m == nil { 1132 | return 0 1133 | } 1134 | var l int 1135 | _ = l 1136 | if m.X != 0 { 1137 | n += 1 + sovAbc(uint64(m.X)) 1138 | } 1139 | return n 1140 | } 1141 | 1142 | func (m *SomeImpl2) Size() (n int) { 1143 | if m == nil { 1144 | return 0 1145 | } 1146 | var l int 1147 | _ = l 1148 | l = len(m.Y) 1149 | if l > 0 { 1150 | n += 1 + l + sovAbc(uint64(l)) 1151 | } 1152 | return n 1153 | } 1154 | 1155 | func sovAbc(x uint64) (n int) { 1156 | return (math_bits.Len64(x|1) + 6) / 7 1157 | } 1158 | func sozAbc(x uint64) (n int) { 1159 | return sovAbc(uint64((x << 1) ^ uint64((int64(x) >> 63)))) 1160 | } 1161 | func (m *ABC) Unmarshal(dAtA []byte) error { 1162 | l := len(dAtA) 1163 | iNdEx := 0 1164 | for iNdEx < l { 1165 | preIndex := iNdEx 1166 | var wire uint64 1167 | for shift := uint(0); ; shift += 7 { 1168 | if shift >= 64 { 1169 | return ErrIntOverflowAbc 1170 | } 1171 | if iNdEx >= l { 1172 | return io.ErrUnexpectedEOF 1173 | } 1174 | b := dAtA[iNdEx] 1175 | iNdEx++ 1176 | wire |= uint64(b&0x7F) << shift 1177 | if b < 0x80 { 1178 | break 1179 | } 1180 | } 1181 | fieldNum := int32(wire >> 3) 1182 | wireType := int(wire & 0x7) 1183 | if wireType == 4 { 1184 | return fmt.Errorf("proto: ABC: wiretype end group for non-group") 1185 | } 1186 | if fieldNum <= 0 { 1187 | return fmt.Errorf("proto: ABC: illegal tag %d (wire type %d)", fieldNum, wire) 1188 | } 1189 | switch fieldNum { 1190 | case 1: 1191 | if wireType != 2 { 1192 | return fmt.Errorf("proto: wrong wireType = %d for field A", wireType) 1193 | } 1194 | var msglen int 1195 | for shift := uint(0); ; shift += 7 { 1196 | if shift >= 64 { 1197 | return ErrIntOverflowAbc 1198 | } 1199 | if iNdEx >= l { 1200 | return io.ErrUnexpectedEOF 1201 | } 1202 | b := dAtA[iNdEx] 1203 | iNdEx++ 1204 | msglen |= int(b&0x7F) << shift 1205 | if b < 0x80 { 1206 | break 1207 | } 1208 | } 1209 | if msglen < 0 { 1210 | return ErrInvalidLengthAbc 1211 | } 1212 | postIndex := iNdEx + msglen 1213 | if postIndex < 0 { 1214 | return ErrInvalidLengthAbc 1215 | } 1216 | if postIndex > l { 1217 | return io.ErrUnexpectedEOF 1218 | } 1219 | v := &A{} 1220 | if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 1221 | return err 1222 | } 1223 | m.Sum = &ABC_A{v} 1224 | iNdEx = postIndex 1225 | case 2: 1226 | if wireType != 2 { 1227 | return fmt.Errorf("proto: wrong wireType = %d for field B", wireType) 1228 | } 1229 | var msglen int 1230 | for shift := uint(0); ; shift += 7 { 1231 | if shift >= 64 { 1232 | return ErrIntOverflowAbc 1233 | } 1234 | if iNdEx >= l { 1235 | return io.ErrUnexpectedEOF 1236 | } 1237 | b := dAtA[iNdEx] 1238 | iNdEx++ 1239 | msglen |= int(b&0x7F) << shift 1240 | if b < 0x80 { 1241 | break 1242 | } 1243 | } 1244 | if msglen < 0 { 1245 | return ErrInvalidLengthAbc 1246 | } 1247 | postIndex := iNdEx + msglen 1248 | if postIndex < 0 { 1249 | return ErrInvalidLengthAbc 1250 | } 1251 | if postIndex > l { 1252 | return io.ErrUnexpectedEOF 1253 | } 1254 | v := &B{} 1255 | if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 1256 | return err 1257 | } 1258 | m.Sum = &ABC_B{v} 1259 | iNdEx = postIndex 1260 | case 3: 1261 | if wireType != 2 { 1262 | return fmt.Errorf("proto: wrong wireType = %d for field C", wireType) 1263 | } 1264 | var msglen int 1265 | for shift := uint(0); ; shift += 7 { 1266 | if shift >= 64 { 1267 | return ErrIntOverflowAbc 1268 | } 1269 | if iNdEx >= l { 1270 | return io.ErrUnexpectedEOF 1271 | } 1272 | b := dAtA[iNdEx] 1273 | iNdEx++ 1274 | msglen |= int(b&0x7F) << shift 1275 | if b < 0x80 { 1276 | break 1277 | } 1278 | } 1279 | if msglen < 0 { 1280 | return ErrInvalidLengthAbc 1281 | } 1282 | postIndex := iNdEx + msglen 1283 | if postIndex < 0 { 1284 | return ErrInvalidLengthAbc 1285 | } 1286 | if postIndex > l { 1287 | return io.ErrUnexpectedEOF 1288 | } 1289 | v := &C{} 1290 | if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 1291 | return err 1292 | } 1293 | m.Sum = &ABC_C{v} 1294 | iNdEx = postIndex 1295 | default: 1296 | iNdEx = preIndex 1297 | skippy, err := skipAbc(dAtA[iNdEx:]) 1298 | if err != nil { 1299 | return err 1300 | } 1301 | if (skippy < 0) || (iNdEx+skippy) < 0 { 1302 | return ErrInvalidLengthAbc 1303 | } 1304 | if (iNdEx + skippy) > l { 1305 | return io.ErrUnexpectedEOF 1306 | } 1307 | iNdEx += skippy 1308 | } 1309 | } 1310 | 1311 | if iNdEx > l { 1312 | return io.ErrUnexpectedEOF 1313 | } 1314 | return nil 1315 | } 1316 | func (m *ABCNonPointer) Unmarshal(dAtA []byte) error { 1317 | l := len(dAtA) 1318 | iNdEx := 0 1319 | for iNdEx < l { 1320 | preIndex := iNdEx 1321 | var wire uint64 1322 | for shift := uint(0); ; shift += 7 { 1323 | if shift >= 64 { 1324 | return ErrIntOverflowAbc 1325 | } 1326 | if iNdEx >= l { 1327 | return io.ErrUnexpectedEOF 1328 | } 1329 | b := dAtA[iNdEx] 1330 | iNdEx++ 1331 | wire |= uint64(b&0x7F) << shift 1332 | if b < 0x80 { 1333 | break 1334 | } 1335 | } 1336 | fieldNum := int32(wire >> 3) 1337 | wireType := int(wire & 0x7) 1338 | if wireType == 4 { 1339 | return fmt.Errorf("proto: ABCNonPointer: wiretype end group for non-group") 1340 | } 1341 | if fieldNum <= 0 { 1342 | return fmt.Errorf("proto: ABCNonPointer: illegal tag %d (wire type %d)", fieldNum, wire) 1343 | } 1344 | switch fieldNum { 1345 | case 1: 1346 | if wireType != 2 { 1347 | return fmt.Errorf("proto: wrong wireType = %d for field A", wireType) 1348 | } 1349 | var msglen int 1350 | for shift := uint(0); ; shift += 7 { 1351 | if shift >= 64 { 1352 | return ErrIntOverflowAbc 1353 | } 1354 | if iNdEx >= l { 1355 | return io.ErrUnexpectedEOF 1356 | } 1357 | b := dAtA[iNdEx] 1358 | iNdEx++ 1359 | msglen |= int(b&0x7F) << shift 1360 | if b < 0x80 { 1361 | break 1362 | } 1363 | } 1364 | if msglen < 0 { 1365 | return ErrInvalidLengthAbc 1366 | } 1367 | postIndex := iNdEx + msglen 1368 | if postIndex < 0 { 1369 | return ErrInvalidLengthAbc 1370 | } 1371 | if postIndex > l { 1372 | return io.ErrUnexpectedEOF 1373 | } 1374 | v := &A{} 1375 | if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 1376 | return err 1377 | } 1378 | m.Sum = &ABCNonPointer_A{v} 1379 | iNdEx = postIndex 1380 | case 2: 1381 | if wireType != 2 { 1382 | return fmt.Errorf("proto: wrong wireType = %d for field B", wireType) 1383 | } 1384 | var msglen int 1385 | for shift := uint(0); ; shift += 7 { 1386 | if shift >= 64 { 1387 | return ErrIntOverflowAbc 1388 | } 1389 | if iNdEx >= l { 1390 | return io.ErrUnexpectedEOF 1391 | } 1392 | b := dAtA[iNdEx] 1393 | iNdEx++ 1394 | msglen |= int(b&0x7F) << shift 1395 | if b < 0x80 { 1396 | break 1397 | } 1398 | } 1399 | if msglen < 0 { 1400 | return ErrInvalidLengthAbc 1401 | } 1402 | postIndex := iNdEx + msglen 1403 | if postIndex < 0 { 1404 | return ErrInvalidLengthAbc 1405 | } 1406 | if postIndex > l { 1407 | return io.ErrUnexpectedEOF 1408 | } 1409 | v := &B{} 1410 | if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 1411 | return err 1412 | } 1413 | m.Sum = &ABCNonPointer_B{v} 1414 | iNdEx = postIndex 1415 | case 3: 1416 | if wireType != 2 { 1417 | return fmt.Errorf("proto: wrong wireType = %d for field C", wireType) 1418 | } 1419 | var msglen int 1420 | for shift := uint(0); ; shift += 7 { 1421 | if shift >= 64 { 1422 | return ErrIntOverflowAbc 1423 | } 1424 | if iNdEx >= l { 1425 | return io.ErrUnexpectedEOF 1426 | } 1427 | b := dAtA[iNdEx] 1428 | iNdEx++ 1429 | msglen |= int(b&0x7F) << shift 1430 | if b < 0x80 { 1431 | break 1432 | } 1433 | } 1434 | if msglen < 0 { 1435 | return ErrInvalidLengthAbc 1436 | } 1437 | postIndex := iNdEx + msglen 1438 | if postIndex < 0 { 1439 | return ErrInvalidLengthAbc 1440 | } 1441 | if postIndex > l { 1442 | return io.ErrUnexpectedEOF 1443 | } 1444 | v := &C{} 1445 | if err := v.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 1446 | return err 1447 | } 1448 | m.Sum = &ABCNonPointer_C{v} 1449 | iNdEx = postIndex 1450 | default: 1451 | iNdEx = preIndex 1452 | skippy, err := skipAbc(dAtA[iNdEx:]) 1453 | if err != nil { 1454 | return err 1455 | } 1456 | if (skippy < 0) || (iNdEx+skippy) < 0 { 1457 | return ErrInvalidLengthAbc 1458 | } 1459 | if (iNdEx + skippy) > l { 1460 | return io.ErrUnexpectedEOF 1461 | } 1462 | iNdEx += skippy 1463 | } 1464 | } 1465 | 1466 | if iNdEx > l { 1467 | return io.ErrUnexpectedEOF 1468 | } 1469 | return nil 1470 | } 1471 | func (m *A) Unmarshal(dAtA []byte) error { 1472 | l := len(dAtA) 1473 | iNdEx := 0 1474 | for iNdEx < l { 1475 | preIndex := iNdEx 1476 | var wire uint64 1477 | for shift := uint(0); ; shift += 7 { 1478 | if shift >= 64 { 1479 | return ErrIntOverflowAbc 1480 | } 1481 | if iNdEx >= l { 1482 | return io.ErrUnexpectedEOF 1483 | } 1484 | b := dAtA[iNdEx] 1485 | iNdEx++ 1486 | wire |= uint64(b&0x7F) << shift 1487 | if b < 0x80 { 1488 | break 1489 | } 1490 | } 1491 | fieldNum := int32(wire >> 3) 1492 | wireType := int(wire & 0x7) 1493 | if wireType == 4 { 1494 | return fmt.Errorf("proto: A: wiretype end group for non-group") 1495 | } 1496 | if fieldNum <= 0 { 1497 | return fmt.Errorf("proto: A: illegal tag %d (wire type %d)", fieldNum, wire) 1498 | } 1499 | switch fieldNum { 1500 | case 1: 1501 | if wireType != 0 { 1502 | return fmt.Errorf("proto: wrong wireType = %d for field X", wireType) 1503 | } 1504 | m.X = 0 1505 | for shift := uint(0); ; shift += 7 { 1506 | if shift >= 64 { 1507 | return ErrIntOverflowAbc 1508 | } 1509 | if iNdEx >= l { 1510 | return io.ErrUnexpectedEOF 1511 | } 1512 | b := dAtA[iNdEx] 1513 | iNdEx++ 1514 | m.X |= int32(b&0x7F) << shift 1515 | if b < 0x80 { 1516 | break 1517 | } 1518 | } 1519 | default: 1520 | iNdEx = preIndex 1521 | skippy, err := skipAbc(dAtA[iNdEx:]) 1522 | if err != nil { 1523 | return err 1524 | } 1525 | if (skippy < 0) || (iNdEx+skippy) < 0 { 1526 | return ErrInvalidLengthAbc 1527 | } 1528 | if (iNdEx + skippy) > l { 1529 | return io.ErrUnexpectedEOF 1530 | } 1531 | iNdEx += skippy 1532 | } 1533 | } 1534 | 1535 | if iNdEx > l { 1536 | return io.ErrUnexpectedEOF 1537 | } 1538 | return nil 1539 | } 1540 | func (m *B) Unmarshal(dAtA []byte) error { 1541 | l := len(dAtA) 1542 | iNdEx := 0 1543 | for iNdEx < l { 1544 | preIndex := iNdEx 1545 | var wire uint64 1546 | for shift := uint(0); ; shift += 7 { 1547 | if shift >= 64 { 1548 | return ErrIntOverflowAbc 1549 | } 1550 | if iNdEx >= l { 1551 | return io.ErrUnexpectedEOF 1552 | } 1553 | b := dAtA[iNdEx] 1554 | iNdEx++ 1555 | wire |= uint64(b&0x7F) << shift 1556 | if b < 0x80 { 1557 | break 1558 | } 1559 | } 1560 | fieldNum := int32(wire >> 3) 1561 | wireType := int(wire & 0x7) 1562 | if wireType == 4 { 1563 | return fmt.Errorf("proto: B: wiretype end group for non-group") 1564 | } 1565 | if fieldNum <= 0 { 1566 | return fmt.Errorf("proto: B: illegal tag %d (wire type %d)", fieldNum, wire) 1567 | } 1568 | switch fieldNum { 1569 | case 1: 1570 | if wireType != 0 { 1571 | return fmt.Errorf("proto: wrong wireType = %d for field Y", wireType) 1572 | } 1573 | m.Y = 0 1574 | for shift := uint(0); ; shift += 7 { 1575 | if shift >= 64 { 1576 | return ErrIntOverflowAbc 1577 | } 1578 | if iNdEx >= l { 1579 | return io.ErrUnexpectedEOF 1580 | } 1581 | b := dAtA[iNdEx] 1582 | iNdEx++ 1583 | m.Y |= uint32(b&0x7F) << shift 1584 | if b < 0x80 { 1585 | break 1586 | } 1587 | } 1588 | default: 1589 | iNdEx = preIndex 1590 | skippy, err := skipAbc(dAtA[iNdEx:]) 1591 | if err != nil { 1592 | return err 1593 | } 1594 | if (skippy < 0) || (iNdEx+skippy) < 0 { 1595 | return ErrInvalidLengthAbc 1596 | } 1597 | if (iNdEx + skippy) > l { 1598 | return io.ErrUnexpectedEOF 1599 | } 1600 | iNdEx += skippy 1601 | } 1602 | } 1603 | 1604 | if iNdEx > l { 1605 | return io.ErrUnexpectedEOF 1606 | } 1607 | return nil 1608 | } 1609 | func (m *C) Unmarshal(dAtA []byte) error { 1610 | l := len(dAtA) 1611 | iNdEx := 0 1612 | for iNdEx < l { 1613 | preIndex := iNdEx 1614 | var wire uint64 1615 | for shift := uint(0); ; shift += 7 { 1616 | if shift >= 64 { 1617 | return ErrIntOverflowAbc 1618 | } 1619 | if iNdEx >= l { 1620 | return io.ErrUnexpectedEOF 1621 | } 1622 | b := dAtA[iNdEx] 1623 | iNdEx++ 1624 | wire |= uint64(b&0x7F) << shift 1625 | if b < 0x80 { 1626 | break 1627 | } 1628 | } 1629 | fieldNum := int32(wire >> 3) 1630 | wireType := int(wire & 0x7) 1631 | if wireType == 4 { 1632 | return fmt.Errorf("proto: C: wiretype end group for non-group") 1633 | } 1634 | if fieldNum <= 0 { 1635 | return fmt.Errorf("proto: C: illegal tag %d (wire type %d)", fieldNum, wire) 1636 | } 1637 | switch fieldNum { 1638 | case 1: 1639 | if wireType != 0 { 1640 | return fmt.Errorf("proto: wrong wireType = %d for field Z", wireType) 1641 | } 1642 | var v int 1643 | for shift := uint(0); ; shift += 7 { 1644 | if shift >= 64 { 1645 | return ErrIntOverflowAbc 1646 | } 1647 | if iNdEx >= l { 1648 | return io.ErrUnexpectedEOF 1649 | } 1650 | b := dAtA[iNdEx] 1651 | iNdEx++ 1652 | v |= int(b&0x7F) << shift 1653 | if b < 0x80 { 1654 | break 1655 | } 1656 | } 1657 | m.Z = bool(v != 0) 1658 | default: 1659 | iNdEx = preIndex 1660 | skippy, err := skipAbc(dAtA[iNdEx:]) 1661 | if err != nil { 1662 | return err 1663 | } 1664 | if (skippy < 0) || (iNdEx+skippy) < 0 { 1665 | return ErrInvalidLengthAbc 1666 | } 1667 | if (iNdEx + skippy) > l { 1668 | return io.ErrUnexpectedEOF 1669 | } 1670 | iNdEx += skippy 1671 | } 1672 | } 1673 | 1674 | if iNdEx > l { 1675 | return io.ErrUnexpectedEOF 1676 | } 1677 | return nil 1678 | } 1679 | func (m *SomeContainer) Unmarshal(dAtA []byte) error { 1680 | l := len(dAtA) 1681 | iNdEx := 0 1682 | for iNdEx < l { 1683 | preIndex := iNdEx 1684 | var wire uint64 1685 | for shift := uint(0); ; shift += 7 { 1686 | if shift >= 64 { 1687 | return ErrIntOverflowAbc 1688 | } 1689 | if iNdEx >= l { 1690 | return io.ErrUnexpectedEOF 1691 | } 1692 | b := dAtA[iNdEx] 1693 | iNdEx++ 1694 | wire |= uint64(b&0x7F) << shift 1695 | if b < 0x80 { 1696 | break 1697 | } 1698 | } 1699 | fieldNum := int32(wire >> 3) 1700 | wireType := int(wire & 0x7) 1701 | if wireType == 4 { 1702 | return fmt.Errorf("proto: SomeContainer: wiretype end group for non-group") 1703 | } 1704 | if fieldNum <= 0 { 1705 | return fmt.Errorf("proto: SomeContainer: illegal tag %d (wire type %d)", fieldNum, wire) 1706 | } 1707 | switch fieldNum { 1708 | case 1: 1709 | if wireType != 2 { 1710 | return fmt.Errorf("proto: wrong wireType = %d for field SomeInterface", wireType) 1711 | } 1712 | var msglen int 1713 | for shift := uint(0); ; shift += 7 { 1714 | if shift >= 64 { 1715 | return ErrIntOverflowAbc 1716 | } 1717 | if iNdEx >= l { 1718 | return io.ErrUnexpectedEOF 1719 | } 1720 | b := dAtA[iNdEx] 1721 | iNdEx++ 1722 | msglen |= int(b&0x7F) << shift 1723 | if b < 0x80 { 1724 | break 1725 | } 1726 | } 1727 | if msglen < 0 { 1728 | return ErrInvalidLengthAbc 1729 | } 1730 | postIndex := iNdEx + msglen 1731 | if postIndex < 0 { 1732 | return ErrInvalidLengthAbc 1733 | } 1734 | if postIndex > l { 1735 | return io.ErrUnexpectedEOF 1736 | } 1737 | if m.SomeInterface == nil { 1738 | m.SomeInterface = &types.Any{} 1739 | } 1740 | if err := m.SomeInterface.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { 1741 | return err 1742 | } 1743 | iNdEx = postIndex 1744 | default: 1745 | iNdEx = preIndex 1746 | skippy, err := skipAbc(dAtA[iNdEx:]) 1747 | if err != nil { 1748 | return err 1749 | } 1750 | if (skippy < 0) || (iNdEx+skippy) < 0 { 1751 | return ErrInvalidLengthAbc 1752 | } 1753 | if (iNdEx + skippy) > l { 1754 | return io.ErrUnexpectedEOF 1755 | } 1756 | iNdEx += skippy 1757 | } 1758 | } 1759 | 1760 | if iNdEx > l { 1761 | return io.ErrUnexpectedEOF 1762 | } 1763 | return nil 1764 | } 1765 | func (m *SomeImpl1) Unmarshal(dAtA []byte) error { 1766 | l := len(dAtA) 1767 | iNdEx := 0 1768 | for iNdEx < l { 1769 | preIndex := iNdEx 1770 | var wire uint64 1771 | for shift := uint(0); ; shift += 7 { 1772 | if shift >= 64 { 1773 | return ErrIntOverflowAbc 1774 | } 1775 | if iNdEx >= l { 1776 | return io.ErrUnexpectedEOF 1777 | } 1778 | b := dAtA[iNdEx] 1779 | iNdEx++ 1780 | wire |= uint64(b&0x7F) << shift 1781 | if b < 0x80 { 1782 | break 1783 | } 1784 | } 1785 | fieldNum := int32(wire >> 3) 1786 | wireType := int(wire & 0x7) 1787 | if wireType == 4 { 1788 | return fmt.Errorf("proto: SomeImpl1: wiretype end group for non-group") 1789 | } 1790 | if fieldNum <= 0 { 1791 | return fmt.Errorf("proto: SomeImpl1: illegal tag %d (wire type %d)", fieldNum, wire) 1792 | } 1793 | switch fieldNum { 1794 | case 1: 1795 | if wireType != 0 { 1796 | return fmt.Errorf("proto: wrong wireType = %d for field X", wireType) 1797 | } 1798 | m.X = 0 1799 | for shift := uint(0); ; shift += 7 { 1800 | if shift >= 64 { 1801 | return ErrIntOverflowAbc 1802 | } 1803 | if iNdEx >= l { 1804 | return io.ErrUnexpectedEOF 1805 | } 1806 | b := dAtA[iNdEx] 1807 | iNdEx++ 1808 | m.X |= int64(b&0x7F) << shift 1809 | if b < 0x80 { 1810 | break 1811 | } 1812 | } 1813 | default: 1814 | iNdEx = preIndex 1815 | skippy, err := skipAbc(dAtA[iNdEx:]) 1816 | if err != nil { 1817 | return err 1818 | } 1819 | if (skippy < 0) || (iNdEx+skippy) < 0 { 1820 | return ErrInvalidLengthAbc 1821 | } 1822 | if (iNdEx + skippy) > l { 1823 | return io.ErrUnexpectedEOF 1824 | } 1825 | iNdEx += skippy 1826 | } 1827 | } 1828 | 1829 | if iNdEx > l { 1830 | return io.ErrUnexpectedEOF 1831 | } 1832 | return nil 1833 | } 1834 | func (m *SomeImpl2) Unmarshal(dAtA []byte) error { 1835 | l := len(dAtA) 1836 | iNdEx := 0 1837 | for iNdEx < l { 1838 | preIndex := iNdEx 1839 | var wire uint64 1840 | for shift := uint(0); ; shift += 7 { 1841 | if shift >= 64 { 1842 | return ErrIntOverflowAbc 1843 | } 1844 | if iNdEx >= l { 1845 | return io.ErrUnexpectedEOF 1846 | } 1847 | b := dAtA[iNdEx] 1848 | iNdEx++ 1849 | wire |= uint64(b&0x7F) << shift 1850 | if b < 0x80 { 1851 | break 1852 | } 1853 | } 1854 | fieldNum := int32(wire >> 3) 1855 | wireType := int(wire & 0x7) 1856 | if wireType == 4 { 1857 | return fmt.Errorf("proto: SomeImpl2: wiretype end group for non-group") 1858 | } 1859 | if fieldNum <= 0 { 1860 | return fmt.Errorf("proto: SomeImpl2: illegal tag %d (wire type %d)", fieldNum, wire) 1861 | } 1862 | switch fieldNum { 1863 | case 2: 1864 | if wireType != 2 { 1865 | return fmt.Errorf("proto: wrong wireType = %d for field Y", wireType) 1866 | } 1867 | var stringLen uint64 1868 | for shift := uint(0); ; shift += 7 { 1869 | if shift >= 64 { 1870 | return ErrIntOverflowAbc 1871 | } 1872 | if iNdEx >= l { 1873 | return io.ErrUnexpectedEOF 1874 | } 1875 | b := dAtA[iNdEx] 1876 | iNdEx++ 1877 | stringLen |= uint64(b&0x7F) << shift 1878 | if b < 0x80 { 1879 | break 1880 | } 1881 | } 1882 | intStringLen := int(stringLen) 1883 | if intStringLen < 0 { 1884 | return ErrInvalidLengthAbc 1885 | } 1886 | postIndex := iNdEx + intStringLen 1887 | if postIndex < 0 { 1888 | return ErrInvalidLengthAbc 1889 | } 1890 | if postIndex > l { 1891 | return io.ErrUnexpectedEOF 1892 | } 1893 | m.Y = string(dAtA[iNdEx:postIndex]) 1894 | iNdEx = postIndex 1895 | default: 1896 | iNdEx = preIndex 1897 | skippy, err := skipAbc(dAtA[iNdEx:]) 1898 | if err != nil { 1899 | return err 1900 | } 1901 | if (skippy < 0) || (iNdEx+skippy) < 0 { 1902 | return ErrInvalidLengthAbc 1903 | } 1904 | if (iNdEx + skippy) > l { 1905 | return io.ErrUnexpectedEOF 1906 | } 1907 | iNdEx += skippy 1908 | } 1909 | } 1910 | 1911 | if iNdEx > l { 1912 | return io.ErrUnexpectedEOF 1913 | } 1914 | return nil 1915 | } 1916 | func skipAbc(dAtA []byte) (n int, err error) { 1917 | l := len(dAtA) 1918 | iNdEx := 0 1919 | depth := 0 1920 | for iNdEx < l { 1921 | var wire uint64 1922 | for shift := uint(0); ; shift += 7 { 1923 | if shift >= 64 { 1924 | return 0, ErrIntOverflowAbc 1925 | } 1926 | if iNdEx >= l { 1927 | return 0, io.ErrUnexpectedEOF 1928 | } 1929 | b := dAtA[iNdEx] 1930 | iNdEx++ 1931 | wire |= (uint64(b) & 0x7F) << shift 1932 | if b < 0x80 { 1933 | break 1934 | } 1935 | } 1936 | wireType := int(wire & 0x7) 1937 | switch wireType { 1938 | case 0: 1939 | for shift := uint(0); ; shift += 7 { 1940 | if shift >= 64 { 1941 | return 0, ErrIntOverflowAbc 1942 | } 1943 | if iNdEx >= l { 1944 | return 0, io.ErrUnexpectedEOF 1945 | } 1946 | iNdEx++ 1947 | if dAtA[iNdEx-1] < 0x80 { 1948 | break 1949 | } 1950 | } 1951 | case 1: 1952 | iNdEx += 8 1953 | case 2: 1954 | var length int 1955 | for shift := uint(0); ; shift += 7 { 1956 | if shift >= 64 { 1957 | return 0, ErrIntOverflowAbc 1958 | } 1959 | if iNdEx >= l { 1960 | return 0, io.ErrUnexpectedEOF 1961 | } 1962 | b := dAtA[iNdEx] 1963 | iNdEx++ 1964 | length |= (int(b) & 0x7F) << shift 1965 | if b < 0x80 { 1966 | break 1967 | } 1968 | } 1969 | if length < 0 { 1970 | return 0, ErrInvalidLengthAbc 1971 | } 1972 | iNdEx += length 1973 | case 3: 1974 | depth++ 1975 | case 4: 1976 | if depth == 0 { 1977 | return 0, ErrUnexpectedEndOfGroupAbc 1978 | } 1979 | depth-- 1980 | case 5: 1981 | iNdEx += 4 1982 | default: 1983 | return 0, fmt.Errorf("proto: illegal wireType %d", wireType) 1984 | } 1985 | if iNdEx < 0 { 1986 | return 0, ErrInvalidLengthAbc 1987 | } 1988 | if depth == 0 { 1989 | return iNdEx, nil 1990 | } 1991 | } 1992 | return 0, io.ErrUnexpectedEOF 1993 | } 1994 | 1995 | var ( 1996 | ErrInvalidLengthAbc = fmt.Errorf("proto: negative length found during unmarshaling") 1997 | ErrIntOverflowAbc = fmt.Errorf("proto: integer overflow") 1998 | ErrUnexpectedEndOfGroupAbc = fmt.Errorf("proto: unexpected end of group") 1999 | ) 2000 | -------------------------------------------------------------------------------- /test/abc.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | package test.abc; 3 | 4 | import "cosmos.proto"; 5 | import "google/protobuf/any.proto"; 6 | 7 | option go_package = "test"; 8 | 9 | message ABC { 10 | option (cosmos_proto.interface_type) = "github.com/regen-network/cosmos-proto/test/iface.Msg"; 11 | oneof sum { 12 | A a = 1; 13 | B b = 2; 14 | C c = 3; 15 | } 16 | } 17 | 18 | message ABCNonPointer { 19 | option (cosmos_proto.interface_type) = "*github.com/regen-network/cosmos-proto/test/iface.Msg"; 20 | oneof sum { 21 | A a = 1; 22 | B b = 2; 23 | C c = 3; 24 | } 25 | } 26 | 27 | message A { 28 | int32 x = 1; 29 | } 30 | 31 | message B { 32 | uint32 y = 1; 33 | } 34 | 35 | message C { 36 | bool z = 1; 37 | } 38 | 39 | message SomeContainer { 40 | google.protobuf.Any some_interface = 1 [(cosmos_proto.accepts_interface) = "SomeInterface"]; 41 | } 42 | 43 | message SomeImpl1 { 44 | option (cosmos_proto.implements_interface) = "SomeInterface"; 45 | int64 x = 1; 46 | } 47 | 48 | message SomeImpl2 { 49 | option (cosmos_proto.implements_interface) = "SomeInterface"; 50 | string y = 2; 51 | } 52 | -------------------------------------------------------------------------------- /test/iface/iface.go: -------------------------------------------------------------------------------- 1 | package iface 2 | 3 | type Msg interface { 4 | SomeMethod() string 5 | } 6 | -------------------------------------------------------------------------------- /test/iface_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "testing" 6 | ) 7 | 8 | type D struct{} 9 | 10 | func (m D) SomeMethod() string { return "D" } 11 | 12 | func TestToAndFrom(t *testing.T) { 13 | abc := ABC{} 14 | 15 | assert.NoError(t, abc.SetMsg(&A{X: 1})) 16 | iface1 := abc.GetMsg() 17 | assert.NotNil(t, iface1) 18 | assert.Equal(t, "A.X:1", iface1.SomeMethod()) 19 | 20 | assert.NoError(t, abc.SetMsg(&B{Y: 2})) 21 | iface1 = abc.GetMsg() 22 | assert.NotNil(t, iface1) 23 | assert.Equal(t, "B.Y:2", iface1.SomeMethod()) 24 | 25 | assert.NoError(t, abc.SetMsg(&C{Z: true})) 26 | iface1 = abc.GetMsg() 27 | assert.NotNil(t, iface1) 28 | assert.Equal(t, "C.Z:true", iface1.SomeMethod()) 29 | 30 | // Non-pointer cases 31 | assert.NoError(t, abc.SetMsg(A{X: 1})) 32 | iface1 = abc.GetMsg() 33 | assert.NotNil(t, iface1) 34 | assert.Equal(t, "A.X:1", iface1.SomeMethod()) 35 | 36 | assert.NoError(t, abc.SetMsg(B{Y: 2})) 37 | iface1 = abc.GetMsg() 38 | assert.NotNil(t, iface1) 39 | assert.Equal(t, "B.Y:2", iface1.SomeMethod()) 40 | 41 | assert.NoError(t, abc.SetMsg(C{Z: true})) 42 | iface1 = abc.GetMsg() 43 | assert.NotNil(t, iface1) 44 | assert.Equal(t, "C.Z:true", iface1.SomeMethod()) 45 | 46 | // test nil 47 | assert.NoError(t, abc.SetMsg(nil)) 48 | iface1 = abc.GetMsg() 49 | assert.Nil(t, iface1) 50 | 51 | // D implements Msg but isn't in the ABC oneof and so this should fail 52 | assert.Error(t, abc.SetMsg(&D{})) 53 | } 54 | 55 | func TestToAndFromNonPointer(t *testing.T) { 56 | abc := ABCNonPointer{} 57 | 58 | assert.NoError(t, abc.SetMsg(&A{X: 1})) 59 | iface1 := abc.GetMsg() 60 | assert.NotNil(t, iface1) 61 | assert.Equal(t, "A.X:1", iface1.SomeMethod()) 62 | 63 | assert.NoError(t, abc.SetMsg(&B{Y: 2})) 64 | iface1 = abc.GetMsg() 65 | assert.NotNil(t, iface1) 66 | assert.Equal(t, "B.Y:2", iface1.SomeMethod()) 67 | 68 | assert.NoError(t, abc.SetMsg(&C{Z: true})) 69 | iface1 = abc.GetMsg() 70 | assert.NotNil(t, iface1) 71 | assert.Equal(t, "C.Z:true", iface1.SomeMethod()) 72 | 73 | // Non-pointer cases should error here 74 | assert.Error(t, abc.SetMsg(A{X: 1})) 75 | assert.Error(t, abc.SetMsg(B{Y: 2})) 76 | assert.Error(t, abc.SetMsg(C{Z: true})) 77 | 78 | // test nil 79 | assert.NoError(t, abc.SetMsg(nil)) 80 | iface1 = abc.GetMsg() 81 | assert.Nil(t, iface1) 82 | 83 | // D implements Msg but isn't in the ABC oneof and so this should fail 84 | assert.Error(t, abc.SetMsg(&D{})) 85 | } 86 | -------------------------------------------------------------------------------- /test/impl.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import "fmt" 4 | 5 | func (m A) SomeMethod() string { 6 | return fmt.Sprintf("A.X:%d", m.X) 7 | } 8 | 9 | func (m B) SomeMethod() string { 10 | return fmt.Sprintf("B.Y:%d", m.Y) 11 | } 12 | 13 | func (m C) SomeMethod() string { 14 | return fmt.Sprintf("C.Z:%t", m.Z) 15 | } 16 | --------------------------------------------------------------------------------