├── .gitignore ├── LICENSE ├── README.md ├── pom.xml ├── protos ├── customer.proto └── gen.sh └── src ├── main ├── java │ └── demo │ │ ├── CustomerProtos.java │ │ └── DemoApplication.java ├── python │ ├── client.py │ ├── customer_pb2.py │ └── customer_pb2.pyc ├── resources │ └── application.properties └── ruby │ ├── client.rb │ └── customer.pb.rb └── test └── java └── demo └── DemoApplicationTests.java /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | -------------------------------------------------------------------------------- /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 {yyyy} {name of copyright owner} 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 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Using Google Protocol Buffers for High Speed REST 2 | 3 | 4 | 5 | Spring Framework 4.1 introduced new support for [Google Protocol Buffers](https://developers.google.com/protocol-buffers/). From the website: 6 | 7 | > Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages... 8 | 9 | Google uses Protocol Buffers extensively in their own, internal, service-centric architecture. 10 | 11 | A `.proto` document describes the types (_messages_) to be encoded and contains a definition language that should be familiar to anyone who's used C `struct`s. In the document, you define types, fields in those types, and their ordering (memory offsets!) in the type relative to each other. 12 | 13 | The `.proto` files aren't implementations - they're declarative descriptions of messages that may be conveyed over the wire. They can prescribe and validate constraints - the type of a given field, or the cardinatlity of that field - on the messages that are encoded and decoded. You must use the Protobuf compiler to generate the appropriate client for your language of choice. 14 | 15 | You can use Google Protocol Buffers anyway you like, but in this post we'll look at using it as a way to encode REST service payloads. This approach is powerful: you can use content-negotiation to serve high speed Protocol Buffer payloads to the clients (in any number of languages) that accept it, and something more conventional like JSON for those that don't. 16 | 17 | Protocol Buffer messages offer a number of improvements over typical JSON-encoded messages, particularly in a polyglot system where microservices are implemented in various technologies but need to be able to reason about communication between services in a consistant, long-term manner. 18 | 19 | Protocol Buffers are several nice features that promote stable APIs: 20 | 21 | - Protocol Buffers offer backward compatibility for free. Each field is numbered in a Protocol Buffer, so you don't have to change the behavior of the code going forward to maintain backward compatability with older clients. Clients that don't know about new fields won't bother trying to parse them. 22 | - Protocol Buffers provide a natural place to specify validation using the `required`, `optional`, and `repeated` keywords. Each client enforces these constraints in their own way. 23 | - Protocol Buffers are polyglot, and [work with all manner of technologies](https://developers.google.com/protocol-buffers/docs/reference/other). In the example code for this blog alone there is a Ruby, Python and Java client for the Java service demonstrated. It's just a matter of using one of the _numerous_ supported compilers. 24 | 25 | 26 | You might think that you could just use Java's inbuilt serialization mechanism in a homogeneous service environment but, as the Protocol Buffers team were quick to point out whent hey first introduced the technology, there are some problems even with that. Java language luminary Josh Bloch's epic tome, _Effective Java_, on page 213, provides further details. 27 | 28 | Let's first look at our `.proto` document: 29 | 30 | ```json 31 | package demo; 32 | 33 | option java_package = "demo"; 34 | option java_outer_classname = "CustomerProtos"; 35 | 36 | message Customer { 37 | required int32 id = 1; 38 | required string firstName = 2; 39 | required string lastName = 3; 40 | 41 | enum EmailType { 42 | PRIVATE = 1; 43 | PROFESSIONAL = 2; 44 | } 45 | 46 | message EmailAddress { 47 | required string email = 1; 48 | optional EmailType type = 2 [default = PROFESSIONAL]; 49 | } 50 | 51 | repeated EmailAddress email = 5; 52 | } 53 | 54 | message Organization { 55 | required string name = 1; 56 | repeated Customer customer = 2; 57 | } 58 | ``` 59 | 60 | You then pass this definition to the `protoc` compiler and specify the output type, like this: 61 | 62 | ```sh 63 | protoc -I=$IN_DIR --java_out=$OUT_DIR $IN_DIR/customer.proto 64 | ``` 65 | 66 | Here's the little Bash script I put together to code-generate my various clients: 67 | 68 | ```sh 69 | #!/usr/bin/env bash 70 | 71 | 72 | SRC_DIR=`pwd` 73 | DST_DIR=`pwd`/../src/main/ 74 | 75 | echo source: $SRC_DIR 76 | echo destination root: $DST_DIR 77 | 78 | function ensure_implementations(){ 79 | 80 | # Ruby and Go aren't natively supported it seems 81 | # Java and Python are 82 | 83 | gem list | grep ruby-protocol-buffers || sudo gem install ruby-protocol-buffers 84 | go get -u github.com/golang/protobuf/{proto,protoc-gen-go} 85 | } 86 | 87 | function gen(){ 88 | D=$1 89 | echo $D 90 | OUT=$DST_DIR/$D 91 | mkdir -p $OUT 92 | protoc -I=$SRC_DIR --${D}_out=$OUT $SRC_DIR/customer.proto 93 | } 94 | 95 | ensure_implementations 96 | 97 | gen java 98 | gen python 99 | gen ruby 100 | ``` 101 | 102 | This will generate the appropriate client classes in the `src/main/{java,ruby,python}` folders. Let's first look at the Spring MVC REST service itself. 103 | 104 | ## A Spring MVC REST Service 105 | 106 | In our example, we'll register an instance of Spring framework 4.1's [`org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter`](http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.html). This type is an `HttpMessageConverter`. `HttpMessageConverter`s encode and decode the requests and responses in REST service calls. They're usually activated after some sort of content negotiation has occurred: if the client specifies `Accept: application/x-protobuf`, for example, then our REST service will send back the Protocol Buffer-encoded response. 107 | 108 | 109 | ```java 110 | package demo; 111 | 112 | import org.springframework.beans.factory.annotation.Autowired; 113 | import org.springframework.boot.SpringApplication; 114 | import org.springframework.boot.autoconfigure.SpringBootApplication; 115 | import org.springframework.context.annotation.Bean; 116 | import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter; 117 | import org.springframework.web.bind.annotation.PathVariable; 118 | import org.springframework.web.bind.annotation.RequestMapping; 119 | import org.springframework.web.bind.annotation.RestController; 120 | 121 | import java.util.Arrays; 122 | import java.util.Collection; 123 | import java.util.Map; 124 | import java.util.concurrent.ConcurrentHashMap; 125 | import java.util.stream.Collectors; 126 | 127 | @SpringBootApplication 128 | public class DemoApplication { 129 | 130 | public static void main(String[] args) { 131 | SpringApplication.run(DemoApplication.class, args); 132 | } 133 | 134 | @Bean 135 | ProtobufHttpMessageConverter protobufHttpMessageConverter() { 136 | return new ProtobufHttpMessageConverter(); 137 | } 138 | 139 | private CustomerProtos.Customer customer(int id, String f, String l, Collection emails) { 140 | Collection emailAddresses = 141 | emails.stream().map(e -> CustomerProtos.Customer.EmailAddress.newBuilder() 142 | .setType(CustomerProtos.Customer.EmailType.PROFESSIONAL) 143 | .setEmail(e).build()) 144 | .collect(Collectors.toList()); 145 | 146 | return CustomerProtos.Customer.newBuilder() 147 | .setFirstName(f) 148 | .setLastName(l) 149 | .setId(id) 150 | .addAllEmail(emailAddresses) 151 | .build(); 152 | } 153 | 154 | @Bean 155 | CustomerRepository customerRepository() { 156 | Map customers = new ConcurrentHashMap<>(); 157 | // populate with some dummy data 158 | Arrays.asList( 159 | customer(1, "Chris", "Richardson", Arrays.asList("crichardson@email.com")), 160 | customer(2, "Josh", "Long", Arrays.asList("jlong@email.com")), 161 | customer(3, "Matt", "Stine", Arrays.asList("mstine@email.com")), 162 | customer(4, "Russ", "Miles", Arrays.asList("rmiles@email.com")) 163 | ).forEach(c -> customers.put(c.getId(), c)); 164 | 165 | // our lambda just gets forwarded to Map#get(Integer) 166 | return customers::get; 167 | } 168 | 169 | } 170 | 171 | interface CustomerRepository { 172 | CustomerProtos.Customer findById(int id); 173 | } 174 | 175 | 176 | @RestController 177 | class CustomerRestController { 178 | 179 | @Autowired 180 | private CustomerRepository customerRepository; 181 | 182 | @RequestMapping("/customers/{id}") 183 | CustomerProtos.Customer customer(@PathVariable Integer id) { 184 | return this.customerRepository.findById(id); 185 | } 186 | } 187 | ``` 188 | 189 | Most of this code is pretty straightforward. It's a Spring Boot application. Spring Boot automatically registers `HttpMessageConverter` beans so we need only define the `ProtobufHttpMessageConverter` bean and it gets configured appropriately. The `@Configuration` class seeds some dummy date and a mock `CustomerRepository` object. I won't reproduce the Java type for our Protocol Buffer, `demo/CustomerProtos.java`, here as it is code-generated bit twiddling and parsing code; not all that interesting to read. One convenience is that the Java implementation automatically provides _builder_ methods for quickly creating instances of these types in Java. 190 | 191 | The code-generated types are dumb `struct` like objects. They're suitable for use as DTOs, but should not be used as the basis for your API. Do _not_ extend them using Java inheritance to introduce new functionality; it'll break the implementation and it's bad OOP practice, anyway. If you want to keep things cleaner, simply wrapt and adapt them as appropriate, perhaps handling conversion from an ORM entity to the Protocol Buffer client type as appropriate in that wrapper. 192 | 193 | `HttpMessageConverter`s may also be used with Spring's REST client, the `RestTemplate`. Here's the appropriate Java-language unit test: 194 | 195 | ```java 196 | package demo; 197 | 198 | import org.junit.Test; 199 | import org.junit.runner.RunWith; 200 | import org.springframework.beans.factory.annotation.Autowired; 201 | import org.springframework.boot.test.IntegrationTest; 202 | import org.springframework.boot.test.SpringApplicationConfiguration; 203 | import org.springframework.context.annotation.Bean; 204 | import org.springframework.context.annotation.Configuration; 205 | import org.springframework.http.ResponseEntity; 206 | import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter; 207 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 208 | import org.springframework.test.context.web.WebAppConfiguration; 209 | import org.springframework.web.client.RestTemplate; 210 | 211 | import java.util.Arrays; 212 | 213 | @RunWith(SpringJUnit4ClassRunner.class) 214 | @SpringApplicationConfiguration(classes = DemoApplication.class) 215 | @WebAppConfiguration 216 | @IntegrationTest 217 | public class DemoApplicationTests { 218 | 219 | @Configuration 220 | public static class RestClientConfiguration { 221 | 222 | @Bean 223 | RestTemplate restTemplate(ProtobufHttpMessageConverter hmc) { 224 | return new RestTemplate(Arrays.asList(hmc)); 225 | } 226 | 227 | @Bean 228 | ProtobufHttpMessageConverter protobufHttpMessageConverter() { 229 | return new ProtobufHttpMessageConverter(); 230 | } 231 | } 232 | 233 | @Autowired 234 | private RestTemplate restTemplate; 235 | 236 | private int port = 8080; 237 | 238 | @Test 239 | public void contextLoaded() { 240 | 241 | ResponseEntity customer = restTemplate.getForEntity( 242 | "http://127.0.0.1:" + port + "/customers/2", CustomerProtos.Customer.class); 243 | 244 | System.out.println("customer retrieved: " + customer.toString()); 245 | 246 | } 247 | 248 | } 249 | ``` 250 | 251 | Things just work as you'd expect, not only in Java and Spring, but also in Ruby and Python. For completeness, here is a simple client using Ruby (client types omitted): 252 | 253 | ```ruby 254 | #!/usr/bin/env ruby 255 | 256 | require './customer.pb' 257 | require 'net/http' 258 | require 'uri' 259 | 260 | uri = URI.parse('http://localhost:8080/customers/3') 261 | body = Net::HTTP.get(uri) 262 | puts Demo::Customer.parse(body) 263 | ``` 264 | 265 | ..and here's a client in Python (client types omitted): 266 | 267 | ```python 268 | 269 | #!/usr/bin/env python 270 | 271 | import urllib 272 | import customer_pb2 273 | 274 | if __name__ == '__main__': 275 | customer = customer_pb2.Customer() 276 | customers_read = urllib.urlopen('http://localhost:8080/customers/1').read() 277 | customer.ParseFromString(customers_read) 278 | print customer 279 | 280 | ``` 281 | 282 | ## Where to go from Here 283 | If you want _very_ high speed message encoding that works with multiple languages, Protocol Buffers are a compelling option. There are other encoding technologies like [Avro](https://avro.apache.org/) or [Thrift](https://thrift.apache.org/), but none nearly so mature and entrenched as Protocol Buffers. You don't necessarily need to use Protocol Buffers with REST, either. You could plug it into some sort of RPC service, if that's your style. There are almost as many client implementations as there are buildpacks for Cloud Foundry - so you could run almost anything on Cloud Foundry and enjoy the same high speed, consistent messaging across all your services! 284 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.test 7 | demo 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 1.2.2.RELEASE 15 | 16 | 17 | 18 | UTF-8 19 | demo.DemoApplication 20 | 1.8 21 | 22 | 23 | 24 | 25 | 26 | 27 | com.google.protobuf 28 | protobuf-java 29 | 2.5.0 30 | 31 | 32 | com.googlecode.protobuf-java-format 33 | protobuf-java-format 34 | 1.2 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-web 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /protos/customer.proto: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | option java_package = "demo"; 4 | option java_outer_classname = "CustomerProtos"; 5 | 6 | message Customer { 7 | required int32 id = 1; 8 | required string firstName = 2; 9 | required string lastName = 3; 10 | 11 | enum EmailType { 12 | PRIVATE = 1; 13 | PROFESSIONAL = 2; 14 | } 15 | 16 | message EmailAddress { 17 | required string email = 1; 18 | optional EmailType type = 2 [default = PROFESSIONAL]; 19 | } 20 | 21 | repeated EmailAddress email = 5; 22 | } 23 | 24 | message Organization { 25 | required string name = 1; 26 | repeated Customer customer = 2; 27 | } -------------------------------------------------------------------------------- /protos/gen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | SRC_DIR=`pwd` 5 | DST_DIR=`pwd`/../src/main/ 6 | 7 | echo source: $SRC_DIR 8 | echo destination root: $DST_DIR 9 | 10 | function ensure_implementations(){ 11 | 12 | # Ruby and Go aren't natively supported it seems 13 | # Java and Python are 14 | 15 | # there are myriad other implementations: 16 | # https://github.com/google/protobuf/wiki/Third-Party-Add-ons#ThirdParty_Addons_for_Protocol_Buffers 17 | gem list | grep ruby-protocol-buffers || sudo gem install ruby-protocol-buffers 18 | go get -u github.com/golang/protobuf/{proto,protoc-gen-go} 19 | } 20 | 21 | function gen(){ 22 | D=$1 23 | echo $D 24 | OUT=$DST_DIR/$D 25 | mkdir -p $OUT 26 | protoc -I=$SRC_DIR --${D}_out=$OUT $SRC_DIR/customer.proto 27 | } 28 | 29 | ensure_implementations 30 | 31 | gen java 32 | gen python 33 | gen ruby -------------------------------------------------------------------------------- /src/main/java/demo/CustomerProtos.java: -------------------------------------------------------------------------------- 1 | // Generated by the protocol buffer compiler. DO NOT EDIT! 2 | // source: customer.proto 3 | 4 | package demo; 5 | 6 | public final class CustomerProtos { 7 | private CustomerProtos() {} 8 | public static void registerAllExtensions( 9 | com.google.protobuf.ExtensionRegistry registry) { 10 | } 11 | public interface CustomerOrBuilder 12 | extends com.google.protobuf.MessageOrBuilder { 13 | 14 | // required int32 id = 1; 15 | /** 16 | * required int32 id = 1; 17 | */ 18 | boolean hasId(); 19 | /** 20 | * required int32 id = 1; 21 | */ 22 | int getId(); 23 | 24 | // required string firstName = 2; 25 | /** 26 | * required string firstName = 2; 27 | */ 28 | boolean hasFirstName(); 29 | /** 30 | * required string firstName = 2; 31 | */ 32 | java.lang.String getFirstName(); 33 | /** 34 | * required string firstName = 2; 35 | */ 36 | com.google.protobuf.ByteString 37 | getFirstNameBytes(); 38 | 39 | // required string lastName = 3; 40 | /** 41 | * required string lastName = 3; 42 | */ 43 | boolean hasLastName(); 44 | /** 45 | * required string lastName = 3; 46 | */ 47 | java.lang.String getLastName(); 48 | /** 49 | * required string lastName = 3; 50 | */ 51 | com.google.protobuf.ByteString 52 | getLastNameBytes(); 53 | 54 | // repeated .demo.Customer.EmailAddress email = 5; 55 | /** 56 | * repeated .demo.Customer.EmailAddress email = 5; 57 | */ 58 | java.util.List 59 | getEmailList(); 60 | /** 61 | * repeated .demo.Customer.EmailAddress email = 5; 62 | */ 63 | demo.CustomerProtos.Customer.EmailAddress getEmail(int index); 64 | /** 65 | * repeated .demo.Customer.EmailAddress email = 5; 66 | */ 67 | int getEmailCount(); 68 | /** 69 | * repeated .demo.Customer.EmailAddress email = 5; 70 | */ 71 | java.util.List 72 | getEmailOrBuilderList(); 73 | /** 74 | * repeated .demo.Customer.EmailAddress email = 5; 75 | */ 76 | demo.CustomerProtos.Customer.EmailAddressOrBuilder getEmailOrBuilder( 77 | int index); 78 | } 79 | /** 80 | * Protobuf type {@code demo.Customer} 81 | */ 82 | public static final class Customer extends 83 | com.google.protobuf.GeneratedMessage 84 | implements CustomerOrBuilder { 85 | // Use Customer.newBuilder() to construct. 86 | private Customer(com.google.protobuf.GeneratedMessage.Builder builder) { 87 | super(builder); 88 | this.unknownFields = builder.getUnknownFields(); 89 | } 90 | private Customer(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } 91 | 92 | private static final Customer defaultInstance; 93 | public static Customer getDefaultInstance() { 94 | return defaultInstance; 95 | } 96 | 97 | public Customer getDefaultInstanceForType() { 98 | return defaultInstance; 99 | } 100 | 101 | private final com.google.protobuf.UnknownFieldSet unknownFields; 102 | @java.lang.Override 103 | public final com.google.protobuf.UnknownFieldSet 104 | getUnknownFields() { 105 | return this.unknownFields; 106 | } 107 | private Customer( 108 | com.google.protobuf.CodedInputStream input, 109 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 110 | throws com.google.protobuf.InvalidProtocolBufferException { 111 | initFields(); 112 | int mutable_bitField0_ = 0; 113 | com.google.protobuf.UnknownFieldSet.Builder unknownFields = 114 | com.google.protobuf.UnknownFieldSet.newBuilder(); 115 | try { 116 | boolean done = false; 117 | while (!done) { 118 | int tag = input.readTag(); 119 | switch (tag) { 120 | case 0: 121 | done = true; 122 | break; 123 | default: { 124 | if (!parseUnknownField(input, unknownFields, 125 | extensionRegistry, tag)) { 126 | done = true; 127 | } 128 | break; 129 | } 130 | case 8: { 131 | bitField0_ |= 0x00000001; 132 | id_ = input.readInt32(); 133 | break; 134 | } 135 | case 18: { 136 | bitField0_ |= 0x00000002; 137 | firstName_ = input.readBytes(); 138 | break; 139 | } 140 | case 26: { 141 | bitField0_ |= 0x00000004; 142 | lastName_ = input.readBytes(); 143 | break; 144 | } 145 | case 42: { 146 | if (!((mutable_bitField0_ & 0x00000008) == 0x00000008)) { 147 | email_ = new java.util.ArrayList(); 148 | mutable_bitField0_ |= 0x00000008; 149 | } 150 | email_.add(input.readMessage(demo.CustomerProtos.Customer.EmailAddress.PARSER, extensionRegistry)); 151 | break; 152 | } 153 | } 154 | } 155 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 156 | throw e.setUnfinishedMessage(this); 157 | } catch (java.io.IOException e) { 158 | throw new com.google.protobuf.InvalidProtocolBufferException( 159 | e.getMessage()).setUnfinishedMessage(this); 160 | } finally { 161 | if (((mutable_bitField0_ & 0x00000008) == 0x00000008)) { 162 | email_ = java.util.Collections.unmodifiableList(email_); 163 | } 164 | this.unknownFields = unknownFields.build(); 165 | makeExtensionsImmutable(); 166 | } 167 | } 168 | public static final com.google.protobuf.Descriptors.Descriptor 169 | getDescriptor() { 170 | return demo.CustomerProtos.internal_static_demo_Customer_descriptor; 171 | } 172 | 173 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 174 | internalGetFieldAccessorTable() { 175 | return demo.CustomerProtos.internal_static_demo_Customer_fieldAccessorTable 176 | .ensureFieldAccessorsInitialized( 177 | demo.CustomerProtos.Customer.class, demo.CustomerProtos.Customer.Builder.class); 178 | } 179 | 180 | public static com.google.protobuf.Parser PARSER = 181 | new com.google.protobuf.AbstractParser() { 182 | public Customer parsePartialFrom( 183 | com.google.protobuf.CodedInputStream input, 184 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 185 | throws com.google.protobuf.InvalidProtocolBufferException { 186 | return new Customer(input, extensionRegistry); 187 | } 188 | }; 189 | 190 | @java.lang.Override 191 | public com.google.protobuf.Parser getParserForType() { 192 | return PARSER; 193 | } 194 | 195 | /** 196 | * Protobuf enum {@code demo.Customer.EmailType} 197 | */ 198 | public enum EmailType 199 | implements com.google.protobuf.ProtocolMessageEnum { 200 | /** 201 | * PRIVATE = 0; 202 | */ 203 | PRIVATE(0, 0), 204 | /** 205 | * PROFESSIONAL = 1; 206 | */ 207 | PROFESSIONAL(1, 1), 208 | ; 209 | 210 | /** 211 | * PRIVATE = 0; 212 | */ 213 | public static final int PRIVATE_VALUE = 0; 214 | /** 215 | * PROFESSIONAL = 1; 216 | */ 217 | public static final int PROFESSIONAL_VALUE = 1; 218 | 219 | 220 | public final int getNumber() { return value; } 221 | 222 | public static EmailType valueOf(int value) { 223 | switch (value) { 224 | case 0: return PRIVATE; 225 | case 1: return PROFESSIONAL; 226 | default: return null; 227 | } 228 | } 229 | 230 | public static com.google.protobuf.Internal.EnumLiteMap 231 | internalGetValueMap() { 232 | return internalValueMap; 233 | } 234 | private static com.google.protobuf.Internal.EnumLiteMap 235 | internalValueMap = 236 | new com.google.protobuf.Internal.EnumLiteMap() { 237 | public EmailType findValueByNumber(int number) { 238 | return EmailType.valueOf(number); 239 | } 240 | }; 241 | 242 | public final com.google.protobuf.Descriptors.EnumValueDescriptor 243 | getValueDescriptor() { 244 | return getDescriptor().getValues().get(index); 245 | } 246 | public final com.google.protobuf.Descriptors.EnumDescriptor 247 | getDescriptorForType() { 248 | return getDescriptor(); 249 | } 250 | public static final com.google.protobuf.Descriptors.EnumDescriptor 251 | getDescriptor() { 252 | return demo.CustomerProtos.Customer.getDescriptor().getEnumTypes().get(0); 253 | } 254 | 255 | private static final EmailType[] VALUES = values(); 256 | 257 | public static EmailType valueOf( 258 | com.google.protobuf.Descriptors.EnumValueDescriptor desc) { 259 | if (desc.getType() != getDescriptor()) { 260 | throw new java.lang.IllegalArgumentException( 261 | "EnumValueDescriptor is not for this type."); 262 | } 263 | return VALUES[desc.getIndex()]; 264 | } 265 | 266 | private final int index; 267 | private final int value; 268 | 269 | private EmailType(int index, int value) { 270 | this.index = index; 271 | this.value = value; 272 | } 273 | 274 | // @@protoc_insertion_point(enum_scope:demo.Customer.EmailType) 275 | } 276 | 277 | public interface EmailAddressOrBuilder 278 | extends com.google.protobuf.MessageOrBuilder { 279 | 280 | // required string email = 1; 281 | /** 282 | * required string email = 1; 283 | */ 284 | boolean hasEmail(); 285 | /** 286 | * required string email = 1; 287 | */ 288 | java.lang.String getEmail(); 289 | /** 290 | * required string email = 1; 291 | */ 292 | com.google.protobuf.ByteString 293 | getEmailBytes(); 294 | 295 | // optional .demo.Customer.EmailType type = 2 [default = PROFESSIONAL]; 296 | /** 297 | * optional .demo.Customer.EmailType type = 2 [default = PROFESSIONAL]; 298 | */ 299 | boolean hasType(); 300 | /** 301 | * optional .demo.Customer.EmailType type = 2 [default = PROFESSIONAL]; 302 | */ 303 | demo.CustomerProtos.Customer.EmailType getType(); 304 | } 305 | /** 306 | * Protobuf type {@code demo.Customer.EmailAddress} 307 | */ 308 | public static final class EmailAddress extends 309 | com.google.protobuf.GeneratedMessage 310 | implements EmailAddressOrBuilder { 311 | // Use EmailAddress.newBuilder() to construct. 312 | private EmailAddress(com.google.protobuf.GeneratedMessage.Builder builder) { 313 | super(builder); 314 | this.unknownFields = builder.getUnknownFields(); 315 | } 316 | private EmailAddress(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } 317 | 318 | private static final EmailAddress defaultInstance; 319 | public static EmailAddress getDefaultInstance() { 320 | return defaultInstance; 321 | } 322 | 323 | public EmailAddress getDefaultInstanceForType() { 324 | return defaultInstance; 325 | } 326 | 327 | private final com.google.protobuf.UnknownFieldSet unknownFields; 328 | @java.lang.Override 329 | public final com.google.protobuf.UnknownFieldSet 330 | getUnknownFields() { 331 | return this.unknownFields; 332 | } 333 | private EmailAddress( 334 | com.google.protobuf.CodedInputStream input, 335 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 336 | throws com.google.protobuf.InvalidProtocolBufferException { 337 | initFields(); 338 | int mutable_bitField0_ = 0; 339 | com.google.protobuf.UnknownFieldSet.Builder unknownFields = 340 | com.google.protobuf.UnknownFieldSet.newBuilder(); 341 | try { 342 | boolean done = false; 343 | while (!done) { 344 | int tag = input.readTag(); 345 | switch (tag) { 346 | case 0: 347 | done = true; 348 | break; 349 | default: { 350 | if (!parseUnknownField(input, unknownFields, 351 | extensionRegistry, tag)) { 352 | done = true; 353 | } 354 | break; 355 | } 356 | case 10: { 357 | bitField0_ |= 0x00000001; 358 | email_ = input.readBytes(); 359 | break; 360 | } 361 | case 16: { 362 | int rawValue = input.readEnum(); 363 | demo.CustomerProtos.Customer.EmailType value = demo.CustomerProtos.Customer.EmailType.valueOf(rawValue); 364 | if (value == null) { 365 | unknownFields.mergeVarintField(2, rawValue); 366 | } else { 367 | bitField0_ |= 0x00000002; 368 | type_ = value; 369 | } 370 | break; 371 | } 372 | } 373 | } 374 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 375 | throw e.setUnfinishedMessage(this); 376 | } catch (java.io.IOException e) { 377 | throw new com.google.protobuf.InvalidProtocolBufferException( 378 | e.getMessage()).setUnfinishedMessage(this); 379 | } finally { 380 | this.unknownFields = unknownFields.build(); 381 | makeExtensionsImmutable(); 382 | } 383 | } 384 | public static final com.google.protobuf.Descriptors.Descriptor 385 | getDescriptor() { 386 | return demo.CustomerProtos.internal_static_demo_Customer_EmailAddress_descriptor; 387 | } 388 | 389 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 390 | internalGetFieldAccessorTable() { 391 | return demo.CustomerProtos.internal_static_demo_Customer_EmailAddress_fieldAccessorTable 392 | .ensureFieldAccessorsInitialized( 393 | demo.CustomerProtos.Customer.EmailAddress.class, demo.CustomerProtos.Customer.EmailAddress.Builder.class); 394 | } 395 | 396 | public static com.google.protobuf.Parser PARSER = 397 | new com.google.protobuf.AbstractParser() { 398 | public EmailAddress parsePartialFrom( 399 | com.google.protobuf.CodedInputStream input, 400 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 401 | throws com.google.protobuf.InvalidProtocolBufferException { 402 | return new EmailAddress(input, extensionRegistry); 403 | } 404 | }; 405 | 406 | @java.lang.Override 407 | public com.google.protobuf.Parser getParserForType() { 408 | return PARSER; 409 | } 410 | 411 | private int bitField0_; 412 | // required string email = 1; 413 | public static final int EMAIL_FIELD_NUMBER = 1; 414 | private java.lang.Object email_; 415 | /** 416 | * required string email = 1; 417 | */ 418 | public boolean hasEmail() { 419 | return ((bitField0_ & 0x00000001) == 0x00000001); 420 | } 421 | /** 422 | * required string email = 1; 423 | */ 424 | public java.lang.String getEmail() { 425 | java.lang.Object ref = email_; 426 | if (ref instanceof java.lang.String) { 427 | return (java.lang.String) ref; 428 | } else { 429 | com.google.protobuf.ByteString bs = 430 | (com.google.protobuf.ByteString) ref; 431 | java.lang.String s = bs.toStringUtf8(); 432 | if (bs.isValidUtf8()) { 433 | email_ = s; 434 | } 435 | return s; 436 | } 437 | } 438 | /** 439 | * required string email = 1; 440 | */ 441 | public com.google.protobuf.ByteString 442 | getEmailBytes() { 443 | java.lang.Object ref = email_; 444 | if (ref instanceof java.lang.String) { 445 | com.google.protobuf.ByteString b = 446 | com.google.protobuf.ByteString.copyFromUtf8( 447 | (java.lang.String) ref); 448 | email_ = b; 449 | return b; 450 | } else { 451 | return (com.google.protobuf.ByteString) ref; 452 | } 453 | } 454 | 455 | // optional .demo.Customer.EmailType type = 2 [default = PROFESSIONAL]; 456 | public static final int TYPE_FIELD_NUMBER = 2; 457 | private demo.CustomerProtos.Customer.EmailType type_; 458 | /** 459 | * optional .demo.Customer.EmailType type = 2 [default = PROFESSIONAL]; 460 | */ 461 | public boolean hasType() { 462 | return ((bitField0_ & 0x00000002) == 0x00000002); 463 | } 464 | /** 465 | * optional .demo.Customer.EmailType type = 2 [default = PROFESSIONAL]; 466 | */ 467 | public demo.CustomerProtos.Customer.EmailType getType() { 468 | return type_; 469 | } 470 | 471 | private void initFields() { 472 | email_ = ""; 473 | type_ = demo.CustomerProtos.Customer.EmailType.PROFESSIONAL; 474 | } 475 | private byte memoizedIsInitialized = -1; 476 | public final boolean isInitialized() { 477 | byte isInitialized = memoizedIsInitialized; 478 | if (isInitialized != -1) return isInitialized == 1; 479 | 480 | if (!hasEmail()) { 481 | memoizedIsInitialized = 0; 482 | return false; 483 | } 484 | memoizedIsInitialized = 1; 485 | return true; 486 | } 487 | 488 | public void writeTo(com.google.protobuf.CodedOutputStream output) 489 | throws java.io.IOException { 490 | getSerializedSize(); 491 | if (((bitField0_ & 0x00000001) == 0x00000001)) { 492 | output.writeBytes(1, getEmailBytes()); 493 | } 494 | if (((bitField0_ & 0x00000002) == 0x00000002)) { 495 | output.writeEnum(2, type_.getNumber()); 496 | } 497 | getUnknownFields().writeTo(output); 498 | } 499 | 500 | private int memoizedSerializedSize = -1; 501 | public int getSerializedSize() { 502 | int size = memoizedSerializedSize; 503 | if (size != -1) return size; 504 | 505 | size = 0; 506 | if (((bitField0_ & 0x00000001) == 0x00000001)) { 507 | size += com.google.protobuf.CodedOutputStream 508 | .computeBytesSize(1, getEmailBytes()); 509 | } 510 | if (((bitField0_ & 0x00000002) == 0x00000002)) { 511 | size += com.google.protobuf.CodedOutputStream 512 | .computeEnumSize(2, type_.getNumber()); 513 | } 514 | size += getUnknownFields().getSerializedSize(); 515 | memoizedSerializedSize = size; 516 | return size; 517 | } 518 | 519 | private static final long serialVersionUID = 0L; 520 | @java.lang.Override 521 | protected java.lang.Object writeReplace() 522 | throws java.io.ObjectStreamException { 523 | return super.writeReplace(); 524 | } 525 | 526 | public static demo.CustomerProtos.Customer.EmailAddress parseFrom( 527 | com.google.protobuf.ByteString data) 528 | throws com.google.protobuf.InvalidProtocolBufferException { 529 | return PARSER.parseFrom(data); 530 | } 531 | public static demo.CustomerProtos.Customer.EmailAddress parseFrom( 532 | com.google.protobuf.ByteString data, 533 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 534 | throws com.google.protobuf.InvalidProtocolBufferException { 535 | return PARSER.parseFrom(data, extensionRegistry); 536 | } 537 | public static demo.CustomerProtos.Customer.EmailAddress parseFrom(byte[] data) 538 | throws com.google.protobuf.InvalidProtocolBufferException { 539 | return PARSER.parseFrom(data); 540 | } 541 | public static demo.CustomerProtos.Customer.EmailAddress parseFrom( 542 | byte[] data, 543 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 544 | throws com.google.protobuf.InvalidProtocolBufferException { 545 | return PARSER.parseFrom(data, extensionRegistry); 546 | } 547 | public static demo.CustomerProtos.Customer.EmailAddress parseFrom(java.io.InputStream input) 548 | throws java.io.IOException { 549 | return PARSER.parseFrom(input); 550 | } 551 | public static demo.CustomerProtos.Customer.EmailAddress parseFrom( 552 | java.io.InputStream input, 553 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 554 | throws java.io.IOException { 555 | return PARSER.parseFrom(input, extensionRegistry); 556 | } 557 | public static demo.CustomerProtos.Customer.EmailAddress parseDelimitedFrom(java.io.InputStream input) 558 | throws java.io.IOException { 559 | return PARSER.parseDelimitedFrom(input); 560 | } 561 | public static demo.CustomerProtos.Customer.EmailAddress parseDelimitedFrom( 562 | java.io.InputStream input, 563 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 564 | throws java.io.IOException { 565 | return PARSER.parseDelimitedFrom(input, extensionRegistry); 566 | } 567 | public static demo.CustomerProtos.Customer.EmailAddress parseFrom( 568 | com.google.protobuf.CodedInputStream input) 569 | throws java.io.IOException { 570 | return PARSER.parseFrom(input); 571 | } 572 | public static demo.CustomerProtos.Customer.EmailAddress parseFrom( 573 | com.google.protobuf.CodedInputStream input, 574 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 575 | throws java.io.IOException { 576 | return PARSER.parseFrom(input, extensionRegistry); 577 | } 578 | 579 | public static Builder newBuilder() { return Builder.create(); } 580 | public Builder newBuilderForType() { return newBuilder(); } 581 | public static Builder newBuilder(demo.CustomerProtos.Customer.EmailAddress prototype) { 582 | return newBuilder().mergeFrom(prototype); 583 | } 584 | public Builder toBuilder() { return newBuilder(this); } 585 | 586 | @java.lang.Override 587 | protected Builder newBuilderForType( 588 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 589 | Builder builder = new Builder(parent); 590 | return builder; 591 | } 592 | /** 593 | * Protobuf type {@code demo.Customer.EmailAddress} 594 | */ 595 | public static final class Builder extends 596 | com.google.protobuf.GeneratedMessage.Builder 597 | implements demo.CustomerProtos.Customer.EmailAddressOrBuilder { 598 | public static final com.google.protobuf.Descriptors.Descriptor 599 | getDescriptor() { 600 | return demo.CustomerProtos.internal_static_demo_Customer_EmailAddress_descriptor; 601 | } 602 | 603 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 604 | internalGetFieldAccessorTable() { 605 | return demo.CustomerProtos.internal_static_demo_Customer_EmailAddress_fieldAccessorTable 606 | .ensureFieldAccessorsInitialized( 607 | demo.CustomerProtos.Customer.EmailAddress.class, demo.CustomerProtos.Customer.EmailAddress.Builder.class); 608 | } 609 | 610 | // Construct using demo.CustomerProtos.Customer.EmailAddress.newBuilder() 611 | private Builder() { 612 | maybeForceBuilderInitialization(); 613 | } 614 | 615 | private Builder( 616 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 617 | super(parent); 618 | maybeForceBuilderInitialization(); 619 | } 620 | private void maybeForceBuilderInitialization() { 621 | if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { 622 | } 623 | } 624 | private static Builder create() { 625 | return new Builder(); 626 | } 627 | 628 | public Builder clear() { 629 | super.clear(); 630 | email_ = ""; 631 | bitField0_ = (bitField0_ & ~0x00000001); 632 | type_ = demo.CustomerProtos.Customer.EmailType.PROFESSIONAL; 633 | bitField0_ = (bitField0_ & ~0x00000002); 634 | return this; 635 | } 636 | 637 | public Builder clone() { 638 | return create().mergeFrom(buildPartial()); 639 | } 640 | 641 | public com.google.protobuf.Descriptors.Descriptor 642 | getDescriptorForType() { 643 | return demo.CustomerProtos.internal_static_demo_Customer_EmailAddress_descriptor; 644 | } 645 | 646 | public demo.CustomerProtos.Customer.EmailAddress getDefaultInstanceForType() { 647 | return demo.CustomerProtos.Customer.EmailAddress.getDefaultInstance(); 648 | } 649 | 650 | public demo.CustomerProtos.Customer.EmailAddress build() { 651 | demo.CustomerProtos.Customer.EmailAddress result = buildPartial(); 652 | if (!result.isInitialized()) { 653 | throw newUninitializedMessageException(result); 654 | } 655 | return result; 656 | } 657 | 658 | public demo.CustomerProtos.Customer.EmailAddress buildPartial() { 659 | demo.CustomerProtos.Customer.EmailAddress result = new demo.CustomerProtos.Customer.EmailAddress(this); 660 | int from_bitField0_ = bitField0_; 661 | int to_bitField0_ = 0; 662 | if (((from_bitField0_ & 0x00000001) == 0x00000001)) { 663 | to_bitField0_ |= 0x00000001; 664 | } 665 | result.email_ = email_; 666 | if (((from_bitField0_ & 0x00000002) == 0x00000002)) { 667 | to_bitField0_ |= 0x00000002; 668 | } 669 | result.type_ = type_; 670 | result.bitField0_ = to_bitField0_; 671 | onBuilt(); 672 | return result; 673 | } 674 | 675 | public Builder mergeFrom(com.google.protobuf.Message other) { 676 | if (other instanceof demo.CustomerProtos.Customer.EmailAddress) { 677 | return mergeFrom((demo.CustomerProtos.Customer.EmailAddress)other); 678 | } else { 679 | super.mergeFrom(other); 680 | return this; 681 | } 682 | } 683 | 684 | public Builder mergeFrom(demo.CustomerProtos.Customer.EmailAddress other) { 685 | if (other == demo.CustomerProtos.Customer.EmailAddress.getDefaultInstance()) return this; 686 | if (other.hasEmail()) { 687 | bitField0_ |= 0x00000001; 688 | email_ = other.email_; 689 | onChanged(); 690 | } 691 | if (other.hasType()) { 692 | setType(other.getType()); 693 | } 694 | this.mergeUnknownFields(other.getUnknownFields()); 695 | return this; 696 | } 697 | 698 | public final boolean isInitialized() { 699 | if (!hasEmail()) { 700 | 701 | return false; 702 | } 703 | return true; 704 | } 705 | 706 | public Builder mergeFrom( 707 | com.google.protobuf.CodedInputStream input, 708 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 709 | throws java.io.IOException { 710 | demo.CustomerProtos.Customer.EmailAddress parsedMessage = null; 711 | try { 712 | parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); 713 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 714 | parsedMessage = (demo.CustomerProtos.Customer.EmailAddress) e.getUnfinishedMessage(); 715 | throw e; 716 | } finally { 717 | if (parsedMessage != null) { 718 | mergeFrom(parsedMessage); 719 | } 720 | } 721 | return this; 722 | } 723 | private int bitField0_; 724 | 725 | // required string email = 1; 726 | private java.lang.Object email_ = ""; 727 | /** 728 | * required string email = 1; 729 | */ 730 | public boolean hasEmail() { 731 | return ((bitField0_ & 0x00000001) == 0x00000001); 732 | } 733 | /** 734 | * required string email = 1; 735 | */ 736 | public java.lang.String getEmail() { 737 | java.lang.Object ref = email_; 738 | if (!(ref instanceof java.lang.String)) { 739 | java.lang.String s = ((com.google.protobuf.ByteString) ref) 740 | .toStringUtf8(); 741 | email_ = s; 742 | return s; 743 | } else { 744 | return (java.lang.String) ref; 745 | } 746 | } 747 | /** 748 | * required string email = 1; 749 | */ 750 | public com.google.protobuf.ByteString 751 | getEmailBytes() { 752 | java.lang.Object ref = email_; 753 | if (ref instanceof String) { 754 | com.google.protobuf.ByteString b = 755 | com.google.protobuf.ByteString.copyFromUtf8( 756 | (java.lang.String) ref); 757 | email_ = b; 758 | return b; 759 | } else { 760 | return (com.google.protobuf.ByteString) ref; 761 | } 762 | } 763 | /** 764 | * required string email = 1; 765 | */ 766 | public Builder setEmail( 767 | java.lang.String value) { 768 | if (value == null) { 769 | throw new NullPointerException(); 770 | } 771 | bitField0_ |= 0x00000001; 772 | email_ = value; 773 | onChanged(); 774 | return this; 775 | } 776 | /** 777 | * required string email = 1; 778 | */ 779 | public Builder clearEmail() { 780 | bitField0_ = (bitField0_ & ~0x00000001); 781 | email_ = getDefaultInstance().getEmail(); 782 | onChanged(); 783 | return this; 784 | } 785 | /** 786 | * required string email = 1; 787 | */ 788 | public Builder setEmailBytes( 789 | com.google.protobuf.ByteString value) { 790 | if (value == null) { 791 | throw new NullPointerException(); 792 | } 793 | bitField0_ |= 0x00000001; 794 | email_ = value; 795 | onChanged(); 796 | return this; 797 | } 798 | 799 | // optional .demo.Customer.EmailType type = 2 [default = PROFESSIONAL]; 800 | private demo.CustomerProtos.Customer.EmailType type_ = demo.CustomerProtos.Customer.EmailType.PROFESSIONAL; 801 | /** 802 | * optional .demo.Customer.EmailType type = 2 [default = PROFESSIONAL]; 803 | */ 804 | public boolean hasType() { 805 | return ((bitField0_ & 0x00000002) == 0x00000002); 806 | } 807 | /** 808 | * optional .demo.Customer.EmailType type = 2 [default = PROFESSIONAL]; 809 | */ 810 | public demo.CustomerProtos.Customer.EmailType getType() { 811 | return type_; 812 | } 813 | /** 814 | * optional .demo.Customer.EmailType type = 2 [default = PROFESSIONAL]; 815 | */ 816 | public Builder setType(demo.CustomerProtos.Customer.EmailType value) { 817 | if (value == null) { 818 | throw new NullPointerException(); 819 | } 820 | bitField0_ |= 0x00000002; 821 | type_ = value; 822 | onChanged(); 823 | return this; 824 | } 825 | /** 826 | * optional .demo.Customer.EmailType type = 2 [default = PROFESSIONAL]; 827 | */ 828 | public Builder clearType() { 829 | bitField0_ = (bitField0_ & ~0x00000002); 830 | type_ = demo.CustomerProtos.Customer.EmailType.PROFESSIONAL; 831 | onChanged(); 832 | return this; 833 | } 834 | 835 | // @@protoc_insertion_point(builder_scope:demo.Customer.EmailAddress) 836 | } 837 | 838 | static { 839 | defaultInstance = new EmailAddress(true); 840 | defaultInstance.initFields(); 841 | } 842 | 843 | // @@protoc_insertion_point(class_scope:demo.Customer.EmailAddress) 844 | } 845 | 846 | private int bitField0_; 847 | // required int32 id = 1; 848 | public static final int ID_FIELD_NUMBER = 1; 849 | private int id_; 850 | /** 851 | * required int32 id = 1; 852 | */ 853 | public boolean hasId() { 854 | return ((bitField0_ & 0x00000001) == 0x00000001); 855 | } 856 | /** 857 | * required int32 id = 1; 858 | */ 859 | public int getId() { 860 | return id_; 861 | } 862 | 863 | // required string firstName = 2; 864 | public static final int FIRSTNAME_FIELD_NUMBER = 2; 865 | private java.lang.Object firstName_; 866 | /** 867 | * required string firstName = 2; 868 | */ 869 | public boolean hasFirstName() { 870 | return ((bitField0_ & 0x00000002) == 0x00000002); 871 | } 872 | /** 873 | * required string firstName = 2; 874 | */ 875 | public java.lang.String getFirstName() { 876 | java.lang.Object ref = firstName_; 877 | if (ref instanceof java.lang.String) { 878 | return (java.lang.String) ref; 879 | } else { 880 | com.google.protobuf.ByteString bs = 881 | (com.google.protobuf.ByteString) ref; 882 | java.lang.String s = bs.toStringUtf8(); 883 | if (bs.isValidUtf8()) { 884 | firstName_ = s; 885 | } 886 | return s; 887 | } 888 | } 889 | /** 890 | * required string firstName = 2; 891 | */ 892 | public com.google.protobuf.ByteString 893 | getFirstNameBytes() { 894 | java.lang.Object ref = firstName_; 895 | if (ref instanceof java.lang.String) { 896 | com.google.protobuf.ByteString b = 897 | com.google.protobuf.ByteString.copyFromUtf8( 898 | (java.lang.String) ref); 899 | firstName_ = b; 900 | return b; 901 | } else { 902 | return (com.google.protobuf.ByteString) ref; 903 | } 904 | } 905 | 906 | // required string lastName = 3; 907 | public static final int LASTNAME_FIELD_NUMBER = 3; 908 | private java.lang.Object lastName_; 909 | /** 910 | * required string lastName = 3; 911 | */ 912 | public boolean hasLastName() { 913 | return ((bitField0_ & 0x00000004) == 0x00000004); 914 | } 915 | /** 916 | * required string lastName = 3; 917 | */ 918 | public java.lang.String getLastName() { 919 | java.lang.Object ref = lastName_; 920 | if (ref instanceof java.lang.String) { 921 | return (java.lang.String) ref; 922 | } else { 923 | com.google.protobuf.ByteString bs = 924 | (com.google.protobuf.ByteString) ref; 925 | java.lang.String s = bs.toStringUtf8(); 926 | if (bs.isValidUtf8()) { 927 | lastName_ = s; 928 | } 929 | return s; 930 | } 931 | } 932 | /** 933 | * required string lastName = 3; 934 | */ 935 | public com.google.protobuf.ByteString 936 | getLastNameBytes() { 937 | java.lang.Object ref = lastName_; 938 | if (ref instanceof java.lang.String) { 939 | com.google.protobuf.ByteString b = 940 | com.google.protobuf.ByteString.copyFromUtf8( 941 | (java.lang.String) ref); 942 | lastName_ = b; 943 | return b; 944 | } else { 945 | return (com.google.protobuf.ByteString) ref; 946 | } 947 | } 948 | 949 | // repeated .demo.Customer.EmailAddress email = 5; 950 | public static final int EMAIL_FIELD_NUMBER = 5; 951 | private java.util.List email_; 952 | /** 953 | * repeated .demo.Customer.EmailAddress email = 5; 954 | */ 955 | public java.util.List getEmailList() { 956 | return email_; 957 | } 958 | /** 959 | * repeated .demo.Customer.EmailAddress email = 5; 960 | */ 961 | public java.util.List 962 | getEmailOrBuilderList() { 963 | return email_; 964 | } 965 | /** 966 | * repeated .demo.Customer.EmailAddress email = 5; 967 | */ 968 | public int getEmailCount() { 969 | return email_.size(); 970 | } 971 | /** 972 | * repeated .demo.Customer.EmailAddress email = 5; 973 | */ 974 | public demo.CustomerProtos.Customer.EmailAddress getEmail(int index) { 975 | return email_.get(index); 976 | } 977 | /** 978 | * repeated .demo.Customer.EmailAddress email = 5; 979 | */ 980 | public demo.CustomerProtos.Customer.EmailAddressOrBuilder getEmailOrBuilder( 981 | int index) { 982 | return email_.get(index); 983 | } 984 | 985 | private void initFields() { 986 | id_ = 0; 987 | firstName_ = ""; 988 | lastName_ = ""; 989 | email_ = java.util.Collections.emptyList(); 990 | } 991 | private byte memoizedIsInitialized = -1; 992 | public final boolean isInitialized() { 993 | byte isInitialized = memoizedIsInitialized; 994 | if (isInitialized != -1) return isInitialized == 1; 995 | 996 | if (!hasId()) { 997 | memoizedIsInitialized = 0; 998 | return false; 999 | } 1000 | if (!hasFirstName()) { 1001 | memoizedIsInitialized = 0; 1002 | return false; 1003 | } 1004 | if (!hasLastName()) { 1005 | memoizedIsInitialized = 0; 1006 | return false; 1007 | } 1008 | for (int i = 0; i < getEmailCount(); i++) { 1009 | if (!getEmail(i).isInitialized()) { 1010 | memoizedIsInitialized = 0; 1011 | return false; 1012 | } 1013 | } 1014 | memoizedIsInitialized = 1; 1015 | return true; 1016 | } 1017 | 1018 | public void writeTo(com.google.protobuf.CodedOutputStream output) 1019 | throws java.io.IOException { 1020 | getSerializedSize(); 1021 | if (((bitField0_ & 0x00000001) == 0x00000001)) { 1022 | output.writeInt32(1, id_); 1023 | } 1024 | if (((bitField0_ & 0x00000002) == 0x00000002)) { 1025 | output.writeBytes(2, getFirstNameBytes()); 1026 | } 1027 | if (((bitField0_ & 0x00000004) == 0x00000004)) { 1028 | output.writeBytes(3, getLastNameBytes()); 1029 | } 1030 | for (int i = 0; i < email_.size(); i++) { 1031 | output.writeMessage(5, email_.get(i)); 1032 | } 1033 | getUnknownFields().writeTo(output); 1034 | } 1035 | 1036 | private int memoizedSerializedSize = -1; 1037 | public int getSerializedSize() { 1038 | int size = memoizedSerializedSize; 1039 | if (size != -1) return size; 1040 | 1041 | size = 0; 1042 | if (((bitField0_ & 0x00000001) == 0x00000001)) { 1043 | size += com.google.protobuf.CodedOutputStream 1044 | .computeInt32Size(1, id_); 1045 | } 1046 | if (((bitField0_ & 0x00000002) == 0x00000002)) { 1047 | size += com.google.protobuf.CodedOutputStream 1048 | .computeBytesSize(2, getFirstNameBytes()); 1049 | } 1050 | if (((bitField0_ & 0x00000004) == 0x00000004)) { 1051 | size += com.google.protobuf.CodedOutputStream 1052 | .computeBytesSize(3, getLastNameBytes()); 1053 | } 1054 | for (int i = 0; i < email_.size(); i++) { 1055 | size += com.google.protobuf.CodedOutputStream 1056 | .computeMessageSize(5, email_.get(i)); 1057 | } 1058 | size += getUnknownFields().getSerializedSize(); 1059 | memoizedSerializedSize = size; 1060 | return size; 1061 | } 1062 | 1063 | private static final long serialVersionUID = 0L; 1064 | @java.lang.Override 1065 | protected java.lang.Object writeReplace() 1066 | throws java.io.ObjectStreamException { 1067 | return super.writeReplace(); 1068 | } 1069 | 1070 | public static demo.CustomerProtos.Customer parseFrom( 1071 | com.google.protobuf.ByteString data) 1072 | throws com.google.protobuf.InvalidProtocolBufferException { 1073 | return PARSER.parseFrom(data); 1074 | } 1075 | public static demo.CustomerProtos.Customer parseFrom( 1076 | com.google.protobuf.ByteString data, 1077 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1078 | throws com.google.protobuf.InvalidProtocolBufferException { 1079 | return PARSER.parseFrom(data, extensionRegistry); 1080 | } 1081 | public static demo.CustomerProtos.Customer parseFrom(byte[] data) 1082 | throws com.google.protobuf.InvalidProtocolBufferException { 1083 | return PARSER.parseFrom(data); 1084 | } 1085 | public static demo.CustomerProtos.Customer parseFrom( 1086 | byte[] data, 1087 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1088 | throws com.google.protobuf.InvalidProtocolBufferException { 1089 | return PARSER.parseFrom(data, extensionRegistry); 1090 | } 1091 | public static demo.CustomerProtos.Customer parseFrom(java.io.InputStream input) 1092 | throws java.io.IOException { 1093 | return PARSER.parseFrom(input); 1094 | } 1095 | public static demo.CustomerProtos.Customer parseFrom( 1096 | java.io.InputStream input, 1097 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1098 | throws java.io.IOException { 1099 | return PARSER.parseFrom(input, extensionRegistry); 1100 | } 1101 | public static demo.CustomerProtos.Customer parseDelimitedFrom(java.io.InputStream input) 1102 | throws java.io.IOException { 1103 | return PARSER.parseDelimitedFrom(input); 1104 | } 1105 | public static demo.CustomerProtos.Customer parseDelimitedFrom( 1106 | java.io.InputStream input, 1107 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1108 | throws java.io.IOException { 1109 | return PARSER.parseDelimitedFrom(input, extensionRegistry); 1110 | } 1111 | public static demo.CustomerProtos.Customer parseFrom( 1112 | com.google.protobuf.CodedInputStream input) 1113 | throws java.io.IOException { 1114 | return PARSER.parseFrom(input); 1115 | } 1116 | public static demo.CustomerProtos.Customer parseFrom( 1117 | com.google.protobuf.CodedInputStream input, 1118 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1119 | throws java.io.IOException { 1120 | return PARSER.parseFrom(input, extensionRegistry); 1121 | } 1122 | 1123 | public static Builder newBuilder() { return Builder.create(); } 1124 | public Builder newBuilderForType() { return newBuilder(); } 1125 | public static Builder newBuilder(demo.CustomerProtos.Customer prototype) { 1126 | return newBuilder().mergeFrom(prototype); 1127 | } 1128 | public Builder toBuilder() { return newBuilder(this); } 1129 | 1130 | @java.lang.Override 1131 | protected Builder newBuilderForType( 1132 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 1133 | Builder builder = new Builder(parent); 1134 | return builder; 1135 | } 1136 | /** 1137 | * Protobuf type {@code demo.Customer} 1138 | */ 1139 | public static final class Builder extends 1140 | com.google.protobuf.GeneratedMessage.Builder 1141 | implements demo.CustomerProtos.CustomerOrBuilder { 1142 | public static final com.google.protobuf.Descriptors.Descriptor 1143 | getDescriptor() { 1144 | return demo.CustomerProtos.internal_static_demo_Customer_descriptor; 1145 | } 1146 | 1147 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 1148 | internalGetFieldAccessorTable() { 1149 | return demo.CustomerProtos.internal_static_demo_Customer_fieldAccessorTable 1150 | .ensureFieldAccessorsInitialized( 1151 | demo.CustomerProtos.Customer.class, demo.CustomerProtos.Customer.Builder.class); 1152 | } 1153 | 1154 | // Construct using demo.CustomerProtos.Customer.newBuilder() 1155 | private Builder() { 1156 | maybeForceBuilderInitialization(); 1157 | } 1158 | 1159 | private Builder( 1160 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 1161 | super(parent); 1162 | maybeForceBuilderInitialization(); 1163 | } 1164 | private void maybeForceBuilderInitialization() { 1165 | if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { 1166 | getEmailFieldBuilder(); 1167 | } 1168 | } 1169 | private static Builder create() { 1170 | return new Builder(); 1171 | } 1172 | 1173 | public Builder clear() { 1174 | super.clear(); 1175 | id_ = 0; 1176 | bitField0_ = (bitField0_ & ~0x00000001); 1177 | firstName_ = ""; 1178 | bitField0_ = (bitField0_ & ~0x00000002); 1179 | lastName_ = ""; 1180 | bitField0_ = (bitField0_ & ~0x00000004); 1181 | if (emailBuilder_ == null) { 1182 | email_ = java.util.Collections.emptyList(); 1183 | bitField0_ = (bitField0_ & ~0x00000008); 1184 | } else { 1185 | emailBuilder_.clear(); 1186 | } 1187 | return this; 1188 | } 1189 | 1190 | public Builder clone() { 1191 | return create().mergeFrom(buildPartial()); 1192 | } 1193 | 1194 | public com.google.protobuf.Descriptors.Descriptor 1195 | getDescriptorForType() { 1196 | return demo.CustomerProtos.internal_static_demo_Customer_descriptor; 1197 | } 1198 | 1199 | public demo.CustomerProtos.Customer getDefaultInstanceForType() { 1200 | return demo.CustomerProtos.Customer.getDefaultInstance(); 1201 | } 1202 | 1203 | public demo.CustomerProtos.Customer build() { 1204 | demo.CustomerProtos.Customer result = buildPartial(); 1205 | if (!result.isInitialized()) { 1206 | throw newUninitializedMessageException(result); 1207 | } 1208 | return result; 1209 | } 1210 | 1211 | public demo.CustomerProtos.Customer buildPartial() { 1212 | demo.CustomerProtos.Customer result = new demo.CustomerProtos.Customer(this); 1213 | int from_bitField0_ = bitField0_; 1214 | int to_bitField0_ = 0; 1215 | if (((from_bitField0_ & 0x00000001) == 0x00000001)) { 1216 | to_bitField0_ |= 0x00000001; 1217 | } 1218 | result.id_ = id_; 1219 | if (((from_bitField0_ & 0x00000002) == 0x00000002)) { 1220 | to_bitField0_ |= 0x00000002; 1221 | } 1222 | result.firstName_ = firstName_; 1223 | if (((from_bitField0_ & 0x00000004) == 0x00000004)) { 1224 | to_bitField0_ |= 0x00000004; 1225 | } 1226 | result.lastName_ = lastName_; 1227 | if (emailBuilder_ == null) { 1228 | if (((bitField0_ & 0x00000008) == 0x00000008)) { 1229 | email_ = java.util.Collections.unmodifiableList(email_); 1230 | bitField0_ = (bitField0_ & ~0x00000008); 1231 | } 1232 | result.email_ = email_; 1233 | } else { 1234 | result.email_ = emailBuilder_.build(); 1235 | } 1236 | result.bitField0_ = to_bitField0_; 1237 | onBuilt(); 1238 | return result; 1239 | } 1240 | 1241 | public Builder mergeFrom(com.google.protobuf.Message other) { 1242 | if (other instanceof demo.CustomerProtos.Customer) { 1243 | return mergeFrom((demo.CustomerProtos.Customer)other); 1244 | } else { 1245 | super.mergeFrom(other); 1246 | return this; 1247 | } 1248 | } 1249 | 1250 | public Builder mergeFrom(demo.CustomerProtos.Customer other) { 1251 | if (other == demo.CustomerProtos.Customer.getDefaultInstance()) return this; 1252 | if (other.hasId()) { 1253 | setId(other.getId()); 1254 | } 1255 | if (other.hasFirstName()) { 1256 | bitField0_ |= 0x00000002; 1257 | firstName_ = other.firstName_; 1258 | onChanged(); 1259 | } 1260 | if (other.hasLastName()) { 1261 | bitField0_ |= 0x00000004; 1262 | lastName_ = other.lastName_; 1263 | onChanged(); 1264 | } 1265 | if (emailBuilder_ == null) { 1266 | if (!other.email_.isEmpty()) { 1267 | if (email_.isEmpty()) { 1268 | email_ = other.email_; 1269 | bitField0_ = (bitField0_ & ~0x00000008); 1270 | } else { 1271 | ensureEmailIsMutable(); 1272 | email_.addAll(other.email_); 1273 | } 1274 | onChanged(); 1275 | } 1276 | } else { 1277 | if (!other.email_.isEmpty()) { 1278 | if (emailBuilder_.isEmpty()) { 1279 | emailBuilder_.dispose(); 1280 | emailBuilder_ = null; 1281 | email_ = other.email_; 1282 | bitField0_ = (bitField0_ & ~0x00000008); 1283 | emailBuilder_ = 1284 | com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? 1285 | getEmailFieldBuilder() : null; 1286 | } else { 1287 | emailBuilder_.addAllMessages(other.email_); 1288 | } 1289 | } 1290 | } 1291 | this.mergeUnknownFields(other.getUnknownFields()); 1292 | return this; 1293 | } 1294 | 1295 | public final boolean isInitialized() { 1296 | if (!hasId()) { 1297 | 1298 | return false; 1299 | } 1300 | if (!hasFirstName()) { 1301 | 1302 | return false; 1303 | } 1304 | if (!hasLastName()) { 1305 | 1306 | return false; 1307 | } 1308 | for (int i = 0; i < getEmailCount(); i++) { 1309 | if (!getEmail(i).isInitialized()) { 1310 | 1311 | return false; 1312 | } 1313 | } 1314 | return true; 1315 | } 1316 | 1317 | public Builder mergeFrom( 1318 | com.google.protobuf.CodedInputStream input, 1319 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1320 | throws java.io.IOException { 1321 | demo.CustomerProtos.Customer parsedMessage = null; 1322 | try { 1323 | parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); 1324 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 1325 | parsedMessage = (demo.CustomerProtos.Customer) e.getUnfinishedMessage(); 1326 | throw e; 1327 | } finally { 1328 | if (parsedMessage != null) { 1329 | mergeFrom(parsedMessage); 1330 | } 1331 | } 1332 | return this; 1333 | } 1334 | private int bitField0_; 1335 | 1336 | // required int32 id = 1; 1337 | private int id_ ; 1338 | /** 1339 | * required int32 id = 1; 1340 | */ 1341 | public boolean hasId() { 1342 | return ((bitField0_ & 0x00000001) == 0x00000001); 1343 | } 1344 | /** 1345 | * required int32 id = 1; 1346 | */ 1347 | public int getId() { 1348 | return id_; 1349 | } 1350 | /** 1351 | * required int32 id = 1; 1352 | */ 1353 | public Builder setId(int value) { 1354 | bitField0_ |= 0x00000001; 1355 | id_ = value; 1356 | onChanged(); 1357 | return this; 1358 | } 1359 | /** 1360 | * required int32 id = 1; 1361 | */ 1362 | public Builder clearId() { 1363 | bitField0_ = (bitField0_ & ~0x00000001); 1364 | id_ = 0; 1365 | onChanged(); 1366 | return this; 1367 | } 1368 | 1369 | // required string firstName = 2; 1370 | private java.lang.Object firstName_ = ""; 1371 | /** 1372 | * required string firstName = 2; 1373 | */ 1374 | public boolean hasFirstName() { 1375 | return ((bitField0_ & 0x00000002) == 0x00000002); 1376 | } 1377 | /** 1378 | * required string firstName = 2; 1379 | */ 1380 | public java.lang.String getFirstName() { 1381 | java.lang.Object ref = firstName_; 1382 | if (!(ref instanceof java.lang.String)) { 1383 | java.lang.String s = ((com.google.protobuf.ByteString) ref) 1384 | .toStringUtf8(); 1385 | firstName_ = s; 1386 | return s; 1387 | } else { 1388 | return (java.lang.String) ref; 1389 | } 1390 | } 1391 | /** 1392 | * required string firstName = 2; 1393 | */ 1394 | public com.google.protobuf.ByteString 1395 | getFirstNameBytes() { 1396 | java.lang.Object ref = firstName_; 1397 | if (ref instanceof String) { 1398 | com.google.protobuf.ByteString b = 1399 | com.google.protobuf.ByteString.copyFromUtf8( 1400 | (java.lang.String) ref); 1401 | firstName_ = b; 1402 | return b; 1403 | } else { 1404 | return (com.google.protobuf.ByteString) ref; 1405 | } 1406 | } 1407 | /** 1408 | * required string firstName = 2; 1409 | */ 1410 | public Builder setFirstName( 1411 | java.lang.String value) { 1412 | if (value == null) { 1413 | throw new NullPointerException(); 1414 | } 1415 | bitField0_ |= 0x00000002; 1416 | firstName_ = value; 1417 | onChanged(); 1418 | return this; 1419 | } 1420 | /** 1421 | * required string firstName = 2; 1422 | */ 1423 | public Builder clearFirstName() { 1424 | bitField0_ = (bitField0_ & ~0x00000002); 1425 | firstName_ = getDefaultInstance().getFirstName(); 1426 | onChanged(); 1427 | return this; 1428 | } 1429 | /** 1430 | * required string firstName = 2; 1431 | */ 1432 | public Builder setFirstNameBytes( 1433 | com.google.protobuf.ByteString value) { 1434 | if (value == null) { 1435 | throw new NullPointerException(); 1436 | } 1437 | bitField0_ |= 0x00000002; 1438 | firstName_ = value; 1439 | onChanged(); 1440 | return this; 1441 | } 1442 | 1443 | // required string lastName = 3; 1444 | private java.lang.Object lastName_ = ""; 1445 | /** 1446 | * required string lastName = 3; 1447 | */ 1448 | public boolean hasLastName() { 1449 | return ((bitField0_ & 0x00000004) == 0x00000004); 1450 | } 1451 | /** 1452 | * required string lastName = 3; 1453 | */ 1454 | public java.lang.String getLastName() { 1455 | java.lang.Object ref = lastName_; 1456 | if (!(ref instanceof java.lang.String)) { 1457 | java.lang.String s = ((com.google.protobuf.ByteString) ref) 1458 | .toStringUtf8(); 1459 | lastName_ = s; 1460 | return s; 1461 | } else { 1462 | return (java.lang.String) ref; 1463 | } 1464 | } 1465 | /** 1466 | * required string lastName = 3; 1467 | */ 1468 | public com.google.protobuf.ByteString 1469 | getLastNameBytes() { 1470 | java.lang.Object ref = lastName_; 1471 | if (ref instanceof String) { 1472 | com.google.protobuf.ByteString b = 1473 | com.google.protobuf.ByteString.copyFromUtf8( 1474 | (java.lang.String) ref); 1475 | lastName_ = b; 1476 | return b; 1477 | } else { 1478 | return (com.google.protobuf.ByteString) ref; 1479 | } 1480 | } 1481 | /** 1482 | * required string lastName = 3; 1483 | */ 1484 | public Builder setLastName( 1485 | java.lang.String value) { 1486 | if (value == null) { 1487 | throw new NullPointerException(); 1488 | } 1489 | bitField0_ |= 0x00000004; 1490 | lastName_ = value; 1491 | onChanged(); 1492 | return this; 1493 | } 1494 | /** 1495 | * required string lastName = 3; 1496 | */ 1497 | public Builder clearLastName() { 1498 | bitField0_ = (bitField0_ & ~0x00000004); 1499 | lastName_ = getDefaultInstance().getLastName(); 1500 | onChanged(); 1501 | return this; 1502 | } 1503 | /** 1504 | * required string lastName = 3; 1505 | */ 1506 | public Builder setLastNameBytes( 1507 | com.google.protobuf.ByteString value) { 1508 | if (value == null) { 1509 | throw new NullPointerException(); 1510 | } 1511 | bitField0_ |= 0x00000004; 1512 | lastName_ = value; 1513 | onChanged(); 1514 | return this; 1515 | } 1516 | 1517 | // repeated .demo.Customer.EmailAddress email = 5; 1518 | private java.util.List email_ = 1519 | java.util.Collections.emptyList(); 1520 | private void ensureEmailIsMutable() { 1521 | if (!((bitField0_ & 0x00000008) == 0x00000008)) { 1522 | email_ = new java.util.ArrayList(email_); 1523 | bitField0_ |= 0x00000008; 1524 | } 1525 | } 1526 | 1527 | private com.google.protobuf.RepeatedFieldBuilder< 1528 | demo.CustomerProtos.Customer.EmailAddress, demo.CustomerProtos.Customer.EmailAddress.Builder, demo.CustomerProtos.Customer.EmailAddressOrBuilder> emailBuilder_; 1529 | 1530 | /** 1531 | * repeated .demo.Customer.EmailAddress email = 5; 1532 | */ 1533 | public java.util.List getEmailList() { 1534 | if (emailBuilder_ == null) { 1535 | return java.util.Collections.unmodifiableList(email_); 1536 | } else { 1537 | return emailBuilder_.getMessageList(); 1538 | } 1539 | } 1540 | /** 1541 | * repeated .demo.Customer.EmailAddress email = 5; 1542 | */ 1543 | public int getEmailCount() { 1544 | if (emailBuilder_ == null) { 1545 | return email_.size(); 1546 | } else { 1547 | return emailBuilder_.getCount(); 1548 | } 1549 | } 1550 | /** 1551 | * repeated .demo.Customer.EmailAddress email = 5; 1552 | */ 1553 | public demo.CustomerProtos.Customer.EmailAddress getEmail(int index) { 1554 | if (emailBuilder_ == null) { 1555 | return email_.get(index); 1556 | } else { 1557 | return emailBuilder_.getMessage(index); 1558 | } 1559 | } 1560 | /** 1561 | * repeated .demo.Customer.EmailAddress email = 5; 1562 | */ 1563 | public Builder setEmail( 1564 | int index, demo.CustomerProtos.Customer.EmailAddress value) { 1565 | if (emailBuilder_ == null) { 1566 | if (value == null) { 1567 | throw new NullPointerException(); 1568 | } 1569 | ensureEmailIsMutable(); 1570 | email_.set(index, value); 1571 | onChanged(); 1572 | } else { 1573 | emailBuilder_.setMessage(index, value); 1574 | } 1575 | return this; 1576 | } 1577 | /** 1578 | * repeated .demo.Customer.EmailAddress email = 5; 1579 | */ 1580 | public Builder setEmail( 1581 | int index, demo.CustomerProtos.Customer.EmailAddress.Builder builderForValue) { 1582 | if (emailBuilder_ == null) { 1583 | ensureEmailIsMutable(); 1584 | email_.set(index, builderForValue.build()); 1585 | onChanged(); 1586 | } else { 1587 | emailBuilder_.setMessage(index, builderForValue.build()); 1588 | } 1589 | return this; 1590 | } 1591 | /** 1592 | * repeated .demo.Customer.EmailAddress email = 5; 1593 | */ 1594 | public Builder addEmail(demo.CustomerProtos.Customer.EmailAddress value) { 1595 | if (emailBuilder_ == null) { 1596 | if (value == null) { 1597 | throw new NullPointerException(); 1598 | } 1599 | ensureEmailIsMutable(); 1600 | email_.add(value); 1601 | onChanged(); 1602 | } else { 1603 | emailBuilder_.addMessage(value); 1604 | } 1605 | return this; 1606 | } 1607 | /** 1608 | * repeated .demo.Customer.EmailAddress email = 5; 1609 | */ 1610 | public Builder addEmail( 1611 | int index, demo.CustomerProtos.Customer.EmailAddress value) { 1612 | if (emailBuilder_ == null) { 1613 | if (value == null) { 1614 | throw new NullPointerException(); 1615 | } 1616 | ensureEmailIsMutable(); 1617 | email_.add(index, value); 1618 | onChanged(); 1619 | } else { 1620 | emailBuilder_.addMessage(index, value); 1621 | } 1622 | return this; 1623 | } 1624 | /** 1625 | * repeated .demo.Customer.EmailAddress email = 5; 1626 | */ 1627 | public Builder addEmail( 1628 | demo.CustomerProtos.Customer.EmailAddress.Builder builderForValue) { 1629 | if (emailBuilder_ == null) { 1630 | ensureEmailIsMutable(); 1631 | email_.add(builderForValue.build()); 1632 | onChanged(); 1633 | } else { 1634 | emailBuilder_.addMessage(builderForValue.build()); 1635 | } 1636 | return this; 1637 | } 1638 | /** 1639 | * repeated .demo.Customer.EmailAddress email = 5; 1640 | */ 1641 | public Builder addEmail( 1642 | int index, demo.CustomerProtos.Customer.EmailAddress.Builder builderForValue) { 1643 | if (emailBuilder_ == null) { 1644 | ensureEmailIsMutable(); 1645 | email_.add(index, builderForValue.build()); 1646 | onChanged(); 1647 | } else { 1648 | emailBuilder_.addMessage(index, builderForValue.build()); 1649 | } 1650 | return this; 1651 | } 1652 | /** 1653 | * repeated .demo.Customer.EmailAddress email = 5; 1654 | */ 1655 | public Builder addAllEmail( 1656 | java.lang.Iterable values) { 1657 | if (emailBuilder_ == null) { 1658 | ensureEmailIsMutable(); 1659 | super.addAll(values, email_); 1660 | onChanged(); 1661 | } else { 1662 | emailBuilder_.addAllMessages(values); 1663 | } 1664 | return this; 1665 | } 1666 | /** 1667 | * repeated .demo.Customer.EmailAddress email = 5; 1668 | */ 1669 | public Builder clearEmail() { 1670 | if (emailBuilder_ == null) { 1671 | email_ = java.util.Collections.emptyList(); 1672 | bitField0_ = (bitField0_ & ~0x00000008); 1673 | onChanged(); 1674 | } else { 1675 | emailBuilder_.clear(); 1676 | } 1677 | return this; 1678 | } 1679 | /** 1680 | * repeated .demo.Customer.EmailAddress email = 5; 1681 | */ 1682 | public Builder removeEmail(int index) { 1683 | if (emailBuilder_ == null) { 1684 | ensureEmailIsMutable(); 1685 | email_.remove(index); 1686 | onChanged(); 1687 | } else { 1688 | emailBuilder_.remove(index); 1689 | } 1690 | return this; 1691 | } 1692 | /** 1693 | * repeated .demo.Customer.EmailAddress email = 5; 1694 | */ 1695 | public demo.CustomerProtos.Customer.EmailAddress.Builder getEmailBuilder( 1696 | int index) { 1697 | return getEmailFieldBuilder().getBuilder(index); 1698 | } 1699 | /** 1700 | * repeated .demo.Customer.EmailAddress email = 5; 1701 | */ 1702 | public demo.CustomerProtos.Customer.EmailAddressOrBuilder getEmailOrBuilder( 1703 | int index) { 1704 | if (emailBuilder_ == null) { 1705 | return email_.get(index); } else { 1706 | return emailBuilder_.getMessageOrBuilder(index); 1707 | } 1708 | } 1709 | /** 1710 | * repeated .demo.Customer.EmailAddress email = 5; 1711 | */ 1712 | public java.util.List 1713 | getEmailOrBuilderList() { 1714 | if (emailBuilder_ != null) { 1715 | return emailBuilder_.getMessageOrBuilderList(); 1716 | } else { 1717 | return java.util.Collections.unmodifiableList(email_); 1718 | } 1719 | } 1720 | /** 1721 | * repeated .demo.Customer.EmailAddress email = 5; 1722 | */ 1723 | public demo.CustomerProtos.Customer.EmailAddress.Builder addEmailBuilder() { 1724 | return getEmailFieldBuilder().addBuilder( 1725 | demo.CustomerProtos.Customer.EmailAddress.getDefaultInstance()); 1726 | } 1727 | /** 1728 | * repeated .demo.Customer.EmailAddress email = 5; 1729 | */ 1730 | public demo.CustomerProtos.Customer.EmailAddress.Builder addEmailBuilder( 1731 | int index) { 1732 | return getEmailFieldBuilder().addBuilder( 1733 | index, demo.CustomerProtos.Customer.EmailAddress.getDefaultInstance()); 1734 | } 1735 | /** 1736 | * repeated .demo.Customer.EmailAddress email = 5; 1737 | */ 1738 | public java.util.List 1739 | getEmailBuilderList() { 1740 | return getEmailFieldBuilder().getBuilderList(); 1741 | } 1742 | private com.google.protobuf.RepeatedFieldBuilder< 1743 | demo.CustomerProtos.Customer.EmailAddress, demo.CustomerProtos.Customer.EmailAddress.Builder, demo.CustomerProtos.Customer.EmailAddressOrBuilder> 1744 | getEmailFieldBuilder() { 1745 | if (emailBuilder_ == null) { 1746 | emailBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< 1747 | demo.CustomerProtos.Customer.EmailAddress, demo.CustomerProtos.Customer.EmailAddress.Builder, demo.CustomerProtos.Customer.EmailAddressOrBuilder>( 1748 | email_, 1749 | ((bitField0_ & 0x00000008) == 0x00000008), 1750 | getParentForChildren(), 1751 | isClean()); 1752 | email_ = null; 1753 | } 1754 | return emailBuilder_; 1755 | } 1756 | 1757 | // @@protoc_insertion_point(builder_scope:demo.Customer) 1758 | } 1759 | 1760 | static { 1761 | defaultInstance = new Customer(true); 1762 | defaultInstance.initFields(); 1763 | } 1764 | 1765 | // @@protoc_insertion_point(class_scope:demo.Customer) 1766 | } 1767 | 1768 | public interface OrganizationOrBuilder 1769 | extends com.google.protobuf.MessageOrBuilder { 1770 | 1771 | // required string name = 4; 1772 | /** 1773 | * required string name = 4; 1774 | */ 1775 | boolean hasName(); 1776 | /** 1777 | * required string name = 4; 1778 | */ 1779 | java.lang.String getName(); 1780 | /** 1781 | * required string name = 4; 1782 | */ 1783 | com.google.protobuf.ByteString 1784 | getNameBytes(); 1785 | 1786 | // repeated .demo.Customer customer = 1; 1787 | /** 1788 | * repeated .demo.Customer customer = 1; 1789 | */ 1790 | java.util.List 1791 | getCustomerList(); 1792 | /** 1793 | * repeated .demo.Customer customer = 1; 1794 | */ 1795 | demo.CustomerProtos.Customer getCustomer(int index); 1796 | /** 1797 | * repeated .demo.Customer customer = 1; 1798 | */ 1799 | int getCustomerCount(); 1800 | /** 1801 | * repeated .demo.Customer customer = 1; 1802 | */ 1803 | java.util.List 1804 | getCustomerOrBuilderList(); 1805 | /** 1806 | * repeated .demo.Customer customer = 1; 1807 | */ 1808 | demo.CustomerProtos.CustomerOrBuilder getCustomerOrBuilder( 1809 | int index); 1810 | } 1811 | /** 1812 | * Protobuf type {@code demo.Organization} 1813 | */ 1814 | public static final class Organization extends 1815 | com.google.protobuf.GeneratedMessage 1816 | implements OrganizationOrBuilder { 1817 | // Use Organization.newBuilder() to construct. 1818 | private Organization(com.google.protobuf.GeneratedMessage.Builder builder) { 1819 | super(builder); 1820 | this.unknownFields = builder.getUnknownFields(); 1821 | } 1822 | private Organization(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } 1823 | 1824 | private static final Organization defaultInstance; 1825 | public static Organization getDefaultInstance() { 1826 | return defaultInstance; 1827 | } 1828 | 1829 | public Organization getDefaultInstanceForType() { 1830 | return defaultInstance; 1831 | } 1832 | 1833 | private final com.google.protobuf.UnknownFieldSet unknownFields; 1834 | @java.lang.Override 1835 | public final com.google.protobuf.UnknownFieldSet 1836 | getUnknownFields() { 1837 | return this.unknownFields; 1838 | } 1839 | private Organization( 1840 | com.google.protobuf.CodedInputStream input, 1841 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1842 | throws com.google.protobuf.InvalidProtocolBufferException { 1843 | initFields(); 1844 | int mutable_bitField0_ = 0; 1845 | com.google.protobuf.UnknownFieldSet.Builder unknownFields = 1846 | com.google.protobuf.UnknownFieldSet.newBuilder(); 1847 | try { 1848 | boolean done = false; 1849 | while (!done) { 1850 | int tag = input.readTag(); 1851 | switch (tag) { 1852 | case 0: 1853 | done = true; 1854 | break; 1855 | default: { 1856 | if (!parseUnknownField(input, unknownFields, 1857 | extensionRegistry, tag)) { 1858 | done = true; 1859 | } 1860 | break; 1861 | } 1862 | case 10: { 1863 | if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) { 1864 | customer_ = new java.util.ArrayList(); 1865 | mutable_bitField0_ |= 0x00000002; 1866 | } 1867 | customer_.add(input.readMessage(demo.CustomerProtos.Customer.PARSER, extensionRegistry)); 1868 | break; 1869 | } 1870 | case 34: { 1871 | bitField0_ |= 0x00000001; 1872 | name_ = input.readBytes(); 1873 | break; 1874 | } 1875 | } 1876 | } 1877 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 1878 | throw e.setUnfinishedMessage(this); 1879 | } catch (java.io.IOException e) { 1880 | throw new com.google.protobuf.InvalidProtocolBufferException( 1881 | e.getMessage()).setUnfinishedMessage(this); 1882 | } finally { 1883 | if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) { 1884 | customer_ = java.util.Collections.unmodifiableList(customer_); 1885 | } 1886 | this.unknownFields = unknownFields.build(); 1887 | makeExtensionsImmutable(); 1888 | } 1889 | } 1890 | public static final com.google.protobuf.Descriptors.Descriptor 1891 | getDescriptor() { 1892 | return demo.CustomerProtos.internal_static_demo_Organization_descriptor; 1893 | } 1894 | 1895 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 1896 | internalGetFieldAccessorTable() { 1897 | return demo.CustomerProtos.internal_static_demo_Organization_fieldAccessorTable 1898 | .ensureFieldAccessorsInitialized( 1899 | demo.CustomerProtos.Organization.class, demo.CustomerProtos.Organization.Builder.class); 1900 | } 1901 | 1902 | public static com.google.protobuf.Parser PARSER = 1903 | new com.google.protobuf.AbstractParser() { 1904 | public Organization parsePartialFrom( 1905 | com.google.protobuf.CodedInputStream input, 1906 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 1907 | throws com.google.protobuf.InvalidProtocolBufferException { 1908 | return new Organization(input, extensionRegistry); 1909 | } 1910 | }; 1911 | 1912 | @java.lang.Override 1913 | public com.google.protobuf.Parser getParserForType() { 1914 | return PARSER; 1915 | } 1916 | 1917 | private int bitField0_; 1918 | // required string name = 4; 1919 | public static final int NAME_FIELD_NUMBER = 4; 1920 | private java.lang.Object name_; 1921 | /** 1922 | * required string name = 4; 1923 | */ 1924 | public boolean hasName() { 1925 | return ((bitField0_ & 0x00000001) == 0x00000001); 1926 | } 1927 | /** 1928 | * required string name = 4; 1929 | */ 1930 | public java.lang.String getName() { 1931 | java.lang.Object ref = name_; 1932 | if (ref instanceof java.lang.String) { 1933 | return (java.lang.String) ref; 1934 | } else { 1935 | com.google.protobuf.ByteString bs = 1936 | (com.google.protobuf.ByteString) ref; 1937 | java.lang.String s = bs.toStringUtf8(); 1938 | if (bs.isValidUtf8()) { 1939 | name_ = s; 1940 | } 1941 | return s; 1942 | } 1943 | } 1944 | /** 1945 | * required string name = 4; 1946 | */ 1947 | public com.google.protobuf.ByteString 1948 | getNameBytes() { 1949 | java.lang.Object ref = name_; 1950 | if (ref instanceof java.lang.String) { 1951 | com.google.protobuf.ByteString b = 1952 | com.google.protobuf.ByteString.copyFromUtf8( 1953 | (java.lang.String) ref); 1954 | name_ = b; 1955 | return b; 1956 | } else { 1957 | return (com.google.protobuf.ByteString) ref; 1958 | } 1959 | } 1960 | 1961 | // repeated .demo.Customer customer = 1; 1962 | public static final int CUSTOMER_FIELD_NUMBER = 1; 1963 | private java.util.List customer_; 1964 | /** 1965 | * repeated .demo.Customer customer = 1; 1966 | */ 1967 | public java.util.List getCustomerList() { 1968 | return customer_; 1969 | } 1970 | /** 1971 | * repeated .demo.Customer customer = 1; 1972 | */ 1973 | public java.util.List 1974 | getCustomerOrBuilderList() { 1975 | return customer_; 1976 | } 1977 | /** 1978 | * repeated .demo.Customer customer = 1; 1979 | */ 1980 | public int getCustomerCount() { 1981 | return customer_.size(); 1982 | } 1983 | /** 1984 | * repeated .demo.Customer customer = 1; 1985 | */ 1986 | public demo.CustomerProtos.Customer getCustomer(int index) { 1987 | return customer_.get(index); 1988 | } 1989 | /** 1990 | * repeated .demo.Customer customer = 1; 1991 | */ 1992 | public demo.CustomerProtos.CustomerOrBuilder getCustomerOrBuilder( 1993 | int index) { 1994 | return customer_.get(index); 1995 | } 1996 | 1997 | private void initFields() { 1998 | name_ = ""; 1999 | customer_ = java.util.Collections.emptyList(); 2000 | } 2001 | private byte memoizedIsInitialized = -1; 2002 | public final boolean isInitialized() { 2003 | byte isInitialized = memoizedIsInitialized; 2004 | if (isInitialized != -1) return isInitialized == 1; 2005 | 2006 | if (!hasName()) { 2007 | memoizedIsInitialized = 0; 2008 | return false; 2009 | } 2010 | for (int i = 0; i < getCustomerCount(); i++) { 2011 | if (!getCustomer(i).isInitialized()) { 2012 | memoizedIsInitialized = 0; 2013 | return false; 2014 | } 2015 | } 2016 | memoizedIsInitialized = 1; 2017 | return true; 2018 | } 2019 | 2020 | public void writeTo(com.google.protobuf.CodedOutputStream output) 2021 | throws java.io.IOException { 2022 | getSerializedSize(); 2023 | for (int i = 0; i < customer_.size(); i++) { 2024 | output.writeMessage(1, customer_.get(i)); 2025 | } 2026 | if (((bitField0_ & 0x00000001) == 0x00000001)) { 2027 | output.writeBytes(4, getNameBytes()); 2028 | } 2029 | getUnknownFields().writeTo(output); 2030 | } 2031 | 2032 | private int memoizedSerializedSize = -1; 2033 | public int getSerializedSize() { 2034 | int size = memoizedSerializedSize; 2035 | if (size != -1) return size; 2036 | 2037 | size = 0; 2038 | for (int i = 0; i < customer_.size(); i++) { 2039 | size += com.google.protobuf.CodedOutputStream 2040 | .computeMessageSize(1, customer_.get(i)); 2041 | } 2042 | if (((bitField0_ & 0x00000001) == 0x00000001)) { 2043 | size += com.google.protobuf.CodedOutputStream 2044 | .computeBytesSize(4, getNameBytes()); 2045 | } 2046 | size += getUnknownFields().getSerializedSize(); 2047 | memoizedSerializedSize = size; 2048 | return size; 2049 | } 2050 | 2051 | private static final long serialVersionUID = 0L; 2052 | @java.lang.Override 2053 | protected java.lang.Object writeReplace() 2054 | throws java.io.ObjectStreamException { 2055 | return super.writeReplace(); 2056 | } 2057 | 2058 | public static demo.CustomerProtos.Organization parseFrom( 2059 | com.google.protobuf.ByteString data) 2060 | throws com.google.protobuf.InvalidProtocolBufferException { 2061 | return PARSER.parseFrom(data); 2062 | } 2063 | public static demo.CustomerProtos.Organization parseFrom( 2064 | com.google.protobuf.ByteString data, 2065 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 2066 | throws com.google.protobuf.InvalidProtocolBufferException { 2067 | return PARSER.parseFrom(data, extensionRegistry); 2068 | } 2069 | public static demo.CustomerProtos.Organization parseFrom(byte[] data) 2070 | throws com.google.protobuf.InvalidProtocolBufferException { 2071 | return PARSER.parseFrom(data); 2072 | } 2073 | public static demo.CustomerProtos.Organization parseFrom( 2074 | byte[] data, 2075 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 2076 | throws com.google.protobuf.InvalidProtocolBufferException { 2077 | return PARSER.parseFrom(data, extensionRegistry); 2078 | } 2079 | public static demo.CustomerProtos.Organization parseFrom(java.io.InputStream input) 2080 | throws java.io.IOException { 2081 | return PARSER.parseFrom(input); 2082 | } 2083 | public static demo.CustomerProtos.Organization parseFrom( 2084 | java.io.InputStream input, 2085 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 2086 | throws java.io.IOException { 2087 | return PARSER.parseFrom(input, extensionRegistry); 2088 | } 2089 | public static demo.CustomerProtos.Organization parseDelimitedFrom(java.io.InputStream input) 2090 | throws java.io.IOException { 2091 | return PARSER.parseDelimitedFrom(input); 2092 | } 2093 | public static demo.CustomerProtos.Organization parseDelimitedFrom( 2094 | java.io.InputStream input, 2095 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 2096 | throws java.io.IOException { 2097 | return PARSER.parseDelimitedFrom(input, extensionRegistry); 2098 | } 2099 | public static demo.CustomerProtos.Organization parseFrom( 2100 | com.google.protobuf.CodedInputStream input) 2101 | throws java.io.IOException { 2102 | return PARSER.parseFrom(input); 2103 | } 2104 | public static demo.CustomerProtos.Organization parseFrom( 2105 | com.google.protobuf.CodedInputStream input, 2106 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 2107 | throws java.io.IOException { 2108 | return PARSER.parseFrom(input, extensionRegistry); 2109 | } 2110 | 2111 | public static Builder newBuilder() { return Builder.create(); } 2112 | public Builder newBuilderForType() { return newBuilder(); } 2113 | public static Builder newBuilder(demo.CustomerProtos.Organization prototype) { 2114 | return newBuilder().mergeFrom(prototype); 2115 | } 2116 | public Builder toBuilder() { return newBuilder(this); } 2117 | 2118 | @java.lang.Override 2119 | protected Builder newBuilderForType( 2120 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 2121 | Builder builder = new Builder(parent); 2122 | return builder; 2123 | } 2124 | /** 2125 | * Protobuf type {@code demo.Organization} 2126 | */ 2127 | public static final class Builder extends 2128 | com.google.protobuf.GeneratedMessage.Builder 2129 | implements demo.CustomerProtos.OrganizationOrBuilder { 2130 | public static final com.google.protobuf.Descriptors.Descriptor 2131 | getDescriptor() { 2132 | return demo.CustomerProtos.internal_static_demo_Organization_descriptor; 2133 | } 2134 | 2135 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable 2136 | internalGetFieldAccessorTable() { 2137 | return demo.CustomerProtos.internal_static_demo_Organization_fieldAccessorTable 2138 | .ensureFieldAccessorsInitialized( 2139 | demo.CustomerProtos.Organization.class, demo.CustomerProtos.Organization.Builder.class); 2140 | } 2141 | 2142 | // Construct using demo.CustomerProtos.Organization.newBuilder() 2143 | private Builder() { 2144 | maybeForceBuilderInitialization(); 2145 | } 2146 | 2147 | private Builder( 2148 | com.google.protobuf.GeneratedMessage.BuilderParent parent) { 2149 | super(parent); 2150 | maybeForceBuilderInitialization(); 2151 | } 2152 | private void maybeForceBuilderInitialization() { 2153 | if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { 2154 | getCustomerFieldBuilder(); 2155 | } 2156 | } 2157 | private static Builder create() { 2158 | return new Builder(); 2159 | } 2160 | 2161 | public Builder clear() { 2162 | super.clear(); 2163 | name_ = ""; 2164 | bitField0_ = (bitField0_ & ~0x00000001); 2165 | if (customerBuilder_ == null) { 2166 | customer_ = java.util.Collections.emptyList(); 2167 | bitField0_ = (bitField0_ & ~0x00000002); 2168 | } else { 2169 | customerBuilder_.clear(); 2170 | } 2171 | return this; 2172 | } 2173 | 2174 | public Builder clone() { 2175 | return create().mergeFrom(buildPartial()); 2176 | } 2177 | 2178 | public com.google.protobuf.Descriptors.Descriptor 2179 | getDescriptorForType() { 2180 | return demo.CustomerProtos.internal_static_demo_Organization_descriptor; 2181 | } 2182 | 2183 | public demo.CustomerProtos.Organization getDefaultInstanceForType() { 2184 | return demo.CustomerProtos.Organization.getDefaultInstance(); 2185 | } 2186 | 2187 | public demo.CustomerProtos.Organization build() { 2188 | demo.CustomerProtos.Organization result = buildPartial(); 2189 | if (!result.isInitialized()) { 2190 | throw newUninitializedMessageException(result); 2191 | } 2192 | return result; 2193 | } 2194 | 2195 | public demo.CustomerProtos.Organization buildPartial() { 2196 | demo.CustomerProtos.Organization result = new demo.CustomerProtos.Organization(this); 2197 | int from_bitField0_ = bitField0_; 2198 | int to_bitField0_ = 0; 2199 | if (((from_bitField0_ & 0x00000001) == 0x00000001)) { 2200 | to_bitField0_ |= 0x00000001; 2201 | } 2202 | result.name_ = name_; 2203 | if (customerBuilder_ == null) { 2204 | if (((bitField0_ & 0x00000002) == 0x00000002)) { 2205 | customer_ = java.util.Collections.unmodifiableList(customer_); 2206 | bitField0_ = (bitField0_ & ~0x00000002); 2207 | } 2208 | result.customer_ = customer_; 2209 | } else { 2210 | result.customer_ = customerBuilder_.build(); 2211 | } 2212 | result.bitField0_ = to_bitField0_; 2213 | onBuilt(); 2214 | return result; 2215 | } 2216 | 2217 | public Builder mergeFrom(com.google.protobuf.Message other) { 2218 | if (other instanceof demo.CustomerProtos.Organization) { 2219 | return mergeFrom((demo.CustomerProtos.Organization)other); 2220 | } else { 2221 | super.mergeFrom(other); 2222 | return this; 2223 | } 2224 | } 2225 | 2226 | public Builder mergeFrom(demo.CustomerProtos.Organization other) { 2227 | if (other == demo.CustomerProtos.Organization.getDefaultInstance()) return this; 2228 | if (other.hasName()) { 2229 | bitField0_ |= 0x00000001; 2230 | name_ = other.name_; 2231 | onChanged(); 2232 | } 2233 | if (customerBuilder_ == null) { 2234 | if (!other.customer_.isEmpty()) { 2235 | if (customer_.isEmpty()) { 2236 | customer_ = other.customer_; 2237 | bitField0_ = (bitField0_ & ~0x00000002); 2238 | } else { 2239 | ensureCustomerIsMutable(); 2240 | customer_.addAll(other.customer_); 2241 | } 2242 | onChanged(); 2243 | } 2244 | } else { 2245 | if (!other.customer_.isEmpty()) { 2246 | if (customerBuilder_.isEmpty()) { 2247 | customerBuilder_.dispose(); 2248 | customerBuilder_ = null; 2249 | customer_ = other.customer_; 2250 | bitField0_ = (bitField0_ & ~0x00000002); 2251 | customerBuilder_ = 2252 | com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? 2253 | getCustomerFieldBuilder() : null; 2254 | } else { 2255 | customerBuilder_.addAllMessages(other.customer_); 2256 | } 2257 | } 2258 | } 2259 | this.mergeUnknownFields(other.getUnknownFields()); 2260 | return this; 2261 | } 2262 | 2263 | public final boolean isInitialized() { 2264 | if (!hasName()) { 2265 | 2266 | return false; 2267 | } 2268 | for (int i = 0; i < getCustomerCount(); i++) { 2269 | if (!getCustomer(i).isInitialized()) { 2270 | 2271 | return false; 2272 | } 2273 | } 2274 | return true; 2275 | } 2276 | 2277 | public Builder mergeFrom( 2278 | com.google.protobuf.CodedInputStream input, 2279 | com.google.protobuf.ExtensionRegistryLite extensionRegistry) 2280 | throws java.io.IOException { 2281 | demo.CustomerProtos.Organization parsedMessage = null; 2282 | try { 2283 | parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); 2284 | } catch (com.google.protobuf.InvalidProtocolBufferException e) { 2285 | parsedMessage = (demo.CustomerProtos.Organization) e.getUnfinishedMessage(); 2286 | throw e; 2287 | } finally { 2288 | if (parsedMessage != null) { 2289 | mergeFrom(parsedMessage); 2290 | } 2291 | } 2292 | return this; 2293 | } 2294 | private int bitField0_; 2295 | 2296 | // required string name = 4; 2297 | private java.lang.Object name_ = ""; 2298 | /** 2299 | * required string name = 4; 2300 | */ 2301 | public boolean hasName() { 2302 | return ((bitField0_ & 0x00000001) == 0x00000001); 2303 | } 2304 | /** 2305 | * required string name = 4; 2306 | */ 2307 | public java.lang.String getName() { 2308 | java.lang.Object ref = name_; 2309 | if (!(ref instanceof java.lang.String)) { 2310 | java.lang.String s = ((com.google.protobuf.ByteString) ref) 2311 | .toStringUtf8(); 2312 | name_ = s; 2313 | return s; 2314 | } else { 2315 | return (java.lang.String) ref; 2316 | } 2317 | } 2318 | /** 2319 | * required string name = 4; 2320 | */ 2321 | public com.google.protobuf.ByteString 2322 | getNameBytes() { 2323 | java.lang.Object ref = name_; 2324 | if (ref instanceof String) { 2325 | com.google.protobuf.ByteString b = 2326 | com.google.protobuf.ByteString.copyFromUtf8( 2327 | (java.lang.String) ref); 2328 | name_ = b; 2329 | return b; 2330 | } else { 2331 | return (com.google.protobuf.ByteString) ref; 2332 | } 2333 | } 2334 | /** 2335 | * required string name = 4; 2336 | */ 2337 | public Builder setName( 2338 | java.lang.String value) { 2339 | if (value == null) { 2340 | throw new NullPointerException(); 2341 | } 2342 | bitField0_ |= 0x00000001; 2343 | name_ = value; 2344 | onChanged(); 2345 | return this; 2346 | } 2347 | /** 2348 | * required string name = 4; 2349 | */ 2350 | public Builder clearName() { 2351 | bitField0_ = (bitField0_ & ~0x00000001); 2352 | name_ = getDefaultInstance().getName(); 2353 | onChanged(); 2354 | return this; 2355 | } 2356 | /** 2357 | * required string name = 4; 2358 | */ 2359 | public Builder setNameBytes( 2360 | com.google.protobuf.ByteString value) { 2361 | if (value == null) { 2362 | throw new NullPointerException(); 2363 | } 2364 | bitField0_ |= 0x00000001; 2365 | name_ = value; 2366 | onChanged(); 2367 | return this; 2368 | } 2369 | 2370 | // repeated .demo.Customer customer = 1; 2371 | private java.util.List customer_ = 2372 | java.util.Collections.emptyList(); 2373 | private void ensureCustomerIsMutable() { 2374 | if (!((bitField0_ & 0x00000002) == 0x00000002)) { 2375 | customer_ = new java.util.ArrayList(customer_); 2376 | bitField0_ |= 0x00000002; 2377 | } 2378 | } 2379 | 2380 | private com.google.protobuf.RepeatedFieldBuilder< 2381 | demo.CustomerProtos.Customer, demo.CustomerProtos.Customer.Builder, demo.CustomerProtos.CustomerOrBuilder> customerBuilder_; 2382 | 2383 | /** 2384 | * repeated .demo.Customer customer = 1; 2385 | */ 2386 | public java.util.List getCustomerList() { 2387 | if (customerBuilder_ == null) { 2388 | return java.util.Collections.unmodifiableList(customer_); 2389 | } else { 2390 | return customerBuilder_.getMessageList(); 2391 | } 2392 | } 2393 | /** 2394 | * repeated .demo.Customer customer = 1; 2395 | */ 2396 | public int getCustomerCount() { 2397 | if (customerBuilder_ == null) { 2398 | return customer_.size(); 2399 | } else { 2400 | return customerBuilder_.getCount(); 2401 | } 2402 | } 2403 | /** 2404 | * repeated .demo.Customer customer = 1; 2405 | */ 2406 | public demo.CustomerProtos.Customer getCustomer(int index) { 2407 | if (customerBuilder_ == null) { 2408 | return customer_.get(index); 2409 | } else { 2410 | return customerBuilder_.getMessage(index); 2411 | } 2412 | } 2413 | /** 2414 | * repeated .demo.Customer customer = 1; 2415 | */ 2416 | public Builder setCustomer( 2417 | int index, demo.CustomerProtos.Customer value) { 2418 | if (customerBuilder_ == null) { 2419 | if (value == null) { 2420 | throw new NullPointerException(); 2421 | } 2422 | ensureCustomerIsMutable(); 2423 | customer_.set(index, value); 2424 | onChanged(); 2425 | } else { 2426 | customerBuilder_.setMessage(index, value); 2427 | } 2428 | return this; 2429 | } 2430 | /** 2431 | * repeated .demo.Customer customer = 1; 2432 | */ 2433 | public Builder setCustomer( 2434 | int index, demo.CustomerProtos.Customer.Builder builderForValue) { 2435 | if (customerBuilder_ == null) { 2436 | ensureCustomerIsMutable(); 2437 | customer_.set(index, builderForValue.build()); 2438 | onChanged(); 2439 | } else { 2440 | customerBuilder_.setMessage(index, builderForValue.build()); 2441 | } 2442 | return this; 2443 | } 2444 | /** 2445 | * repeated .demo.Customer customer = 1; 2446 | */ 2447 | public Builder addCustomer(demo.CustomerProtos.Customer value) { 2448 | if (customerBuilder_ == null) { 2449 | if (value == null) { 2450 | throw new NullPointerException(); 2451 | } 2452 | ensureCustomerIsMutable(); 2453 | customer_.add(value); 2454 | onChanged(); 2455 | } else { 2456 | customerBuilder_.addMessage(value); 2457 | } 2458 | return this; 2459 | } 2460 | /** 2461 | * repeated .demo.Customer customer = 1; 2462 | */ 2463 | public Builder addCustomer( 2464 | int index, demo.CustomerProtos.Customer value) { 2465 | if (customerBuilder_ == null) { 2466 | if (value == null) { 2467 | throw new NullPointerException(); 2468 | } 2469 | ensureCustomerIsMutable(); 2470 | customer_.add(index, value); 2471 | onChanged(); 2472 | } else { 2473 | customerBuilder_.addMessage(index, value); 2474 | } 2475 | return this; 2476 | } 2477 | /** 2478 | * repeated .demo.Customer customer = 1; 2479 | */ 2480 | public Builder addCustomer( 2481 | demo.CustomerProtos.Customer.Builder builderForValue) { 2482 | if (customerBuilder_ == null) { 2483 | ensureCustomerIsMutable(); 2484 | customer_.add(builderForValue.build()); 2485 | onChanged(); 2486 | } else { 2487 | customerBuilder_.addMessage(builderForValue.build()); 2488 | } 2489 | return this; 2490 | } 2491 | /** 2492 | * repeated .demo.Customer customer = 1; 2493 | */ 2494 | public Builder addCustomer( 2495 | int index, demo.CustomerProtos.Customer.Builder builderForValue) { 2496 | if (customerBuilder_ == null) { 2497 | ensureCustomerIsMutable(); 2498 | customer_.add(index, builderForValue.build()); 2499 | onChanged(); 2500 | } else { 2501 | customerBuilder_.addMessage(index, builderForValue.build()); 2502 | } 2503 | return this; 2504 | } 2505 | /** 2506 | * repeated .demo.Customer customer = 1; 2507 | */ 2508 | public Builder addAllCustomer( 2509 | java.lang.Iterable values) { 2510 | if (customerBuilder_ == null) { 2511 | ensureCustomerIsMutable(); 2512 | super.addAll(values, customer_); 2513 | onChanged(); 2514 | } else { 2515 | customerBuilder_.addAllMessages(values); 2516 | } 2517 | return this; 2518 | } 2519 | /** 2520 | * repeated .demo.Customer customer = 1; 2521 | */ 2522 | public Builder clearCustomer() { 2523 | if (customerBuilder_ == null) { 2524 | customer_ = java.util.Collections.emptyList(); 2525 | bitField0_ = (bitField0_ & ~0x00000002); 2526 | onChanged(); 2527 | } else { 2528 | customerBuilder_.clear(); 2529 | } 2530 | return this; 2531 | } 2532 | /** 2533 | * repeated .demo.Customer customer = 1; 2534 | */ 2535 | public Builder removeCustomer(int index) { 2536 | if (customerBuilder_ == null) { 2537 | ensureCustomerIsMutable(); 2538 | customer_.remove(index); 2539 | onChanged(); 2540 | } else { 2541 | customerBuilder_.remove(index); 2542 | } 2543 | return this; 2544 | } 2545 | /** 2546 | * repeated .demo.Customer customer = 1; 2547 | */ 2548 | public demo.CustomerProtos.Customer.Builder getCustomerBuilder( 2549 | int index) { 2550 | return getCustomerFieldBuilder().getBuilder(index); 2551 | } 2552 | /** 2553 | * repeated .demo.Customer customer = 1; 2554 | */ 2555 | public demo.CustomerProtos.CustomerOrBuilder getCustomerOrBuilder( 2556 | int index) { 2557 | if (customerBuilder_ == null) { 2558 | return customer_.get(index); } else { 2559 | return customerBuilder_.getMessageOrBuilder(index); 2560 | } 2561 | } 2562 | /** 2563 | * repeated .demo.Customer customer = 1; 2564 | */ 2565 | public java.util.List 2566 | getCustomerOrBuilderList() { 2567 | if (customerBuilder_ != null) { 2568 | return customerBuilder_.getMessageOrBuilderList(); 2569 | } else { 2570 | return java.util.Collections.unmodifiableList(customer_); 2571 | } 2572 | } 2573 | /** 2574 | * repeated .demo.Customer customer = 1; 2575 | */ 2576 | public demo.CustomerProtos.Customer.Builder addCustomerBuilder() { 2577 | return getCustomerFieldBuilder().addBuilder( 2578 | demo.CustomerProtos.Customer.getDefaultInstance()); 2579 | } 2580 | /** 2581 | * repeated .demo.Customer customer = 1; 2582 | */ 2583 | public demo.CustomerProtos.Customer.Builder addCustomerBuilder( 2584 | int index) { 2585 | return getCustomerFieldBuilder().addBuilder( 2586 | index, demo.CustomerProtos.Customer.getDefaultInstance()); 2587 | } 2588 | /** 2589 | * repeated .demo.Customer customer = 1; 2590 | */ 2591 | public java.util.List 2592 | getCustomerBuilderList() { 2593 | return getCustomerFieldBuilder().getBuilderList(); 2594 | } 2595 | private com.google.protobuf.RepeatedFieldBuilder< 2596 | demo.CustomerProtos.Customer, demo.CustomerProtos.Customer.Builder, demo.CustomerProtos.CustomerOrBuilder> 2597 | getCustomerFieldBuilder() { 2598 | if (customerBuilder_ == null) { 2599 | customerBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< 2600 | demo.CustomerProtos.Customer, demo.CustomerProtos.Customer.Builder, demo.CustomerProtos.CustomerOrBuilder>( 2601 | customer_, 2602 | ((bitField0_ & 0x00000002) == 0x00000002), 2603 | getParentForChildren(), 2604 | isClean()); 2605 | customer_ = null; 2606 | } 2607 | return customerBuilder_; 2608 | } 2609 | 2610 | // @@protoc_insertion_point(builder_scope:demo.Organization) 2611 | } 2612 | 2613 | static { 2614 | defaultInstance = new Organization(true); 2615 | defaultInstance.initFields(); 2616 | } 2617 | 2618 | // @@protoc_insertion_point(class_scope:demo.Organization) 2619 | } 2620 | 2621 | private static com.google.protobuf.Descriptors.Descriptor 2622 | internal_static_demo_Customer_descriptor; 2623 | private static 2624 | com.google.protobuf.GeneratedMessage.FieldAccessorTable 2625 | internal_static_demo_Customer_fieldAccessorTable; 2626 | private static com.google.protobuf.Descriptors.Descriptor 2627 | internal_static_demo_Customer_EmailAddress_descriptor; 2628 | private static 2629 | com.google.protobuf.GeneratedMessage.FieldAccessorTable 2630 | internal_static_demo_Customer_EmailAddress_fieldAccessorTable; 2631 | private static com.google.protobuf.Descriptors.Descriptor 2632 | internal_static_demo_Organization_descriptor; 2633 | private static 2634 | com.google.protobuf.GeneratedMessage.FieldAccessorTable 2635 | internal_static_demo_Organization_fieldAccessorTable; 2636 | 2637 | public static com.google.protobuf.Descriptors.FileDescriptor 2638 | getDescriptor() { 2639 | return descriptor; 2640 | } 2641 | private static com.google.protobuf.Descriptors.FileDescriptor 2642 | descriptor; 2643 | static { 2644 | java.lang.String[] descriptorData = { 2645 | "\n\016customer.proto\022\004demo\"\350\001\n\010Customer\022\n\n\002i" + 2646 | "d\030\001 \002(\005\022\021\n\tfirstName\030\002 \002(\t\022\020\n\010lastName\030\003" + 2647 | " \002(\t\022*\n\005email\030\005 \003(\0132\033.demo.Customer.Emai" + 2648 | "lAddress\032S\n\014EmailAddress\022\r\n\005email\030\001 \002(\t\022" + 2649 | "4\n\004type\030\002 \001(\0162\030.demo.Customer.EmailType:" + 2650 | "\014PROFESSIONAL\"*\n\tEmailType\022\013\n\007PRIVATE\020\000\022" + 2651 | "\020\n\014PROFESSIONAL\020\001\">\n\014Organization\022\014\n\004nam" + 2652 | "e\030\004 \002(\t\022 \n\010customer\030\001 \003(\0132\016.demo.Custome" + 2653 | "rB\026\n\004demoB\016CustomerProtos" 2654 | }; 2655 | com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = 2656 | new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { 2657 | public com.google.protobuf.ExtensionRegistry assignDescriptors( 2658 | com.google.protobuf.Descriptors.FileDescriptor root) { 2659 | descriptor = root; 2660 | internal_static_demo_Customer_descriptor = 2661 | getDescriptor().getMessageTypes().get(0); 2662 | internal_static_demo_Customer_fieldAccessorTable = new 2663 | com.google.protobuf.GeneratedMessage.FieldAccessorTable( 2664 | internal_static_demo_Customer_descriptor, 2665 | new java.lang.String[] { "Id", "FirstName", "LastName", "Email", }); 2666 | internal_static_demo_Customer_EmailAddress_descriptor = 2667 | internal_static_demo_Customer_descriptor.getNestedTypes().get(0); 2668 | internal_static_demo_Customer_EmailAddress_fieldAccessorTable = new 2669 | com.google.protobuf.GeneratedMessage.FieldAccessorTable( 2670 | internal_static_demo_Customer_EmailAddress_descriptor, 2671 | new java.lang.String[] { "Email", "Type", }); 2672 | internal_static_demo_Organization_descriptor = 2673 | getDescriptor().getMessageTypes().get(1); 2674 | internal_static_demo_Organization_fieldAccessorTable = new 2675 | com.google.protobuf.GeneratedMessage.FieldAccessorTable( 2676 | internal_static_demo_Organization_descriptor, 2677 | new java.lang.String[] { "Name", "Customer", }); 2678 | return null; 2679 | } 2680 | }; 2681 | com.google.protobuf.Descriptors.FileDescriptor 2682 | .internalBuildGeneratedFileFrom(descriptorData, 2683 | new com.google.protobuf.Descriptors.FileDescriptor[] { 2684 | }, assigner); 2685 | } 2686 | 2687 | // @@protoc_insertion_point(outer_class_scope) 2688 | } 2689 | -------------------------------------------------------------------------------- /src/main/java/demo/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.util.Arrays; 13 | import java.util.Collection; 14 | import java.util.Map; 15 | import java.util.concurrent.ConcurrentHashMap; 16 | import java.util.stream.Collectors; 17 | 18 | /** 19 | * This example demonstrates serving up REST payloads encoded using 20 | * Google Protocol Buffers. 21 | */ 22 | @SpringBootApplication 23 | public class DemoApplication { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(DemoApplication.class, args); 27 | } 28 | 29 | @Bean 30 | ProtobufHttpMessageConverter protobufHttpMessageConverter() { 31 | return new ProtobufHttpMessageConverter(); 32 | } 33 | 34 | private CustomerProtos.Customer customer(int id, String f, String l, Collection emails) { 35 | Collection emailAddresses = 36 | emails.stream().map(e -> CustomerProtos.Customer.EmailAddress.newBuilder() 37 | .setType(CustomerProtos.Customer.EmailType.PROFESSIONAL) 38 | .setEmail(e).build()) 39 | .collect(Collectors.toList()); 40 | 41 | return CustomerProtos.Customer.newBuilder() 42 | .setFirstName(f) 43 | .setLastName(l) 44 | .setId(id) 45 | .addAllEmail(emailAddresses) 46 | .build(); 47 | } 48 | 49 | @Bean 50 | CustomerRepository customerRepository() { 51 | Map customers = new ConcurrentHashMap<>(); 52 | // populate with some dummy data 53 | Arrays.asList( 54 | customer(1, "Chris", "Richardson", Arrays.asList("crichardson@email.com")), 55 | customer(2, "Josh", "Long", Arrays.asList("jlong@email.com")), 56 | customer(3, "Matt", "Stine", Arrays.asList("mstine@email.com")), 57 | customer(4, "Russ", "Miles", Arrays.asList("rmiles@email.com")) 58 | ).forEach(c -> customers.put(c.getId(), c)); 59 | 60 | // our lambda just gets forwarded to Map#get(Integer) 61 | return customers::get; 62 | } 63 | 64 | } 65 | 66 | interface CustomerRepository { 67 | CustomerProtos.Customer findById(int id); 68 | } 69 | 70 | 71 | @RestController 72 | class CustomerRestController { 73 | 74 | @Autowired 75 | private CustomerRepository customerRepository; 76 | 77 | @RequestMapping("/customers/{id}") 78 | CustomerProtos.Customer customer(@PathVariable Integer id) { 79 | return this.customerRepository.findById(id); 80 | } 81 | } -------------------------------------------------------------------------------- /src/main/python/client.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import urllib 4 | import customer_pb2 5 | 6 | if __name__ == '__main__': 7 | customer = customer_pb2.Customer() 8 | customers_read = urllib.urlopen('http://localhost:8080/customers/1').read() 9 | customer.ParseFromString(customers_read) 10 | print customer 11 | -------------------------------------------------------------------------------- /src/main/python/customer_pb2.py: -------------------------------------------------------------------------------- 1 | # Generated by the protocol buffer compiler. DO NOT EDIT! 2 | # source: customer.proto 3 | 4 | from google.protobuf import descriptor as _descriptor 5 | from google.protobuf import message as _message 6 | from google.protobuf import reflection as _reflection 7 | from google.protobuf import descriptor_pb2 8 | # @@protoc_insertion_point(imports) 9 | 10 | 11 | 12 | 13 | DESCRIPTOR = _descriptor.FileDescriptor( 14 | name='customer.proto', 15 | package='demo', 16 | serialized_pb='\n\x0e\x63ustomer.proto\x12\x04\x64\x65mo\"\xe8\x01\n\x08\x43ustomer\x12\n\n\x02id\x18\x01 \x02(\x05\x12\x11\n\tfirstName\x18\x02 \x02(\t\x12\x10\n\x08lastName\x18\x03 \x02(\t\x12*\n\x05\x65mail\x18\x05 \x03(\x0b\x32\x1b.demo.Customer.EmailAddress\x1aS\n\x0c\x45mailAddress\x12\r\n\x05\x65mail\x18\x01 \x02(\t\x12\x34\n\x04type\x18\x02 \x01(\x0e\x32\x18.demo.Customer.EmailType:\x0cPROFESSIONAL\"*\n\tEmailType\x12\x0b\n\x07PRIVATE\x10\x00\x12\x10\n\x0cPROFESSIONAL\x10\x01\">\n\x0cOrganization\x12\x0c\n\x04name\x18\x04 \x02(\t\x12 \n\x08\x63ustomer\x18\x01 \x03(\x0b\x32\x0e.demo.CustomerB\x16\n\x04\x64\x65moB\x0e\x43ustomerProtos') 17 | 18 | 19 | 20 | _CUSTOMER_EMAILTYPE = _descriptor.EnumDescriptor( 21 | name='EmailType', 22 | full_name='demo.Customer.EmailType', 23 | filename=None, 24 | file=DESCRIPTOR, 25 | values=[ 26 | _descriptor.EnumValueDescriptor( 27 | name='PRIVATE', index=0, number=0, 28 | options=None, 29 | type=None), 30 | _descriptor.EnumValueDescriptor( 31 | name='PROFESSIONAL', index=1, number=1, 32 | options=None, 33 | type=None), 34 | ], 35 | containing_type=None, 36 | options=None, 37 | serialized_start=215, 38 | serialized_end=257, 39 | ) 40 | 41 | 42 | _CUSTOMER_EMAILADDRESS = _descriptor.Descriptor( 43 | name='EmailAddress', 44 | full_name='demo.Customer.EmailAddress', 45 | filename=None, 46 | file=DESCRIPTOR, 47 | containing_type=None, 48 | fields=[ 49 | _descriptor.FieldDescriptor( 50 | name='email', full_name='demo.Customer.EmailAddress.email', index=0, 51 | number=1, type=9, cpp_type=9, label=2, 52 | has_default_value=False, default_value=unicode("", "utf-8"), 53 | message_type=None, enum_type=None, containing_type=None, 54 | is_extension=False, extension_scope=None, 55 | options=None), 56 | _descriptor.FieldDescriptor( 57 | name='type', full_name='demo.Customer.EmailAddress.type', index=1, 58 | number=2, type=14, cpp_type=8, label=1, 59 | has_default_value=True, default_value=1, 60 | message_type=None, enum_type=None, containing_type=None, 61 | is_extension=False, extension_scope=None, 62 | options=None), 63 | ], 64 | extensions=[ 65 | ], 66 | nested_types=[], 67 | enum_types=[ 68 | ], 69 | options=None, 70 | is_extendable=False, 71 | extension_ranges=[], 72 | serialized_start=130, 73 | serialized_end=213, 74 | ) 75 | 76 | _CUSTOMER = _descriptor.Descriptor( 77 | name='Customer', 78 | full_name='demo.Customer', 79 | filename=None, 80 | file=DESCRIPTOR, 81 | containing_type=None, 82 | fields=[ 83 | _descriptor.FieldDescriptor( 84 | name='id', full_name='demo.Customer.id', index=0, 85 | number=1, type=5, cpp_type=1, label=2, 86 | has_default_value=False, default_value=0, 87 | message_type=None, enum_type=None, containing_type=None, 88 | is_extension=False, extension_scope=None, 89 | options=None), 90 | _descriptor.FieldDescriptor( 91 | name='firstName', full_name='demo.Customer.firstName', index=1, 92 | number=2, type=9, cpp_type=9, label=2, 93 | has_default_value=False, default_value=unicode("", "utf-8"), 94 | message_type=None, enum_type=None, containing_type=None, 95 | is_extension=False, extension_scope=None, 96 | options=None), 97 | _descriptor.FieldDescriptor( 98 | name='lastName', full_name='demo.Customer.lastName', index=2, 99 | number=3, type=9, cpp_type=9, label=2, 100 | has_default_value=False, default_value=unicode("", "utf-8"), 101 | message_type=None, enum_type=None, containing_type=None, 102 | is_extension=False, extension_scope=None, 103 | options=None), 104 | _descriptor.FieldDescriptor( 105 | name='email', full_name='demo.Customer.email', index=3, 106 | number=5, type=11, cpp_type=10, label=3, 107 | has_default_value=False, default_value=[], 108 | message_type=None, enum_type=None, containing_type=None, 109 | is_extension=False, extension_scope=None, 110 | options=None), 111 | ], 112 | extensions=[ 113 | ], 114 | nested_types=[_CUSTOMER_EMAILADDRESS, ], 115 | enum_types=[ 116 | _CUSTOMER_EMAILTYPE, 117 | ], 118 | options=None, 119 | is_extendable=False, 120 | extension_ranges=[], 121 | serialized_start=25, 122 | serialized_end=257, 123 | ) 124 | 125 | 126 | _ORGANIZATION = _descriptor.Descriptor( 127 | name='Organization', 128 | full_name='demo.Organization', 129 | filename=None, 130 | file=DESCRIPTOR, 131 | containing_type=None, 132 | fields=[ 133 | _descriptor.FieldDescriptor( 134 | name='name', full_name='demo.Organization.name', index=0, 135 | number=4, type=9, cpp_type=9, label=2, 136 | has_default_value=False, default_value=unicode("", "utf-8"), 137 | message_type=None, enum_type=None, containing_type=None, 138 | is_extension=False, extension_scope=None, 139 | options=None), 140 | _descriptor.FieldDescriptor( 141 | name='customer', full_name='demo.Organization.customer', index=1, 142 | number=1, type=11, cpp_type=10, label=3, 143 | has_default_value=False, default_value=[], 144 | message_type=None, enum_type=None, containing_type=None, 145 | is_extension=False, extension_scope=None, 146 | options=None), 147 | ], 148 | extensions=[ 149 | ], 150 | nested_types=[], 151 | enum_types=[ 152 | ], 153 | options=None, 154 | is_extendable=False, 155 | extension_ranges=[], 156 | serialized_start=259, 157 | serialized_end=321, 158 | ) 159 | 160 | _CUSTOMER_EMAILADDRESS.fields_by_name['type'].enum_type = _CUSTOMER_EMAILTYPE 161 | _CUSTOMER_EMAILADDRESS.containing_type = _CUSTOMER; 162 | _CUSTOMER.fields_by_name['email'].message_type = _CUSTOMER_EMAILADDRESS 163 | _CUSTOMER_EMAILTYPE.containing_type = _CUSTOMER; 164 | _ORGANIZATION.fields_by_name['customer'].message_type = _CUSTOMER 165 | DESCRIPTOR.message_types_by_name['Customer'] = _CUSTOMER 166 | DESCRIPTOR.message_types_by_name['Organization'] = _ORGANIZATION 167 | 168 | class Customer(_message.Message): 169 | __metaclass__ = _reflection.GeneratedProtocolMessageType 170 | 171 | class EmailAddress(_message.Message): 172 | __metaclass__ = _reflection.GeneratedProtocolMessageType 173 | DESCRIPTOR = _CUSTOMER_EMAILADDRESS 174 | 175 | # @@protoc_insertion_point(class_scope:demo.Customer.EmailAddress) 176 | DESCRIPTOR = _CUSTOMER 177 | 178 | # @@protoc_insertion_point(class_scope:demo.Customer) 179 | 180 | class Organization(_message.Message): 181 | __metaclass__ = _reflection.GeneratedProtocolMessageType 182 | DESCRIPTOR = _ORGANIZATION 183 | 184 | # @@protoc_insertion_point(class_scope:demo.Organization) 185 | 186 | 187 | DESCRIPTOR.has_options = True 188 | DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), '\n\004demoB\016CustomerProtos') 189 | # @@protoc_insertion_point(module_scope) 190 | -------------------------------------------------------------------------------- /src/main/python/customer_pb2.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshlong-attic/spring-and-google-protocol-buffers/f2cda13ada75d21a2d18722b38fab1950e62d789/src/main/python/customer_pb2.pyc -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joshlong-attic/spring-and-google-protocol-buffers/f2cda13ada75d21a2d18722b38fab1950e62d789/src/main/resources/application.properties -------------------------------------------------------------------------------- /src/main/ruby/client.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | require './customer.pb' 4 | require 'net/http' 5 | require 'uri' 6 | 7 | uri = URI.parse('http://localhost:8080/customers/3') 8 | body = Net::HTTP.get(uri) 9 | puts Demo::Customer.parse(body) -------------------------------------------------------------------------------- /src/main/ruby/customer.pb.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # Generated by the protocol buffer compiler. DO NOT EDIT! 3 | 4 | require 'protocol_buffers' 5 | 6 | module Demo 7 | # forward declarations 8 | class Customer < ::ProtocolBuffers::Message; end 9 | class Organization < ::ProtocolBuffers::Message; end 10 | 11 | class Customer < ::ProtocolBuffers::Message 12 | # forward declarations 13 | class EmailAddress < ::ProtocolBuffers::Message; end 14 | 15 | # enums 16 | module EmailType 17 | include ::ProtocolBuffers::Enum 18 | 19 | set_fully_qualified_name "demo.Customer.EmailType" 20 | 21 | PRIVATE = 0 22 | PROFESSIONAL = 1 23 | end 24 | 25 | set_fully_qualified_name "demo.Customer" 26 | 27 | # nested messages 28 | class EmailAddress < ::ProtocolBuffers::Message 29 | set_fully_qualified_name "demo.Customer.EmailAddress" 30 | 31 | required :string, :email, 1 32 | optional ::Demo::Customer::EmailType, :type, 2, :default => ::Demo::Customer::EmailType::PROFESSIONAL 33 | end 34 | 35 | required :int32, :id, 1 36 | required :string, :firstName, 2 37 | required :string, :lastName, 3 38 | repeated ::Demo::Customer::EmailAddress, :email, 5 39 | end 40 | 41 | class Organization < ::ProtocolBuffers::Message 42 | set_fully_qualified_name "demo.Organization" 43 | 44 | required :string, :name, 4 45 | repeated ::Demo::Customer, :customer, 1 46 | end 47 | 48 | end 49 | -------------------------------------------------------------------------------- /src/test/java/demo/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package demo; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.IntegrationTest; 7 | import org.springframework.boot.test.SpringApplicationConfiguration; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter; 12 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 13 | import org.springframework.test.context.web.WebAppConfiguration; 14 | import org.springframework.web.client.RestTemplate; 15 | 16 | import java.util.Arrays; 17 | 18 | @RunWith(SpringJUnit4ClassRunner.class) 19 | @SpringApplicationConfiguration(classes = DemoApplication.class) 20 | @WebAppConfiguration 21 | @IntegrationTest 22 | public class DemoApplicationTests { 23 | 24 | @Configuration 25 | public static class RestClientConfiguration { 26 | 27 | @Bean 28 | RestTemplate restTemplate(ProtobufHttpMessageConverter hmc) { 29 | return new RestTemplate(Arrays.asList(hmc)); 30 | } 31 | 32 | @Bean 33 | ProtobufHttpMessageConverter protobufHttpMessageConverter() { 34 | return new ProtobufHttpMessageConverter(); 35 | } 36 | } 37 | 38 | @Autowired 39 | private RestTemplate restTemplate; 40 | 41 | private int port = 8080; 42 | 43 | @Test 44 | public void contextLoaded() { 45 | 46 | ResponseEntity customer = restTemplate.getForEntity( 47 | "http://127.0.0.1:" + port + "/customers/2", CustomerProtos.Customer.class); 48 | 49 | System.out.println("customer retrieved: " + customer.toString()); 50 | 51 | } 52 | 53 | } 54 | --------------------------------------------------------------------------------