diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/Makefile b/proto/compiler/google/src/google/protobuf/compiler/kotlin/Makefile index c73425b371c..7998b70fe47 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/Makefile +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/Makefile @@ -5,6 +5,7 @@ LDFLAGS = -lprotoc -lprotobuf EXE = protoc SRCDIR = src BINDIR = bin +TESTDIR = test OBJECTS = $(patsubst $(SRCDIR)/%.cc,$(BINDIR)/%.o,$(wildcard $(SRCDIR)/*.cc)) @@ -25,10 +26,6 @@ clean: rm -rf $(BINDIR) $(EXE) generate: - ./protoc --kotlin_out=./ ./test/addressbook.proto + ./protoc --kotlin_out=$$HOME/Downloads/carkot/proto/compiler/src ./test/addressbook.proto + ./protoc --kotlin_out=$$HOME/Downloads/carkot/proto/compiler/src ./test/nested-msg.proto .PHONY: clean all generate - -low: dummy - -dummy: CXXFLAGS += -DKOTLIN_GENERATED_CODE_LANGUAGE_LEVEL_LOW -dummy: all \ No newline at end of file diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc index 1505621c582..0fb824de168 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.cc @@ -6,6 +6,7 @@ #include #include "kotlin_enum_generator.h" #include "kotlin_field_generator.h" +#include "kotlin_name_resolver.h" #include namespace google { @@ -14,6 +15,7 @@ namespace compiler { namespace kotlin { class FieldGenerator; // declared in "kotlin_file_generator.h" +class NameResolver; // declared in "kotlin_name_resolver.h" void ClassGenerator::generateCode(io::Printer *printer, bool isBuilder) const { generateHeader(printer, isBuilder); @@ -74,26 +76,29 @@ void ClassGenerator::generateCode(io::Printer *printer, bool isBuilder) const { printer->Print("}\n"); } -ClassGenerator::ClassGenerator(Descriptor const *descriptor) - : descriptor(descriptor) { +ClassGenerator::ClassGenerator(Descriptor const *descriptor, NameResolver * nameResolver) + : descriptor(descriptor) + , nameResolver(nameResolver) +{ simpleName = descriptor->name(); - builderName = "Builder" + simpleName; int field_count = descriptor->field_count(); for (int i = 0; i < field_count; ++i) { FieldDescriptor const * fieldDescriptor = descriptor->field(i); - properties.push_back(new FieldGenerator(fieldDescriptor, /* enclosingClass = */ this)); + properties.push_back(new FieldGenerator(fieldDescriptor, /* enclosingClass = */ this, nameResolver)); } int nested_types_count = descriptor->nested_type_count(); for (int i = 0; i < nested_types_count; ++i) { Descriptor const * nestedClassDescriptor = descriptor->nested_type(i); - classesDeclarations.push_back(new ClassGenerator(nestedClassDescriptor)); + nameResolver->addClass(nestedClassDescriptor->name(), nameResolver->getClassName(simpleName)); + classesDeclarations.push_back(new ClassGenerator(nestedClassDescriptor, nameResolver)); } int enums_declarations_count = descriptor->enum_type_count(); for (int i = 0; i < enums_declarations_count; ++i) { EnumDescriptor const * nestedEnumDescriptor = descriptor->enum_type(i); + nameResolver->addClass(nestedEnumDescriptor->name(), nameResolver->getClassName(simpleName)); enumsDeclaraions.push_back(new EnumGenerator(nestedEnumDescriptor)); } @@ -165,7 +170,7 @@ void ClassGenerator::generateMergeMethods(io::Printer *printer) const { printer->Print(vars, "fun mergeFrom (input: CodedInputStream) {\n"); printer->Indent(); - vars["builderName"] = builderName; + vars["builderName"] = nameResolver->getBuilderName(simpleName); printer->Print(vars, "val builder = $builderName$()\n"); printer->Print("mergeWith(builder.parseFrom(input).build())"); @@ -179,7 +184,7 @@ void ClassGenerator::generateSerializers(io::Printer *printer, bool isRead) cons vars["funName"]= isRead ? "readFrom" : "writeTo"; vars["stream"] = isRead ? "CodedInputStream" : "CodedOutputStream"; vars["arg"] = isRead ? "input" : "output"; - vars["returnType"] = isRead ? builderName : "Unit"; + vars["returnType"] = isRead ? nameResolver->getBuilderName(simpleName) : "Unit"; vars["maybeReturn"] = isRead ? "return this\n" : ""; // generate function header @@ -211,7 +216,7 @@ void ClassGenerator::generateHeader(io::Printer * printer, bool isBuilder) const } map vars; - vars["name"] = isBuilder? builderName : simpleName; + vars["name"] = isBuilder? "Builder" + simpleName : simpleName; vars["argumentList"] = argumentList; vars["maybePrivate"] = isBuilder? "" : " private"; printer->Print(vars, @@ -261,7 +266,7 @@ void ClassGenerator::generateInitSection(io::Printer * printer) const { void ClassGenerator::generateParseMethods(io::Printer *printer) const { // parseFieldFrom(input: CodedInputStream): Boolean map vars; - vars["builderName"] = builderName; + vars["builderName"] = nameResolver->getBuilderName(simpleName); printer->Print("fun parseFieldFrom(input: CodedInputStream): Boolean {\n"); printer->Indent(); diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.h b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.h index 62158289644..73ef7596150 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.h +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_class_generator.h @@ -10,6 +10,7 @@ #include #include "kotlin_field_generator.h" #include "kotlin_enum_generator.h" +#include "kotlin_name_resolver.h" namespace google { namespace protobuf { @@ -17,6 +18,7 @@ namespace compiler { namespace kotlin { class FieldGenerator; // declared in "kotlin_file_generator.h" +class NameResolver; // declared in "kotlin_name_resolver.h" // wrapper for enum CLASS/INTERFACE with convenience method of getting name class ClassModifier { @@ -35,17 +37,18 @@ public: class ClassGenerator { public: string simpleName; + string fullName; vector properties; vector classesDeclarations; vector enumsDeclaraions; - string builderName; - ClassGenerator (Descriptor const * descriptor); + ClassGenerator (Descriptor const * descriptor, NameResolver * nameResolver); ~ClassGenerator (); void generateCode (io::Printer * printer, bool isBuilder = false) const; private: Descriptor const * descriptor; + NameResolver * nameResolver; void generateBuilder (io::Printer * printer) const; void generateBuildMethod (io::Printer * printer) const; void generateInitSection (io::Printer * printer) const; diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.cc b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.cc index 948b130980d..e24cee2022e 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.cc +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.cc @@ -15,12 +15,7 @@ namespace compiler { namespace kotlin { string FieldGenerator::getInitValue() const { - if (descriptor->is_repeated()) - return "mutableListOf()"; - else if (protoType == FieldDescriptor::TYPE_MESSAGE) { - return enclosingClass->builderName + "().build()"; - } - return name_resolving::protobufTypeToInitValue(descriptor); + return name_resolving::protobufTypeToInitValue(this); } void FieldGenerator::generateCode(io::Printer *printer, bool isBuilder) const { @@ -45,7 +40,7 @@ void FieldGenerator::generateCode(io::Printer *printer, bool isBuilder) const { } } -FieldGenerator::FieldGenerator(FieldDescriptor const * descriptor, ClassGenerator const * enclosingClass) +FieldGenerator::FieldGenerator(FieldDescriptor const * descriptor, ClassGenerator const * enclosingClass, NameResolver * nameResolver) : descriptor(descriptor) , modifier(descriptor->label()) , enclosingClass(enclosingClass) @@ -54,6 +49,7 @@ FieldGenerator::FieldGenerator(FieldDescriptor const * descriptor, ClassGenerato , fullType(name_resolving::protobufToKotlinField(descriptor)) , protoType(descriptor->type()) , fieldNumber(descriptor->number()) + , nameResolver(nameResolver) { } // TODO: long, complicated and messy method. Refactor it ASAP @@ -94,7 +90,7 @@ void FieldGenerator::generateSerializationCode(io::Printer *printer, bool isRead removed as soon as target code will support inheritance and interfaces. (then writing CodedOutputStream.writeMessage will be possible). */ - FieldGenerator singleFieldGen = FieldGenerator(descriptor, enclosingClass); + FieldGenerator singleFieldGen = FieldGenerator(descriptor, enclosingClass, nameResolver); /* Another dirty hack here: create tmp variable of a given type and read it from input stream then add that tmp var into list. @@ -140,7 +136,7 @@ void FieldGenerator::generateSerializationCode(io::Printer *printer, bool isRead printer->Indent(); // hack: see above - FieldGenerator singleFieldGen = FieldGenerator(descriptor, enclosingClass); + FieldGenerator singleFieldGen = FieldGenerator(descriptor, enclosingClass, nameResolver); singleFieldGen.simpleName = "item"; singleFieldGen.modifier = FieldDescriptor::LABEL_OPTIONAL; @@ -200,7 +196,7 @@ void FieldGenerator::generateSerializationCode(io::Printer *printer, bool isRead // read message itself without tag printer->Print(vars, - "$fieldName$.readFrom(input)\n"); + "$fieldName$.mergeFrom(input)\n"); // check that actual size equal to expected size printer->Print(vars, "if (expectedSize != $fieldName$.getSize()) { " @@ -237,7 +233,7 @@ void FieldGenerator::generateSetter(io::Printer *printer) const { map vars; vars["camelCaseName"] = name_resolving::makeFirstLetterUpper(simpleName); vars["fieldName"] = simpleName; - vars["builderName"] = enclosingClass->builderName; + vars["builderName"] = nameResolver->getBuilderName(enclosingClass->simpleName); vars["type"] = fullType; printer->Print(vars, "fun set$camelCaseName$(value: $type$): $builderName$ {\n"); @@ -254,7 +250,7 @@ void FieldGenerator::generateRepeatedMethods(io::Printer * printer, bool isBuild vars["elementType"] = underlyingType; vars["arg"] = "value"; vars["fieldName"] = simpleName; - vars["builderName"] = enclosingClass->builderName; + vars["builderName"] = nameResolver->getBuilderName(underlyingType); // TODO: call to non-existent field in map. // generate indexed setter for builders if (isBuilder) { @@ -300,7 +296,7 @@ string FieldGenerator::getUnderlyingTypeInitValue() const { if (protoType == FieldDescriptor::TYPE_MESSAGE) { return "Builder" + underlyingType + "().build()"; } - return name_resolving::protobufTypeToInitValue(descriptor); + return name_resolving::protobufTypeToInitValue(this); } void FieldGenerator::generateSizeEstimationCode(io::Printer *printer, string varName, bool noTag) const { @@ -325,7 +321,7 @@ void FieldGenerator::generateSizeEstimationCode(io::Printer *printer, string var printer->Indent(); // hack: reuse generateSizeEstimationCode in the same manner as in generateSerializationCode - FieldGenerator singleFieldGen = FieldGenerator(descriptor, enclosingClass); + FieldGenerator singleFieldGen = FieldGenerator(descriptor, enclosingClass, nameResolver); singleFieldGen.modifier = FieldDescriptor::LABEL_OPTIONAL; singleFieldGen.simpleName = "item"; singleFieldGen.generateSizeEstimationCode(printer, "arraySize"); diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.h b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.h index 05a5e293762..cd721189ebd 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.h +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_field_generator.h @@ -9,6 +9,7 @@ #include #include #include "kotlin_class_generator.h" +#include "kotlin_name_resolver.h" namespace google { namespace protobuf { @@ -16,11 +17,11 @@ namespace compiler { namespace kotlin { class ClassGenerator; // declared in kotlin_class_generator.h +class NameResolver; // declared in kotlin_name_resolver.h class FieldGenerator { private: FieldDescriptor const * descriptor; - // TODO: refactor from field generator to some static utility namespace void generateSetter(io::Printer * printer) const; @@ -38,15 +39,18 @@ public: * fullType = underlyingType for all other cases */ string fullType; + string builderName; + string fullName; string getInitValue() const; string getUnderlyingTypeInitValue() const; FieldDescriptor::Type protoType; int fieldNumber; + NameResolver * nameResolver; void generateCode(io::Printer * printer, bool isBuilder) const; void generateSerializationCode(io::Printer * printer, bool isRead = false, bool noTag = false) const; void generateSizeEstimationCode(io::Printer * printer, string varName, bool noTag = false) const; - FieldGenerator(FieldDescriptor const * descriptor, ClassGenerator const * enclosingClass); + FieldGenerator(FieldDescriptor const * descriptor, ClassGenerator const * enclosingClass, NameResolver * nameResolver); string getKotlinFunctionSuffix() const; }; diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_file_generator.cc b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_file_generator.cc index ee36d46f73d..9ef67a067e7 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_file_generator.cc +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_file_generator.cc @@ -30,20 +30,26 @@ bool FileGenerator::Generate(const FileDescriptor *file, const string ¶meter string const file_name = name_resolving::getKotlinOutputByProtoName(file->name()); google::protobuf::scoped_ptr output(context->Open(file_name)); io::Printer printer(output.get(), '$', /* annotation_collector = */ NULL); + NameResolver * nameResolver = new NameResolver(); // Create Generators for all top-level messages int topLevelMessagesCount = file->message_type_count(); for (int i = 0; i < topLevelMessagesCount; ++i) { Descriptor const * descriptor = file->message_type(i); - ClassGenerator * cgen = new ClassGenerator(descriptor); + // TODO: think about order of initialization and cross-branches calls. If we don't allow such things, everythign is ok atm + nameResolver->addClass(descriptor->name(), ""); + ClassGenerator * cgen = new ClassGenerator(descriptor, nameResolver); classes.push_back(cgen); } // Generate code and clean up generateCode(&printer, classes); + for (int i = 0; i < classes.size(); ++i) { delete classes[i]; } + delete nameResolver; + return true; } diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_name_resolver.cc b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_name_resolver.cc index e799519121f..6ab33327387 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_name_resolver.cc +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_name_resolver.cc @@ -3,6 +3,7 @@ // #include "kotlin_name_resolver.h" +#include "kotlin_field_generator.h" #include #include @@ -27,7 +28,8 @@ string getFileNameWithoutExtension(string fullName) { } string getKotlinOutputByProtoName(string protoName) { - string justName = getFileNameWithoutExtension(protoName); + string fileWithoutPath = protoName.substr(protoName.find_last_of("/") + 1, protoName.length()); + string justName = getFileNameWithoutExtension(fileWithoutPath); return justName + ".kt"; } @@ -91,8 +93,12 @@ string protobufToKotlinField(FieldDescriptor const * descriptor) { } // TODO: think about nested arrays -string protobufTypeToInitValue(FieldDescriptor const * descriptor) { - FieldDescriptor::Type type = descriptor->type(); +string protobufTypeToInitValue(FieldGenerator const * fieldGen) { + if (fieldGen->modifier == FieldDescriptor::LABEL_REPEATED) { + return "mutableListOf()"; + } + + FieldDescriptor::Type type = fieldGen->protoType; switch(type) { case FieldDescriptor::TYPE_BOOL: return "false"; @@ -101,8 +107,7 @@ string protobufTypeToInitValue(FieldDescriptor const * descriptor) { case FieldDescriptor::TYPE_DOUBLE: return "0.0"; case FieldDescriptor::TYPE_ENUM: { - string enumType = descriptor->enum_type()->name(); - return enumType + ".fromIntTo" + enumType + "(0)"; // produce enum from 0, as demanded by Google + return fieldGen->nameResolver->getClassName(fieldGen->fullType) + ".fromIntTo" + fieldGen->fullType + "(0)"; // produce enum from 0, as demanded by Google } case FieldDescriptor::TYPE_FIXED32: return "0"; @@ -115,7 +120,7 @@ string protobufTypeToInitValue(FieldDescriptor const * descriptor) { case FieldDescriptor::TYPE_INT64: return "0L"; case FieldDescriptor::TYPE_MESSAGE: - return string(descriptor->message_type()->name()) + "()"; + return fieldGen->nameResolver->getBuilderName(fieldGen->fullType) + "().build()"; case FieldDescriptor::TYPE_SFIXED32: return "0"; case FieldDescriptor::TYPE_SFIXED64: @@ -171,8 +176,36 @@ string protobufTypeToKotlinFunctionSuffix(FieldDescriptor::Type type) { return "SInt64"; } } + } // namespace name_resolving + +NameResolver::NameResolver() { + names = map(); + builders = map(); +} + +void NameResolver::addClass(string simpleName, string parentName) { + if (parentName == "") { + names[simpleName] = simpleName; + builders[simpleName] = simpleName + ".Builder" + simpleName; + } + else + { + names[simpleName] = parentName + "." + simpleName; + builders[simpleName] = parentName + "." + simpleName + ".Builder" + simpleName; + } +} + +string NameResolver::getClassName(string simpleName) { + return names[simpleName]; +} + +string NameResolver::getBuilderName(string classSimpleName) { + return builders[classSimpleName]; +} + } // namespace kotlin } // namespace compiler } // namespace protobuf -} // namespace google \ No newline at end of file +} // namespace google + diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_name_resolver.h b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_name_resolver.h index 112253c9451..25179993b40 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_name_resolver.h +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/src/kotlin_name_resolver.h @@ -7,11 +7,28 @@ #include #include +#include +#include "kotlin_field_generator.h" namespace google { namespace protobuf { namespace compiler { namespace kotlin { + +class FieldGenerator; // declared in kotlin_field_generator.h +class ClassGenerator; // declared in kotlin_class_generator.h + +class NameResolver { +public: + NameResolver(); + + void addClass (string simpleName, string parentName); + string getClassName (string simpleName); + string getBuilderName (string classSimpleName); +private: + std::map names; + std::map builders; +}; namespace name_resolving { std::string makeFirstLetterUpper(std::string s); @@ -20,7 +37,7 @@ std::string getFileNameWithoutExtension(std::string fullName); std::string getKotlinOutputByProtoName(std::string protoName); -std::string protobufTypeToInitValue(FieldDescriptor const * descriptor); +std::string protobufTypeToInitValue(FieldGenerator const * fieldGenerator); std::string protobufToKotlinField(FieldDescriptor const * descriptor); diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/com/example/tutorial/AddressBookProtos.java b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/com/example/tutorial/AddressBookProtos.java deleted file mode 100644 index 02d2b3dcf3c..00000000000 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/com/example/tutorial/AddressBookProtos.java +++ /dev/null @@ -1,2546 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: test/addressbook.proto - -package com.example.tutorial; - -public final class AddressBookProtos { - private AddressBookProtos() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - } - public interface PersonOrBuilder extends - // @@protoc_insertion_point(interface_extends:tutorial.Person) - com.google.protobuf.MessageOrBuilder { - - /** - * optional string name = 1; - */ - java.lang.String getName(); - /** - * optional string name = 1; - */ - com.google.protobuf.ByteString - getNameBytes(); - - /** - *
-     * Unique ID number for this person.
-     * 
- * - * optional int32 id = 2; - */ - int getId(); - - /** - * optional string email = 3; - */ - java.lang.String getEmail(); - /** - * optional string email = 3; - */ - com.google.protobuf.ByteString - getEmailBytes(); - - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - java.util.List - getPhonesList(); - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - com.example.tutorial.AddressBookProtos.Person.PhoneNumber getPhones(int index); - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - int getPhonesCount(); - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - java.util.List - getPhonesOrBuilderList(); - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - com.example.tutorial.AddressBookProtos.Person.PhoneNumberOrBuilder getPhonesOrBuilder( - int index); - } - /** - *
-   * [START messages]
-   * 
- * - * Protobuf type {@code tutorial.Person} - */ - public static final class Person extends - com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:tutorial.Person) - PersonOrBuilder { - // Use Person.newBuilder() to construct. - private Person(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - } - private Person() { - name_ = ""; - id_ = 0; - email_ = ""; - phones_ = java.util.Collections.emptyList(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); - } - private Person( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - int mutable_bitField0_ = 0; - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!input.skipField(tag)) { - done = true; - } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - name_ = s; - break; - } - case 16: { - - id_ = input.readInt32(); - break; - } - case 26: { - java.lang.String s = input.readStringRequireUtf8(); - - email_ = s; - break; - } - case 34: { - if (!((mutable_bitField0_ & 0x00000008) == 0x00000008)) { - phones_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000008; - } - phones_.add( - input.readMessage(com.example.tutorial.AddressBookProtos.Person.PhoneNumber.parser(), extensionRegistry)); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000008) == 0x00000008)) { - phones_ = java.util.Collections.unmodifiableList(phones_); - } - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_Person_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_Person_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.example.tutorial.AddressBookProtos.Person.class, com.example.tutorial.AddressBookProtos.Person.Builder.class); - } - - /** - * Protobuf enum {@code tutorial.Person.PhoneType} - */ - public enum PhoneType - implements com.google.protobuf.ProtocolMessageEnum { - /** - * MOBILE = 0; - */ - MOBILE(0), - /** - * HOME = 1; - */ - HOME(1), - /** - * WORK = 2; - */ - WORK(2), - UNRECOGNIZED(-1), - ; - - /** - * MOBILE = 0; - */ - public static final int MOBILE_VALUE = 0; - /** - * HOME = 1; - */ - public static final int HOME_VALUE = 1; - /** - * WORK = 2; - */ - public static final int WORK_VALUE = 2; - - - public final int getNumber() { - if (this == UNRECOGNIZED) { - throw new java.lang.IllegalArgumentException( - "Can't get the number of an unknown enum value."); - } - return value; - } - - /** - * @deprecated Use {@link #forNumber(int)} instead. - */ - @java.lang.Deprecated - public static PhoneType valueOf(int value) { - return forNumber(value); - } - - public static PhoneType forNumber(int value) { - switch (value) { - case 0: return MOBILE; - case 1: return HOME; - case 2: return WORK; - default: return null; - } - } - - public static com.google.protobuf.Internal.EnumLiteMap - internalGetValueMap() { - return internalValueMap; - } - private static final com.google.protobuf.Internal.EnumLiteMap< - PhoneType> internalValueMap = - new com.google.protobuf.Internal.EnumLiteMap() { - public PhoneType findValueByNumber(int number) { - return PhoneType.forNumber(number); - } - }; - - public final com.google.protobuf.Descriptors.EnumValueDescriptor - getValueDescriptor() { - return getDescriptor().getValues().get(ordinal()); - } - public final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptorForType() { - return getDescriptor(); - } - public static final com.google.protobuf.Descriptors.EnumDescriptor - getDescriptor() { - return com.example.tutorial.AddressBookProtos.Person.getDescriptor().getEnumTypes().get(0); - } - - private static final PhoneType[] VALUES = values(); - - public static PhoneType valueOf( - com.google.protobuf.Descriptors.EnumValueDescriptor desc) { - if (desc.getType() != getDescriptor()) { - throw new java.lang.IllegalArgumentException( - "EnumValueDescriptor is not for this type."); - } - if (desc.getIndex() == -1) { - return UNRECOGNIZED; - } - return VALUES[desc.getIndex()]; - } - - private final int value; - - private PhoneType(int value) { - this.value = value; - } - - // @@protoc_insertion_point(enum_scope:tutorial.Person.PhoneType) - } - - public interface PhoneNumberOrBuilder extends - // @@protoc_insertion_point(interface_extends:tutorial.Person.PhoneNumber) - com.google.protobuf.MessageOrBuilder { - - /** - * optional string number = 1; - */ - java.lang.String getNumber(); - /** - * optional string number = 1; - */ - com.google.protobuf.ByteString - getNumberBytes(); - - /** - * optional .tutorial.Person.PhoneType type = 2; - */ - int getTypeValue(); - /** - * optional .tutorial.Person.PhoneType type = 2; - */ - com.example.tutorial.AddressBookProtos.Person.PhoneType getType(); - } - /** - * Protobuf type {@code tutorial.Person.PhoneNumber} - */ - public static final class PhoneNumber extends - com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:tutorial.Person.PhoneNumber) - PhoneNumberOrBuilder { - // Use PhoneNumber.newBuilder() to construct. - private PhoneNumber(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - } - private PhoneNumber() { - number_ = ""; - type_ = 0; - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); - } - private PhoneNumber( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - int mutable_bitField0_ = 0; - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!input.skipField(tag)) { - done = true; - } - break; - } - case 10: { - java.lang.String s = input.readStringRequireUtf8(); - - number_ = s; - break; - } - case 16: { - int rawValue = input.readEnum(); - - type_ = rawValue; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_Person_PhoneNumber_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_Person_PhoneNumber_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.example.tutorial.AddressBookProtos.Person.PhoneNumber.class, com.example.tutorial.AddressBookProtos.Person.PhoneNumber.Builder.class); - } - - public static final int NUMBER_FIELD_NUMBER = 1; - private volatile java.lang.Object number_; - /** - * optional string number = 1; - */ - public java.lang.String getNumber() { - java.lang.Object ref = number_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - number_ = s; - return s; - } - } - /** - * optional string number = 1; - */ - public com.google.protobuf.ByteString - getNumberBytes() { - java.lang.Object ref = number_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - number_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int TYPE_FIELD_NUMBER = 2; - private int type_; - /** - * optional .tutorial.Person.PhoneType type = 2; - */ - public int getTypeValue() { - return type_; - } - /** - * optional .tutorial.Person.PhoneType type = 2; - */ - public com.example.tutorial.AddressBookProtos.Person.PhoneType getType() { - com.example.tutorial.AddressBookProtos.Person.PhoneType result = com.example.tutorial.AddressBookProtos.Person.PhoneType.valueOf(type_); - return result == null ? com.example.tutorial.AddressBookProtos.Person.PhoneType.UNRECOGNIZED : result; - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getNumberBytes().isEmpty()) { - com.google.protobuf.GeneratedMessage.writeString(output, 1, number_); - } - if (type_ != com.example.tutorial.AddressBookProtos.Person.PhoneType.MOBILE.getNumber()) { - output.writeEnum(2, type_); - } - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getNumberBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessage.computeStringSize(1, number_); - } - if (type_ != com.example.tutorial.AddressBookProtos.Person.PhoneType.MOBILE.getNumber()) { - size += com.google.protobuf.CodedOutputStream - .computeEnumSize(2, type_); - } - memoizedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof com.example.tutorial.AddressBookProtos.Person.PhoneNumber)) { - return super.equals(obj); - } - com.example.tutorial.AddressBookProtos.Person.PhoneNumber other = (com.example.tutorial.AddressBookProtos.Person.PhoneNumber) obj; - - boolean result = true; - result = result && getNumber() - .equals(other.getNumber()); - result = result && type_ == other.type_; - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptorForType().hashCode(); - hash = (37 * hash) + NUMBER_FIELD_NUMBER; - hash = (53 * hash) + getNumber().hashCode(); - hash = (37 * hash) + TYPE_FIELD_NUMBER; - hash = (53 * hash) + type_; - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static com.example.tutorial.AddressBookProtos.Person.PhoneNumber parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static com.example.tutorial.AddressBookProtos.Person.PhoneNumber parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static com.example.tutorial.AddressBookProtos.Person.PhoneNumber parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static com.example.tutorial.AddressBookProtos.Person.PhoneNumber parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static com.example.tutorial.AddressBookProtos.Person.PhoneNumber parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static com.example.tutorial.AddressBookProtos.Person.PhoneNumber parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static com.example.tutorial.AddressBookProtos.Person.PhoneNumber parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input); - } - public static com.example.tutorial.AddressBookProtos.Person.PhoneNumber parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static com.example.tutorial.AddressBookProtos.Person.PhoneNumber parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static com.example.tutorial.AddressBookProtos.Person.PhoneNumber parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(com.example.tutorial.AddressBookProtos.Person.PhoneNumber prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code tutorial.Person.PhoneNumber} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:tutorial.Person.PhoneNumber) - com.example.tutorial.AddressBookProtos.Person.PhoneNumberOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_Person_PhoneNumber_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_Person_PhoneNumber_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.example.tutorial.AddressBookProtos.Person.PhoneNumber.class, com.example.tutorial.AddressBookProtos.Person.PhoneNumber.Builder.class); - } - - // Construct using com.example.tutorial.AddressBookProtos.Person.PhoneNumber.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } - } - public Builder clear() { - super.clear(); - number_ = ""; - - type_ = 0; - - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_Person_PhoneNumber_descriptor; - } - - public com.example.tutorial.AddressBookProtos.Person.PhoneNumber getDefaultInstanceForType() { - return com.example.tutorial.AddressBookProtos.Person.PhoneNumber.getDefaultInstance(); - } - - public com.example.tutorial.AddressBookProtos.Person.PhoneNumber build() { - com.example.tutorial.AddressBookProtos.Person.PhoneNumber result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public com.example.tutorial.AddressBookProtos.Person.PhoneNumber buildPartial() { - com.example.tutorial.AddressBookProtos.Person.PhoneNumber result = new com.example.tutorial.AddressBookProtos.Person.PhoneNumber(this); - result.number_ = number_; - result.type_ = type_; - onBuilt(); - return result; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof com.example.tutorial.AddressBookProtos.Person.PhoneNumber) { - return mergeFrom((com.example.tutorial.AddressBookProtos.Person.PhoneNumber)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(com.example.tutorial.AddressBookProtos.Person.PhoneNumber other) { - if (other == com.example.tutorial.AddressBookProtos.Person.PhoneNumber.getDefaultInstance()) return this; - if (!other.getNumber().isEmpty()) { - number_ = other.number_; - onChanged(); - } - if (other.type_ != 0) { - setTypeValue(other.getTypeValue()); - } - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - com.example.tutorial.AddressBookProtos.Person.PhoneNumber parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (com.example.tutorial.AddressBookProtos.Person.PhoneNumber) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - - private java.lang.Object number_ = ""; - /** - * optional string number = 1; - */ - public java.lang.String getNumber() { - java.lang.Object ref = number_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - number_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * optional string number = 1; - */ - public com.google.protobuf.ByteString - getNumberBytes() { - java.lang.Object ref = number_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - number_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * optional string number = 1; - */ - public Builder setNumber( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - number_ = value; - onChanged(); - return this; - } - /** - * optional string number = 1; - */ - public Builder clearNumber() { - - number_ = getDefaultInstance().getNumber(); - onChanged(); - return this; - } - /** - * optional string number = 1; - */ - public Builder setNumberBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - number_ = value; - onChanged(); - return this; - } - - private int type_ = 0; - /** - * optional .tutorial.Person.PhoneType type = 2; - */ - public int getTypeValue() { - return type_; - } - /** - * optional .tutorial.Person.PhoneType type = 2; - */ - public Builder setTypeValue(int value) { - type_ = value; - onChanged(); - return this; - } - /** - * optional .tutorial.Person.PhoneType type = 2; - */ - public com.example.tutorial.AddressBookProtos.Person.PhoneType getType() { - com.example.tutorial.AddressBookProtos.Person.PhoneType result = com.example.tutorial.AddressBookProtos.Person.PhoneType.valueOf(type_); - return result == null ? com.example.tutorial.AddressBookProtos.Person.PhoneType.UNRECOGNIZED : result; - } - /** - * optional .tutorial.Person.PhoneType type = 2; - */ - public Builder setType(com.example.tutorial.AddressBookProtos.Person.PhoneType value) { - if (value == null) { - throw new NullPointerException(); - } - - type_ = value.getNumber(); - onChanged(); - return this; - } - /** - * optional .tutorial.Person.PhoneType type = 2; - */ - public Builder clearType() { - - type_ = 0; - onChanged(); - return this; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } - - - // @@protoc_insertion_point(builder_scope:tutorial.Person.PhoneNumber) - } - - // @@protoc_insertion_point(class_scope:tutorial.Person.PhoneNumber) - private static final com.example.tutorial.AddressBookProtos.Person.PhoneNumber DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new com.example.tutorial.AddressBookProtos.Person.PhoneNumber(); - } - - public static com.example.tutorial.AddressBookProtos.Person.PhoneNumber getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public PhoneNumber parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new PhoneNumber(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public com.example.tutorial.AddressBookProtos.Person.PhoneNumber getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - private int bitField0_; - public static final int NAME_FIELD_NUMBER = 1; - private volatile java.lang.Object name_; - /** - * optional string name = 1; - */ - public java.lang.String getName() { - java.lang.Object ref = name_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - name_ = s; - return s; - } - } - /** - * optional string name = 1; - */ - public com.google.protobuf.ByteString - getNameBytes() { - java.lang.Object ref = name_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - name_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int ID_FIELD_NUMBER = 2; - private int id_; - /** - *
-     * Unique ID number for this person.
-     * 
- * - * optional int32 id = 2; - */ - public int getId() { - return id_; - } - - public static final int EMAIL_FIELD_NUMBER = 3; - private volatile java.lang.Object email_; - /** - * optional string email = 3; - */ - public java.lang.String getEmail() { - java.lang.Object ref = email_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - email_ = s; - return s; - } - } - /** - * optional string email = 3; - */ - public com.google.protobuf.ByteString - getEmailBytes() { - java.lang.Object ref = email_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - email_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int PHONES_FIELD_NUMBER = 4; - private java.util.List phones_; - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public java.util.List getPhonesList() { - return phones_; - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public java.util.List - getPhonesOrBuilderList() { - return phones_; - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public int getPhonesCount() { - return phones_.size(); - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public com.example.tutorial.AddressBookProtos.Person.PhoneNumber getPhones(int index) { - return phones_.get(index); - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public com.example.tutorial.AddressBookProtos.Person.PhoneNumberOrBuilder getPhonesOrBuilder( - int index) { - return phones_.get(index); - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - if (!getNameBytes().isEmpty()) { - com.google.protobuf.GeneratedMessage.writeString(output, 1, name_); - } - if (id_ != 0) { - output.writeInt32(2, id_); - } - if (!getEmailBytes().isEmpty()) { - com.google.protobuf.GeneratedMessage.writeString(output, 3, email_); - } - for (int i = 0; i < phones_.size(); i++) { - output.writeMessage(4, phones_.get(i)); - } - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - if (!getNameBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessage.computeStringSize(1, name_); - } - if (id_ != 0) { - size += com.google.protobuf.CodedOutputStream - .computeInt32Size(2, id_); - } - if (!getEmailBytes().isEmpty()) { - size += com.google.protobuf.GeneratedMessage.computeStringSize(3, email_); - } - for (int i = 0; i < phones_.size(); i++) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(4, phones_.get(i)); - } - memoizedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof com.example.tutorial.AddressBookProtos.Person)) { - return super.equals(obj); - } - com.example.tutorial.AddressBookProtos.Person other = (com.example.tutorial.AddressBookProtos.Person) obj; - - boolean result = true; - result = result && getName() - .equals(other.getName()); - result = result && (getId() - == other.getId()); - result = result && getEmail() - .equals(other.getEmail()); - result = result && getPhonesList() - .equals(other.getPhonesList()); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptorForType().hashCode(); - hash = (37 * hash) + NAME_FIELD_NUMBER; - hash = (53 * hash) + getName().hashCode(); - hash = (37 * hash) + ID_FIELD_NUMBER; - hash = (53 * hash) + getId(); - hash = (37 * hash) + EMAIL_FIELD_NUMBER; - hash = (53 * hash) + getEmail().hashCode(); - if (getPhonesCount() > 0) { - hash = (37 * hash) + PHONES_FIELD_NUMBER; - hash = (53 * hash) + getPhonesList().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static com.example.tutorial.AddressBookProtos.Person parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static com.example.tutorial.AddressBookProtos.Person parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static com.example.tutorial.AddressBookProtos.Person parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static com.example.tutorial.AddressBookProtos.Person parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static com.example.tutorial.AddressBookProtos.Person parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static com.example.tutorial.AddressBookProtos.Person parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static com.example.tutorial.AddressBookProtos.Person parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input); - } - public static com.example.tutorial.AddressBookProtos.Person parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static com.example.tutorial.AddressBookProtos.Person parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static com.example.tutorial.AddressBookProtos.Person parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(com.example.tutorial.AddressBookProtos.Person prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - *
-     * [START messages]
-     * 
- * - * Protobuf type {@code tutorial.Person} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:tutorial.Person) - com.example.tutorial.AddressBookProtos.PersonOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_Person_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_Person_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.example.tutorial.AddressBookProtos.Person.class, com.example.tutorial.AddressBookProtos.Person.Builder.class); - } - - // Construct using com.example.tutorial.AddressBookProtos.Person.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - getPhonesFieldBuilder(); - } - } - public Builder clear() { - super.clear(); - name_ = ""; - - id_ = 0; - - email_ = ""; - - if (phonesBuilder_ == null) { - phones_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000008); - } else { - phonesBuilder_.clear(); - } - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_Person_descriptor; - } - - public com.example.tutorial.AddressBookProtos.Person getDefaultInstanceForType() { - return com.example.tutorial.AddressBookProtos.Person.getDefaultInstance(); - } - - public com.example.tutorial.AddressBookProtos.Person build() { - com.example.tutorial.AddressBookProtos.Person result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public com.example.tutorial.AddressBookProtos.Person buildPartial() { - com.example.tutorial.AddressBookProtos.Person result = new com.example.tutorial.AddressBookProtos.Person(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - result.name_ = name_; - result.id_ = id_; - result.email_ = email_; - if (phonesBuilder_ == null) { - if (((bitField0_ & 0x00000008) == 0x00000008)) { - phones_ = java.util.Collections.unmodifiableList(phones_); - bitField0_ = (bitField0_ & ~0x00000008); - } - result.phones_ = phones_; - } else { - result.phones_ = phonesBuilder_.build(); - } - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof com.example.tutorial.AddressBookProtos.Person) { - return mergeFrom((com.example.tutorial.AddressBookProtos.Person)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(com.example.tutorial.AddressBookProtos.Person other) { - if (other == com.example.tutorial.AddressBookProtos.Person.getDefaultInstance()) return this; - if (!other.getName().isEmpty()) { - name_ = other.name_; - onChanged(); - } - if (other.getId() != 0) { - setId(other.getId()); - } - if (!other.getEmail().isEmpty()) { - email_ = other.email_; - onChanged(); - } - if (phonesBuilder_ == null) { - if (!other.phones_.isEmpty()) { - if (phones_.isEmpty()) { - phones_ = other.phones_; - bitField0_ = (bitField0_ & ~0x00000008); - } else { - ensurePhonesIsMutable(); - phones_.addAll(other.phones_); - } - onChanged(); - } - } else { - if (!other.phones_.isEmpty()) { - if (phonesBuilder_.isEmpty()) { - phonesBuilder_.dispose(); - phonesBuilder_ = null; - phones_ = other.phones_; - bitField0_ = (bitField0_ & ~0x00000008); - phonesBuilder_ = - com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? - getPhonesFieldBuilder() : null; - } else { - phonesBuilder_.addAllMessages(other.phones_); - } - } - } - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - com.example.tutorial.AddressBookProtos.Person parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (com.example.tutorial.AddressBookProtos.Person) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private java.lang.Object name_ = ""; - /** - * optional string name = 1; - */ - public java.lang.String getName() { - java.lang.Object ref = name_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - name_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * optional string name = 1; - */ - public com.google.protobuf.ByteString - getNameBytes() { - java.lang.Object ref = name_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - name_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * optional string name = 1; - */ - public Builder setName( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - name_ = value; - onChanged(); - return this; - } - /** - * optional string name = 1; - */ - public Builder clearName() { - - name_ = getDefaultInstance().getName(); - onChanged(); - return this; - } - /** - * optional string name = 1; - */ - public Builder setNameBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - name_ = value; - onChanged(); - return this; - } - - private int id_ ; - /** - *
-       * Unique ID number for this person.
-       * 
- * - * optional int32 id = 2; - */ - public int getId() { - return id_; - } - /** - *
-       * Unique ID number for this person.
-       * 
- * - * optional int32 id = 2; - */ - public Builder setId(int value) { - - id_ = value; - onChanged(); - return this; - } - /** - *
-       * Unique ID number for this person.
-       * 
- * - * optional int32 id = 2; - */ - public Builder clearId() { - - id_ = 0; - onChanged(); - return this; - } - - private java.lang.Object email_ = ""; - /** - * optional string email = 3; - */ - public java.lang.String getEmail() { - java.lang.Object ref = email_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - email_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * optional string email = 3; - */ - public com.google.protobuf.ByteString - getEmailBytes() { - java.lang.Object ref = email_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - email_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * optional string email = 3; - */ - public Builder setEmail( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - email_ = value; - onChanged(); - return this; - } - /** - * optional string email = 3; - */ - public Builder clearEmail() { - - email_ = getDefaultInstance().getEmail(); - onChanged(); - return this; - } - /** - * optional string email = 3; - */ - public Builder setEmailBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - email_ = value; - onChanged(); - return this; - } - - private java.util.List phones_ = - java.util.Collections.emptyList(); - private void ensurePhonesIsMutable() { - if (!((bitField0_ & 0x00000008) == 0x00000008)) { - phones_ = new java.util.ArrayList(phones_); - bitField0_ |= 0x00000008; - } - } - - private com.google.protobuf.RepeatedFieldBuilderV3< - com.example.tutorial.AddressBookProtos.Person.PhoneNumber, com.example.tutorial.AddressBookProtos.Person.PhoneNumber.Builder, com.example.tutorial.AddressBookProtos.Person.PhoneNumberOrBuilder> phonesBuilder_; - - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public java.util.List getPhonesList() { - if (phonesBuilder_ == null) { - return java.util.Collections.unmodifiableList(phones_); - } else { - return phonesBuilder_.getMessageList(); - } - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public int getPhonesCount() { - if (phonesBuilder_ == null) { - return phones_.size(); - } else { - return phonesBuilder_.getCount(); - } - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public com.example.tutorial.AddressBookProtos.Person.PhoneNumber getPhones(int index) { - if (phonesBuilder_ == null) { - return phones_.get(index); - } else { - return phonesBuilder_.getMessage(index); - } - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public Builder setPhones( - int index, com.example.tutorial.AddressBookProtos.Person.PhoneNumber value) { - if (phonesBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensurePhonesIsMutable(); - phones_.set(index, value); - onChanged(); - } else { - phonesBuilder_.setMessage(index, value); - } - return this; - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public Builder setPhones( - int index, com.example.tutorial.AddressBookProtos.Person.PhoneNumber.Builder builderForValue) { - if (phonesBuilder_ == null) { - ensurePhonesIsMutable(); - phones_.set(index, builderForValue.build()); - onChanged(); - } else { - phonesBuilder_.setMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public Builder addPhones(com.example.tutorial.AddressBookProtos.Person.PhoneNumber value) { - if (phonesBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensurePhonesIsMutable(); - phones_.add(value); - onChanged(); - } else { - phonesBuilder_.addMessage(value); - } - return this; - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public Builder addPhones( - int index, com.example.tutorial.AddressBookProtos.Person.PhoneNumber value) { - if (phonesBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensurePhonesIsMutable(); - phones_.add(index, value); - onChanged(); - } else { - phonesBuilder_.addMessage(index, value); - } - return this; - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public Builder addPhones( - com.example.tutorial.AddressBookProtos.Person.PhoneNumber.Builder builderForValue) { - if (phonesBuilder_ == null) { - ensurePhonesIsMutable(); - phones_.add(builderForValue.build()); - onChanged(); - } else { - phonesBuilder_.addMessage(builderForValue.build()); - } - return this; - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public Builder addPhones( - int index, com.example.tutorial.AddressBookProtos.Person.PhoneNumber.Builder builderForValue) { - if (phonesBuilder_ == null) { - ensurePhonesIsMutable(); - phones_.add(index, builderForValue.build()); - onChanged(); - } else { - phonesBuilder_.addMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public Builder addAllPhones( - java.lang.Iterable values) { - if (phonesBuilder_ == null) { - ensurePhonesIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, phones_); - onChanged(); - } else { - phonesBuilder_.addAllMessages(values); - } - return this; - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public Builder clearPhones() { - if (phonesBuilder_ == null) { - phones_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000008); - onChanged(); - } else { - phonesBuilder_.clear(); - } - return this; - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public Builder removePhones(int index) { - if (phonesBuilder_ == null) { - ensurePhonesIsMutable(); - phones_.remove(index); - onChanged(); - } else { - phonesBuilder_.remove(index); - } - return this; - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public com.example.tutorial.AddressBookProtos.Person.PhoneNumber.Builder getPhonesBuilder( - int index) { - return getPhonesFieldBuilder().getBuilder(index); - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public com.example.tutorial.AddressBookProtos.Person.PhoneNumberOrBuilder getPhonesOrBuilder( - int index) { - if (phonesBuilder_ == null) { - return phones_.get(index); } else { - return phonesBuilder_.getMessageOrBuilder(index); - } - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public java.util.List - getPhonesOrBuilderList() { - if (phonesBuilder_ != null) { - return phonesBuilder_.getMessageOrBuilderList(); - } else { - return java.util.Collections.unmodifiableList(phones_); - } - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public com.example.tutorial.AddressBookProtos.Person.PhoneNumber.Builder addPhonesBuilder() { - return getPhonesFieldBuilder().addBuilder( - com.example.tutorial.AddressBookProtos.Person.PhoneNumber.getDefaultInstance()); - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public com.example.tutorial.AddressBookProtos.Person.PhoneNumber.Builder addPhonesBuilder( - int index) { - return getPhonesFieldBuilder().addBuilder( - index, com.example.tutorial.AddressBookProtos.Person.PhoneNumber.getDefaultInstance()); - } - /** - * repeated .tutorial.Person.PhoneNumber phones = 4; - */ - public java.util.List - getPhonesBuilderList() { - return getPhonesFieldBuilder().getBuilderList(); - } - private com.google.protobuf.RepeatedFieldBuilderV3< - com.example.tutorial.AddressBookProtos.Person.PhoneNumber, com.example.tutorial.AddressBookProtos.Person.PhoneNumber.Builder, com.example.tutorial.AddressBookProtos.Person.PhoneNumberOrBuilder> - getPhonesFieldBuilder() { - if (phonesBuilder_ == null) { - phonesBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3< - com.example.tutorial.AddressBookProtos.Person.PhoneNumber, com.example.tutorial.AddressBookProtos.Person.PhoneNumber.Builder, com.example.tutorial.AddressBookProtos.Person.PhoneNumberOrBuilder>( - phones_, - ((bitField0_ & 0x00000008) == 0x00000008), - getParentForChildren(), - isClean()); - phones_ = null; - } - return phonesBuilder_; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } - - - // @@protoc_insertion_point(builder_scope:tutorial.Person) - } - - // @@protoc_insertion_point(class_scope:tutorial.Person) - private static final com.example.tutorial.AddressBookProtos.Person DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new com.example.tutorial.AddressBookProtos.Person(); - } - - public static com.example.tutorial.AddressBookProtos.Person getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public Person parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new Person(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public com.example.tutorial.AddressBookProtos.Person getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - public interface AddressBookOrBuilder extends - // @@protoc_insertion_point(interface_extends:tutorial.AddressBook) - com.google.protobuf.MessageOrBuilder { - - /** - * repeated .tutorial.Person people = 1; - */ - java.util.List - getPeopleList(); - /** - * repeated .tutorial.Person people = 1; - */ - com.example.tutorial.AddressBookProtos.Person getPeople(int index); - /** - * repeated .tutorial.Person people = 1; - */ - int getPeopleCount(); - /** - * repeated .tutorial.Person people = 1; - */ - java.util.List - getPeopleOrBuilderList(); - /** - * repeated .tutorial.Person people = 1; - */ - com.example.tutorial.AddressBookProtos.PersonOrBuilder getPeopleOrBuilder( - int index); - } - /** - *
-   * Our address book file is just one of these.
-   * 
- * - * Protobuf type {@code tutorial.AddressBook} - */ - public static final class AddressBook extends - com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:tutorial.AddressBook) - AddressBookOrBuilder { - // Use AddressBook.newBuilder() to construct. - private AddressBook(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - } - private AddressBook() { - people_ = java.util.Collections.emptyList(); - } - - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return com.google.protobuf.UnknownFieldSet.getDefaultInstance(); - } - private AddressBook( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - this(); - int mutable_bitField0_ = 0; - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!input.skipField(tag)) { - done = true; - } - break; - } - case 10: { - if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) { - people_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000001; - } - people_.add( - input.readMessage(com.example.tutorial.AddressBookProtos.Person.parser(), extensionRegistry)); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) { - people_ = java.util.Collections.unmodifiableList(people_); - } - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_AddressBook_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_AddressBook_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.example.tutorial.AddressBookProtos.AddressBook.class, com.example.tutorial.AddressBookProtos.AddressBook.Builder.class); - } - - public static final int PEOPLE_FIELD_NUMBER = 1; - private java.util.List people_; - /** - * repeated .tutorial.Person people = 1; - */ - public java.util.List getPeopleList() { - return people_; - } - /** - * repeated .tutorial.Person people = 1; - */ - public java.util.List - getPeopleOrBuilderList() { - return people_; - } - /** - * repeated .tutorial.Person people = 1; - */ - public int getPeopleCount() { - return people_.size(); - } - /** - * repeated .tutorial.Person people = 1; - */ - public com.example.tutorial.AddressBookProtos.Person getPeople(int index) { - return people_.get(index); - } - /** - * repeated .tutorial.Person people = 1; - */ - public com.example.tutorial.AddressBookProtos.PersonOrBuilder getPeopleOrBuilder( - int index) { - return people_.get(index); - } - - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - for (int i = 0; i < people_.size(); i++) { - output.writeMessage(1, people_.get(i)); - } - } - - public int getSerializedSize() { - int size = memoizedSize; - if (size != -1) return size; - - size = 0; - for (int i = 0; i < people_.size(); i++) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(1, people_.get(i)); - } - memoizedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - @java.lang.Override - public boolean equals(final java.lang.Object obj) { - if (obj == this) { - return true; - } - if (!(obj instanceof com.example.tutorial.AddressBookProtos.AddressBook)) { - return super.equals(obj); - } - com.example.tutorial.AddressBookProtos.AddressBook other = (com.example.tutorial.AddressBookProtos.AddressBook) obj; - - boolean result = true; - result = result && getPeopleList() - .equals(other.getPeopleList()); - return result; - } - - @java.lang.Override - public int hashCode() { - if (memoizedHashCode != 0) { - return memoizedHashCode; - } - int hash = 41; - hash = (19 * hash) + getDescriptorForType().hashCode(); - if (getPeopleCount() > 0) { - hash = (37 * hash) + PEOPLE_FIELD_NUMBER; - hash = (53 * hash) + getPeopleList().hashCode(); - } - hash = (29 * hash) + unknownFields.hashCode(); - memoizedHashCode = hash; - return hash; - } - - public static com.example.tutorial.AddressBookProtos.AddressBook parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static com.example.tutorial.AddressBookProtos.AddressBook parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static com.example.tutorial.AddressBookProtos.AddressBook parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static com.example.tutorial.AddressBookProtos.AddressBook parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static com.example.tutorial.AddressBookProtos.AddressBook parseFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static com.example.tutorial.AddressBookProtos.AddressBook parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - public static com.example.tutorial.AddressBookProtos.AddressBook parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input); - } - public static com.example.tutorial.AddressBookProtos.AddressBook parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseDelimitedWithIOException(PARSER, input, extensionRegistry); - } - public static com.example.tutorial.AddressBookProtos.AddressBook parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input); - } - public static com.example.tutorial.AddressBookProtos.AddressBook parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return com.google.protobuf.GeneratedMessage - .parseWithIOException(PARSER, input, extensionRegistry); - } - - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder() { - return DEFAULT_INSTANCE.toBuilder(); - } - public static Builder newBuilder(com.example.tutorial.AddressBookProtos.AddressBook prototype) { - return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { - return this == DEFAULT_INSTANCE - ? new Builder() : new Builder().mergeFrom(this); - } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - *
-     * Our address book file is just one of these.
-     * 
- * - * Protobuf type {@code tutorial.AddressBook} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:tutorial.AddressBook) - com.example.tutorial.AddressBookProtos.AddressBookOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_AddressBook_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_AddressBook_fieldAccessorTable - .ensureFieldAccessorsInitialized( - com.example.tutorial.AddressBookProtos.AddressBook.class, com.example.tutorial.AddressBookProtos.AddressBook.Builder.class); - } - - // Construct using com.example.tutorial.AddressBookProtos.AddressBook.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - getPeopleFieldBuilder(); - } - } - public Builder clear() { - super.clear(); - if (peopleBuilder_ == null) { - people_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000001); - } else { - peopleBuilder_.clear(); - } - return this; - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return com.example.tutorial.AddressBookProtos.internal_static_tutorial_AddressBook_descriptor; - } - - public com.example.tutorial.AddressBookProtos.AddressBook getDefaultInstanceForType() { - return com.example.tutorial.AddressBookProtos.AddressBook.getDefaultInstance(); - } - - public com.example.tutorial.AddressBookProtos.AddressBook build() { - com.example.tutorial.AddressBookProtos.AddressBook result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public com.example.tutorial.AddressBookProtos.AddressBook buildPartial() { - com.example.tutorial.AddressBookProtos.AddressBook result = new com.example.tutorial.AddressBookProtos.AddressBook(this); - int from_bitField0_ = bitField0_; - if (peopleBuilder_ == null) { - if (((bitField0_ & 0x00000001) == 0x00000001)) { - people_ = java.util.Collections.unmodifiableList(people_); - bitField0_ = (bitField0_ & ~0x00000001); - } - result.people_ = people_; - } else { - result.people_ = peopleBuilder_.build(); - } - onBuilt(); - return result; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof com.example.tutorial.AddressBookProtos.AddressBook) { - return mergeFrom((com.example.tutorial.AddressBookProtos.AddressBook)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(com.example.tutorial.AddressBookProtos.AddressBook other) { - if (other == com.example.tutorial.AddressBookProtos.AddressBook.getDefaultInstance()) return this; - if (peopleBuilder_ == null) { - if (!other.people_.isEmpty()) { - if (people_.isEmpty()) { - people_ = other.people_; - bitField0_ = (bitField0_ & ~0x00000001); - } else { - ensurePeopleIsMutable(); - people_.addAll(other.people_); - } - onChanged(); - } - } else { - if (!other.people_.isEmpty()) { - if (peopleBuilder_.isEmpty()) { - peopleBuilder_.dispose(); - peopleBuilder_ = null; - people_ = other.people_; - bitField0_ = (bitField0_ & ~0x00000001); - peopleBuilder_ = - com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? - getPeopleFieldBuilder() : null; - } else { - peopleBuilder_.addAllMessages(other.people_); - } - } - } - onChanged(); - return this; - } - - public final boolean isInitialized() { - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - com.example.tutorial.AddressBookProtos.AddressBook parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (com.example.tutorial.AddressBookProtos.AddressBook) e.getUnfinishedMessage(); - throw e.unwrapIOException(); - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private java.util.List people_ = - java.util.Collections.emptyList(); - private void ensurePeopleIsMutable() { - if (!((bitField0_ & 0x00000001) == 0x00000001)) { - people_ = new java.util.ArrayList(people_); - bitField0_ |= 0x00000001; - } - } - - private com.google.protobuf.RepeatedFieldBuilderV3< - com.example.tutorial.AddressBookProtos.Person, com.example.tutorial.AddressBookProtos.Person.Builder, com.example.tutorial.AddressBookProtos.PersonOrBuilder> peopleBuilder_; - - /** - * repeated .tutorial.Person people = 1; - */ - public java.util.List getPeopleList() { - if (peopleBuilder_ == null) { - return java.util.Collections.unmodifiableList(people_); - } else { - return peopleBuilder_.getMessageList(); - } - } - /** - * repeated .tutorial.Person people = 1; - */ - public int getPeopleCount() { - if (peopleBuilder_ == null) { - return people_.size(); - } else { - return peopleBuilder_.getCount(); - } - } - /** - * repeated .tutorial.Person people = 1; - */ - public com.example.tutorial.AddressBookProtos.Person getPeople(int index) { - if (peopleBuilder_ == null) { - return people_.get(index); - } else { - return peopleBuilder_.getMessage(index); - } - } - /** - * repeated .tutorial.Person people = 1; - */ - public Builder setPeople( - int index, com.example.tutorial.AddressBookProtos.Person value) { - if (peopleBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensurePeopleIsMutable(); - people_.set(index, value); - onChanged(); - } else { - peopleBuilder_.setMessage(index, value); - } - return this; - } - /** - * repeated .tutorial.Person people = 1; - */ - public Builder setPeople( - int index, com.example.tutorial.AddressBookProtos.Person.Builder builderForValue) { - if (peopleBuilder_ == null) { - ensurePeopleIsMutable(); - people_.set(index, builderForValue.build()); - onChanged(); - } else { - peopleBuilder_.setMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .tutorial.Person people = 1; - */ - public Builder addPeople(com.example.tutorial.AddressBookProtos.Person value) { - if (peopleBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensurePeopleIsMutable(); - people_.add(value); - onChanged(); - } else { - peopleBuilder_.addMessage(value); - } - return this; - } - /** - * repeated .tutorial.Person people = 1; - */ - public Builder addPeople( - int index, com.example.tutorial.AddressBookProtos.Person value) { - if (peopleBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensurePeopleIsMutable(); - people_.add(index, value); - onChanged(); - } else { - peopleBuilder_.addMessage(index, value); - } - return this; - } - /** - * repeated .tutorial.Person people = 1; - */ - public Builder addPeople( - com.example.tutorial.AddressBookProtos.Person.Builder builderForValue) { - if (peopleBuilder_ == null) { - ensurePeopleIsMutable(); - people_.add(builderForValue.build()); - onChanged(); - } else { - peopleBuilder_.addMessage(builderForValue.build()); - } - return this; - } - /** - * repeated .tutorial.Person people = 1; - */ - public Builder addPeople( - int index, com.example.tutorial.AddressBookProtos.Person.Builder builderForValue) { - if (peopleBuilder_ == null) { - ensurePeopleIsMutable(); - people_.add(index, builderForValue.build()); - onChanged(); - } else { - peopleBuilder_.addMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .tutorial.Person people = 1; - */ - public Builder addAllPeople( - java.lang.Iterable values) { - if (peopleBuilder_ == null) { - ensurePeopleIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, people_); - onChanged(); - } else { - peopleBuilder_.addAllMessages(values); - } - return this; - } - /** - * repeated .tutorial.Person people = 1; - */ - public Builder clearPeople() { - if (peopleBuilder_ == null) { - people_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000001); - onChanged(); - } else { - peopleBuilder_.clear(); - } - return this; - } - /** - * repeated .tutorial.Person people = 1; - */ - public Builder removePeople(int index) { - if (peopleBuilder_ == null) { - ensurePeopleIsMutable(); - people_.remove(index); - onChanged(); - } else { - peopleBuilder_.remove(index); - } - return this; - } - /** - * repeated .tutorial.Person people = 1; - */ - public com.example.tutorial.AddressBookProtos.Person.Builder getPeopleBuilder( - int index) { - return getPeopleFieldBuilder().getBuilder(index); - } - /** - * repeated .tutorial.Person people = 1; - */ - public com.example.tutorial.AddressBookProtos.PersonOrBuilder getPeopleOrBuilder( - int index) { - if (peopleBuilder_ == null) { - return people_.get(index); } else { - return peopleBuilder_.getMessageOrBuilder(index); - } - } - /** - * repeated .tutorial.Person people = 1; - */ - public java.util.List - getPeopleOrBuilderList() { - if (peopleBuilder_ != null) { - return peopleBuilder_.getMessageOrBuilderList(); - } else { - return java.util.Collections.unmodifiableList(people_); - } - } - /** - * repeated .tutorial.Person people = 1; - */ - public com.example.tutorial.AddressBookProtos.Person.Builder addPeopleBuilder() { - return getPeopleFieldBuilder().addBuilder( - com.example.tutorial.AddressBookProtos.Person.getDefaultInstance()); - } - /** - * repeated .tutorial.Person people = 1; - */ - public com.example.tutorial.AddressBookProtos.Person.Builder addPeopleBuilder( - int index) { - return getPeopleFieldBuilder().addBuilder( - index, com.example.tutorial.AddressBookProtos.Person.getDefaultInstance()); - } - /** - * repeated .tutorial.Person people = 1; - */ - public java.util.List - getPeopleBuilderList() { - return getPeopleFieldBuilder().getBuilderList(); - } - private com.google.protobuf.RepeatedFieldBuilderV3< - com.example.tutorial.AddressBookProtos.Person, com.example.tutorial.AddressBookProtos.Person.Builder, com.example.tutorial.AddressBookProtos.PersonOrBuilder> - getPeopleFieldBuilder() { - if (peopleBuilder_ == null) { - peopleBuilder_ = new com.google.protobuf.RepeatedFieldBuilderV3< - com.example.tutorial.AddressBookProtos.Person, com.example.tutorial.AddressBookProtos.Person.Builder, com.example.tutorial.AddressBookProtos.PersonOrBuilder>( - people_, - ((bitField0_ & 0x00000001) == 0x00000001), - getParentForChildren(), - isClean()); - people_ = null; - } - return peopleBuilder_; - } - public final Builder setUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } - - public final Builder mergeUnknownFields( - final com.google.protobuf.UnknownFieldSet unknownFields) { - return this; - } - - - // @@protoc_insertion_point(builder_scope:tutorial.AddressBook) - } - - // @@protoc_insertion_point(class_scope:tutorial.AddressBook) - private static final com.example.tutorial.AddressBookProtos.AddressBook DEFAULT_INSTANCE; - static { - DEFAULT_INSTANCE = new com.example.tutorial.AddressBookProtos.AddressBook(); - } - - public static com.example.tutorial.AddressBookProtos.AddressBook getDefaultInstance() { - return DEFAULT_INSTANCE; - } - - private static final com.google.protobuf.Parser - PARSER = new com.google.protobuf.AbstractParser() { - public AddressBook parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new AddressBook(input, extensionRegistry); - } - }; - - public static com.google.protobuf.Parser parser() { - return PARSER; - } - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - public com.example.tutorial.AddressBookProtos.AddressBook getDefaultInstanceForType() { - return DEFAULT_INSTANCE; - } - - } - - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_tutorial_Person_descriptor; - private static final - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_tutorial_Person_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_tutorial_Person_PhoneNumber_descriptor; - private static final - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_tutorial_Person_PhoneNumber_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_tutorial_AddressBook_descriptor; - private static final - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_tutorial_AddressBook_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\026test/addressbook.proto\022\010tutorial\"\325\001\n\006P" + - "erson\022\014\n\004name\030\001 \001(\t\022\n\n\002id\030\002 \001(\005\022\r\n\005email" + - "\030\003 \001(\t\022,\n\006phones\030\004 \003(\0132\034.tutorial.Person" + - ".PhoneNumber\032G\n\013PhoneNumber\022\016\n\006number\030\001 " + - "\001(\t\022(\n\004type\030\002 \001(\0162\032.tutorial.Person.Phon" + - "eType\"+\n\tPhoneType\022\n\n\006MOBILE\020\000\022\010\n\004HOME\020\001" + - "\022\010\n\004WORK\020\002\"/\n\013AddressBook\022 \n\006people\030\001 \003(" + - "\0132\020.tutorial.PersonBP\n\024com.example.tutor" + - "ialB\021AddressBookProtos\252\002$Google.Protobuf" + - ".Examples.AddressBookb\006proto3" - }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }, assigner); - internal_static_tutorial_Person_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_tutorial_Person_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_tutorial_Person_descriptor, - new java.lang.String[] { "Name", "Id", "Email", "Phones", }); - internal_static_tutorial_Person_PhoneNumber_descriptor = - internal_static_tutorial_Person_descriptor.getNestedTypes().get(0); - internal_static_tutorial_Person_PhoneNumber_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_tutorial_Person_PhoneNumber_descriptor, - new java.lang.String[] { "Number", "Type", }); - internal_static_tutorial_AddressBook_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_tutorial_AddressBook_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_tutorial_AddressBook_descriptor, - new java.lang.String[] { "People", }); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/nested-msg.proto b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/nested-msg.proto new file mode 100644 index 00000000000..f52084e67f0 --- /dev/null +++ b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/nested-msg.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +message Level1 { + Level2 field1 = 1; + message Level2 { + Level3 field2 = 2; + message Level3 { + Level4 field3 = 3; + message Level4 { + string field4 = 4; + } + } + } +} \ No newline at end of file diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/test/addressbook.proto b/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/test/addressbook.proto deleted file mode 100644 index f97aeb68a69..00000000000 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/test/addressbook.proto +++ /dev/null @@ -1,18 +0,0 @@ -class Person { - class PhoneNumber { - val number : kotlin.String? - val type : PhoneType? - } - enum class PhoneType(val ord: Int) { - MOBILE (0), - HOME (1), - WORK (2) - } - val name : kotlin.String? - val id : Int? - val email : kotlin.String? - val phones : List -} -class AddressBook { - val people : List -} diff --git a/proto/compiler/src/PersonMessage.kt b/proto/compiler/src/PersonMessage.kt deleted file mode 100644 index 70d01f986ba..00000000000 --- a/proto/compiler/src/PersonMessage.kt +++ /dev/null @@ -1,451 +0,0 @@ -class Person private constructor (name: kotlin.String = "", id: Int = 0, email: kotlin.String = "", phones: MutableList = mutableListOf(), someBytes: ByteArray = ByteArray(0)) { - var name : kotlin.String - private set - - var id : Int - private set - - var email : kotlin.String - private set - - var phones : MutableList - private set - - var someBytes : ByteArray - private set - - - init { - this.name = name - this.id = id - this.email = email - this.phones = phones - this.someBytes = someBytes - } - enum class PhoneType(val ord: Int) { - MOBILE (0), - HOME (1), - WORK (2); - - companion object { - fun fromIntToPhoneType (ord: Int): PhoneType { - return when (ord) { - 0 -> PhoneType.MOBILE - 1 -> PhoneType.HOME - 2 -> PhoneType.WORK - else -> throw InvalidProtocolBufferException("Error: got unexpected int ${ord} while parsing PhoneType "); - } - } - } - } - class PhoneNumber private constructor (number: kotlin.String = "", type: PhoneType = PhoneType.fromIntToPhoneType(0)) { - var number : kotlin.String - private set - - var type : PhoneType - private set - - - init { - this.number = number - this.type = type - } - - fun writeTo (output: CodedOutputStream): Unit { - output.writeString (1, number) - output.writeEnum (2, type.ord) - } - - class BuilderPhoneNumber constructor (number: kotlin.String = "", type: PhoneType = PhoneType.fromIntToPhoneType(0)) { - var number : kotlin.String - private set - fun setNumber(value: kotlin.String): BuilderPhoneNumber { - number = value - return this - } - - var type : PhoneType - private set - fun setType(value: PhoneType): BuilderPhoneNumber { - type = value - return this - } - - - init { - this.number = number - this.type = type - } - - fun readFrom (input: CodedInputStream): BuilderPhoneNumber { - number = input.readString(1) - type = PhoneType.fromIntToPhoneType(input.readEnum(2)) - return this - } - - fun build(): PhoneNumber { - return PhoneNumber(number, type) - } - - fun parseFieldFrom(input: CodedInputStream): Boolean { - if (input.isAtEnd()) { return false } - val tag = input.readInt32NoTag() - if (tag == 0) { return false } - val fieldNumber = WireFormat.getTagFieldNumber(tag) - val wireType = WireFormat.getTagWireType(tag) - when(fieldNumber) { - 1 -> number = input.readStringNoTag() - 2 -> type = PhoneType.fromIntToPhoneType(input.readEnumNoTag()) - } - return true} - fun parseFrom(input: CodedInputStream): BuilderPhoneNumber { - while(parseFieldFrom(input)) {} - return this - } - fun getSize(): Int { - var size = 0 - size += WireFormat.getStringSize(1, number) - size += WireFormat.getEnumSize(2, type.ord) - return size - } - } - - - fun mergeWith (other: PhoneNumber) { - number = other.number - type = other.type - } - - fun mergeFrom (input: CodedInputStream) { - val builder = BuilderPhoneNumber() - mergeWith(builder.parseFrom(input).build())} - fun getSize(): Int { - var size = 0 - size += WireFormat.getStringSize(1, number) - size += WireFormat.getEnumSize(2, type.ord) - return size - } - } - - - fun writeTo (output: CodedOutputStream): Unit { - output.writeString (1, name) - output.writeInt32 (2, id) - output.writeString (3, email) - if (phones.size > 0) { - output.writeTag(4, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - run { - var arraySize = 0 - for (item in phones) { - arraySize += item.getSize() + WireFormat.getTagSize(4, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(item.getSize()) - } - arrayByteSize += arraySize - } - output.writeInt32NoTag(arrayByteSize) - for (item in phones) { - output.writeTag(4, WireType.LENGTH_DELIMITED) - output.writeInt32NoTag(item.getSize()) - item.writeTo(output) - } - } - output.writeBytes (5, someBytes) - } - - class BuilderPerson constructor (name: kotlin.String = "", id: Int = 0, email: kotlin.String = "", phones: MutableList = mutableListOf(), someBytes: ByteArray = ByteArray(0)) { - var name : kotlin.String - private set - fun setName(value: kotlin.String): BuilderPerson { - name = value - return this - } - - var id : Int - private set - fun setId(value: Int): BuilderPerson { - id = value - return this - } - - var email : kotlin.String - private set - fun setEmail(value: kotlin.String): BuilderPerson { - email = value - return this - } - - var phones : MutableList - private set - fun setPhones(value: MutableList ): BuilderPerson { - phones = value - return this - } - fun setPhoneNumber(index: Int, value: PhoneNumber): BuilderPerson { - phones[index] = value - return this - } - fun addPhoneNumber(value: PhoneNumber): BuilderPerson { - phones.add(value) - return this - } - fun addAllPhoneNumber(value: Iterable): BuilderPerson { - for (item in value) { - phones.add(item) - } - return this - } - - var someBytes : ByteArray - private set - fun setSomeBytes(value: ByteArray): BuilderPerson { - someBytes = value - return this - } - - - init { - this.name = name - this.id = id - this.email = email - this.phones = phones - this.someBytes = someBytes - } - - fun readFrom (input: CodedInputStream): BuilderPerson { - name = input.readString(1) - id = input.readInt32(2) - email = input.readString(3) - val tag = input.readTag(4, WireType.LENGTH_DELIMITED) - val expectedSize = input.readInt32NoTag() - var readSize = 0 - while(readSize != expectedSize) { - val tmp: PhoneNumber.BuilderPhoneNumber = PhoneNumber.BuilderPhoneNumber() - input.readTag(4, WireType.LENGTH_DELIMITED) - val expectedSize = input.readInt32NoTag() - tmp.readFrom(input) - if (expectedSize != tmp.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${tmp.getSize()}") } - readSize += tmp.getSize() + WireFormat.getTagSize(4, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(tmp.getSize()) - phones.add(tmp.build()) - } - someBytes = input.readBytes(5) - return this - } - - fun build(): Person { - return Person(name, id, email, phones, someBytes) - } - - fun parseFieldFrom(input: CodedInputStream): Boolean { - if (input.isAtEnd()) { return false } - val tag = input.readInt32NoTag() - if (tag == 0) { return false } - val fieldNumber = WireFormat.getTagFieldNumber(tag) - val wireType = WireFormat.getTagWireType(tag) - when(fieldNumber) { - 1 -> name = input.readStringNoTag() - 2 -> id = input.readInt32NoTag() - 3 -> email = input.readStringNoTag() - 4 -> { - val expectedSize = input.readInt32NoTag() - var readSize = 0 - while(readSize != expectedSize) { - val tmp: PhoneNumber.BuilderPhoneNumber = PhoneNumber.BuilderPhoneNumber() - input.readTag(4, WireType.LENGTH_DELIMITED) - val expectedSize = input.readInt32NoTag() - tmp.readFrom(input) - if (expectedSize != tmp.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${tmp.getSize()}") } - readSize += tmp.getSize() + WireFormat.getTagSize(4, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(tmp.getSize()) - phones.add(tmp.build()) - } - } - 5 -> someBytes = input.readBytesNoTag() - } - return true} - fun parseFrom(input: CodedInputStream): BuilderPerson { - while(parseFieldFrom(input)) {} - return this - } - fun getSize(): Int { - var size = 0 - size += WireFormat.getStringSize(1, name) - size += WireFormat.getInt32Size(2, id) - size += WireFormat.getStringSize(3, email) - run { - var arraySize = 0 - for (item in phones) { - arraySize += item.getSize() + WireFormat.getTagSize(4, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(item.getSize()) - } - size += arraySize + WireFormat.getTagSize(4, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(arraySize) - } - size += WireFormat.getBytesSize(5, someBytes) - return size - } - } - - - fun mergeWith (other: Person) { - name = other.name - id = other.id - email = other.email - phones.addAll(other.phones) - someBytes.plus(other.someBytes) - } - - fun mergeFrom (input: CodedInputStream) { - val builder = BuilderPerson() - mergeWith(builder.parseFrom(input).build())} - fun getSize(): Int { - var size = 0 - size += WireFormat.getStringSize(1, name) - size += WireFormat.getInt32Size(2, id) - size += WireFormat.getStringSize(3, email) - run { - var arraySize = 0 - for (item in phones) { - arraySize += item.getSize() + WireFormat.getTagSize(4, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(item.getSize()) - } - size += arraySize + WireFormat.getTagSize(4, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(arraySize) - } - size += WireFormat.getBytesSize(5, someBytes) - return size - } -} - - -class AddressBook private constructor (people: MutableList = mutableListOf()) { - var people : MutableList - private set - - - init { - this.people = people - } - - fun writeTo (output: CodedOutputStream): Unit { - if (people.size > 0) { - output.writeTag(1, WireType.LENGTH_DELIMITED) - var arrayByteSize = 0 - run { - var arraySize = 0 - for (item in people) { - arraySize += item.getSize() + WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(item.getSize()) - } - arrayByteSize += arraySize - } - output.writeInt32NoTag(arrayByteSize) - for (item in people) { - output.writeTag(1, WireType.LENGTH_DELIMITED) - output.writeInt32NoTag(item.getSize()) - item.writeTo(output) - } - } - } - - class BuilderAddressBook constructor (people: MutableList = mutableListOf()) { - var people : MutableList - private set - fun setPeople(value: MutableList ): BuilderAddressBook { - people = value - return this - } - fun setPerson(index: Int, value: Person): BuilderAddressBook { - people[index] = value - return this - } - fun addPerson(value: Person): BuilderAddressBook { - people.add(value) - return this - } - fun addAllPerson(value: Iterable): BuilderAddressBook { - for (item in value) { - people.add(item) - } - return this - } - - - init { - this.people = people - } - - fun readFrom (input: CodedInputStream): BuilderAddressBook { - val tag = input.readTag(1, WireType.LENGTH_DELIMITED) - val expectedSize = input.readInt32NoTag() - var readSize = 0 - while(readSize != expectedSize) { - val tmp: Person.BuilderPerson = Person.BuilderPerson() - input.readTag(1, WireType.LENGTH_DELIMITED) - val expectedSize = input.readInt32NoTag() - tmp.readFrom(input) - if (expectedSize != tmp.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${tmp.getSize()}") } - readSize += tmp.getSize() + WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(tmp.getSize()) - people.add(tmp.build()) - } - return this - } - - fun build(): AddressBook { - return AddressBook(people) - } - - fun parseFieldFrom(input: CodedInputStream): Boolean { - if (input.isAtEnd()) { return false } - val tag = input.readInt32NoTag() - if (tag == 0) { return false } - val fieldNumber = WireFormat.getTagFieldNumber(tag) - val wireType = WireFormat.getTagWireType(tag) - when(fieldNumber) { - 1 -> { - val expectedSize = input.readInt32NoTag() - var readSize = 0 - while(readSize != expectedSize) { - val tmp: Person.BuilderPerson = Person.BuilderPerson() - input.readTag(1, WireType.LENGTH_DELIMITED) - val expectedSize = input.readInt32NoTag() - tmp.readFrom(input) - if (expectedSize != tmp.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${tmp.getSize()}") } - readSize += tmp.getSize() + WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(tmp.getSize()) - people.add(tmp.build()) - } - } - } - return true} - fun parseFrom(input: CodedInputStream): BuilderAddressBook { - while(parseFieldFrom(input)) {} - return this - } - fun getSize(): Int { - var size = 0 - run { - var arraySize = 0 - for (item in people) { - arraySize += item.getSize() + WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(item.getSize()) - } - size += arraySize + WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(arraySize) - } - return size - } - } - - - fun mergeWith (other: AddressBook) { - people.addAll(other.people) - } - - fun mergeFrom (input: CodedInputStream) { - val builder = BuilderAddressBook() - mergeWith(builder.parseFrom(input).build())} - fun getSize(): Int { - var size = 0 - run { - var arraySize = 0 - for (item in people) { - arraySize += item.getSize() + WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(item.getSize()) - } - size += arraySize + WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(arraySize) - } - return size - } -} - - diff --git a/proto/compiler/src/TestAddressbook.kt b/proto/compiler/src/TestAddressbook.kt new file mode 100644 index 00000000000..72101a2abb0 --- /dev/null +++ b/proto/compiler/src/TestAddressbook.kt @@ -0,0 +1,54 @@ +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream + +/** + * Created by user on 7/8/16. + */ +object AddressbookTests { + fun testMessageSerialization() { + // Messages work only with CodedStream classes, provided by ProtoKot-runtime library. + // One can create CodedStream passing any instance of corresponding Stream from Java's library. + val s = ByteArrayOutputStream() + val outs = CodedOutputStream(s) + + // All messages are immutable. Use Builders for creating new messages + val msg = Person.BuilderPerson() + .setEmail("wtf@dasda.com") // all setters return this builder, so you could chain modifiers in LINQ-style + .setId(42) + .setName("John Doe") + .addPhoneNumber(// repeated fields stored as Array<>, so use arrayOf() for creating repeated fields + Person.PhoneNumber.BuilderPhoneNumber() + .setNumber("342143-23423-42") + .setType(Person.PhoneType.HOME) + .build() + ) + .addPhoneNumber( + Person.PhoneNumber.BuilderPhoneNumber() + .setNumber("8-800-555-35-35") + .setType(Person.PhoneType.WORK) + .build() + ) + .build() // don't forget to call build() to produce message + msg.writeTo(outs) + + // Now let's use output stream as input to read our message from it! + var ins = CodedInputStream(ByteArrayInputStream(s.toByteArray())) + + // Create default instance of message + var readMsg = Person.BuilderPerson().build() + // Read in that message data from input stream. + readMsg.mergeFrom(ins) + + // Note, that currently mergeFrom is the only way to mutate instance of message. + // Don't rely on it, probably mergeFrom will be refactored lately to guarantee full immutability of mesages. + + // Better way to read a message: + ins = CodedInputStream(ByteArrayInputStream(s.toByteArray())) + readMsg = Person.BuilderPerson().readFrom(ins).build() + assert(msg == readMsg) + } +} +fun main(args: Array) { + AddressbookTests.testMessageSerialization() + println("OK") +} diff --git a/proto/compiler/src/TestMessages.kt b/proto/compiler/src/TestMessages.kt deleted file mode 100644 index ffe8e78295c..00000000000 --- a/proto/compiler/src/TestMessages.kt +++ /dev/null @@ -1,54 +0,0 @@ -import java.io.ByteArrayInputStream -import java.io.ByteArrayOutputStream - -/** - * Created by user on 7/8/16. - */ - -fun testMessageSerialization() { - // Messages work only with CodedStream classes, provided by ProtoKot-runtime library. - // One can create CodedStream passing any instance of corresponding Stream from Java's library. - val s = ByteArrayOutputStream() - val outs = CodedOutputStream(s) - - // All messages are immutable. Use Builders for creating new messages - val msg = Person.BuilderPerson() - .setEmail("wtf@dasda.com") // all setters return this builder, so you could chain modifiers in LINQ-style - .setId(42) - .setName("John Doe") - .addPhoneNumber( // repeated fields stored as Array<>, so use arrayOf() for creating repeated fields - Person.PhoneNumber.BuilderPhoneNumber() - .setNumber("342143-23423-42") - .setType(Person.PhoneType.HOME) - .build() - ) - .addPhoneNumber( - Person.PhoneNumber.BuilderPhoneNumber() - .setNumber("8-800-555-35-35") - .setType(Person.PhoneType.WORK) - .build() - ) - .build() // don't forget to call build() to produce message - msg.writeTo(outs) - - // Now let's use output stream as input to read our message from it! - var ins = CodedInputStream(ByteArrayInputStream(s.toByteArray())) - - // Create default instance of message - var readMsg = Person.BuilderPerson().build() - // Read in that message data from input stream. - readMsg.mergeFrom(ins) - - // Note, that currently mergeFrom is the only way to mutate instance of message. - // Don't rely on it, probably mergeFrom will be refactored lately to guarantee full immutability of mesages. - - // Better way to read a message: - ins = CodedInputStream(ByteArrayInputStream(s.toByteArray())) - readMsg = Person.BuilderPerson().readFrom(ins).build() - assert(msg == readMsg) -} - -fun main(args: Array) { - testMessageSerialization() - println("OK") -} diff --git a/proto/compiler/src/TestNestedMsg.kt b/proto/compiler/src/TestNestedMsg.kt new file mode 100644 index 00000000000..a445a5bd1dc --- /dev/null +++ b/proto/compiler/src/TestNestedMsg.kt @@ -0,0 +1,37 @@ +import java.io.ByteArrayOutputStream + +/** + * Created by user on 7/18/16. + */ + +object NestedMsgTests { + val msg1 = Level1.BuilderLevel1() + .setField1( + Level1.Level2.BuilderLevel2() + .setField2( + Level1.Level2.Level3.BuilderLevel3() + .setField3( + Level1.Level2.Level3.Level4.BuilderLevel4() + .setField4("Hello!") + .build() + ) + .build() + ) + .build() + ) + .build() + + fun testMessageSerialization() { + val s = ByteArrayOutputStream() + val output = CodedOutputStream(s) + + msg1.writeTo(output) + + val readMsg = Level1.BuilderLevel1().build() + + } +} +fun main(args: Array) { + NestedMsgTests.testMessageSerialization() + println("OK") +} diff --git a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/addressbook.kt b/proto/compiler/src/addressbook.kt similarity index 86% rename from proto/compiler/google/src/google/protobuf/compiler/kotlin/test/addressbook.kt rename to proto/compiler/src/addressbook.kt index c4518b2454b..586aee2f031 100644 --- a/proto/compiler/google/src/google/protobuf/compiler/kotlin/test/addressbook.kt +++ b/proto/compiler/src/addressbook.kt @@ -38,7 +38,7 @@ class Person private constructor (name: kotlin.String = "", id: Int = 0, email: } } } - class PhoneNumber private constructor (number: kotlin.String = "", type: PhoneType = PhoneType.fromIntToPhoneType(0)) { + class PhoneNumber private constructor (number: kotlin.String = "", type: PhoneType = Person.PhoneType.fromIntToPhoneType(0)) { var number : kotlin.String private set @@ -56,17 +56,17 @@ class Person private constructor (name: kotlin.String = "", id: Int = 0, email: output.writeEnum (2, type.ord) } - class BuilderPhoneNumber constructor (number: kotlin.String = "", type: PhoneType = PhoneType.fromIntToPhoneType(0)) { + class BuilderPhoneNumber constructor (number: kotlin.String = "", type: PhoneType = Person.PhoneType.fromIntToPhoneType(0)) { var number : kotlin.String private set - fun setNumber(value: kotlin.String): BuilderPhoneNumber { + fun setNumber(value: kotlin.String): Person.PhoneNumber.BuilderPhoneNumber { number = value return this } var type : PhoneType private set - fun setType(value: PhoneType): BuilderPhoneNumber { + fun setType(value: PhoneType): Person.PhoneNumber.BuilderPhoneNumber { type = value return this } @@ -77,7 +77,7 @@ class Person private constructor (name: kotlin.String = "", id: Int = 0, email: this.type = type } - fun readFrom (input: CodedInputStream): BuilderPhoneNumber { + fun readFrom (input: CodedInputStream): Person.PhoneNumber.BuilderPhoneNumber { number = input.readString(1) type = PhoneType.fromIntToPhoneType(input.readEnum(2)) return this @@ -98,7 +98,7 @@ class Person private constructor (name: kotlin.String = "", id: Int = 0, email: 2 -> type = PhoneType.fromIntToPhoneType(input.readEnumNoTag()) } return true} - fun parseFrom(input: CodedInputStream): BuilderPhoneNumber { + fun parseFrom(input: CodedInputStream): Person.PhoneNumber.BuilderPhoneNumber { while(parseFieldFrom(input)) {} return this } @@ -117,7 +117,7 @@ class Person private constructor (name: kotlin.String = "", id: Int = 0, email: } fun mergeFrom (input: CodedInputStream) { - val builder = BuilderPhoneNumber() + val builder = Person.PhoneNumber.BuilderPhoneNumber() mergeWith(builder.parseFrom(input).build())} fun getSize(): Int { var size = 0 @@ -155,40 +155,40 @@ class Person private constructor (name: kotlin.String = "", id: Int = 0, email: class BuilderPerson constructor (name: kotlin.String = "", id: Int = 0, email: kotlin.String = "", phones: MutableList = mutableListOf(), someBytes: ByteArray = ByteArray(0)) { var name : kotlin.String private set - fun setName(value: kotlin.String): BuilderPerson { + fun setName(value: kotlin.String): Person.BuilderPerson { name = value return this } var id : Int private set - fun setId(value: Int): BuilderPerson { + fun setId(value: Int): Person.BuilderPerson { id = value return this } var email : kotlin.String private set - fun setEmail(value: kotlin.String): BuilderPerson { + fun setEmail(value: kotlin.String): Person.BuilderPerson { email = value return this } var phones : MutableList private set - fun setPhones(value: MutableList ): BuilderPerson { + fun setPhones(value: MutableList ): Person.BuilderPerson { phones = value return this } - fun setPhoneNumber(index: Int, value: PhoneNumber): BuilderPerson { + fun setPhoneNumber(index: Int, value: PhoneNumber): Person.PhoneNumber.BuilderPhoneNumber { phones[index] = value return this } - fun addPhoneNumber(value: PhoneNumber): BuilderPerson { + fun addPhoneNumber(value: PhoneNumber): Person.PhoneNumber.BuilderPhoneNumber { phones.add(value) return this } - fun addAllPhoneNumber(value: Iterable): BuilderPerson { + fun addAllPhoneNumber(value: Iterable): Person.PhoneNumber.BuilderPhoneNumber { for (item in value) { phones.add(item) } @@ -197,7 +197,7 @@ class Person private constructor (name: kotlin.String = "", id: Int = 0, email: var someBytes : ByteArray private set - fun setSomeBytes(value: ByteArray): BuilderPerson { + fun setSomeBytes(value: ByteArray): Person.BuilderPerson { someBytes = value return this } @@ -211,7 +211,7 @@ class Person private constructor (name: kotlin.String = "", id: Int = 0, email: this.someBytes = someBytes } - fun readFrom (input: CodedInputStream): BuilderPerson { + fun readFrom (input: CodedInputStream): Person.BuilderPerson { name = input.readString(1) id = input.readInt32(2) email = input.readString(3) @@ -222,7 +222,7 @@ class Person private constructor (name: kotlin.String = "", id: Int = 0, email: val tmp: PhoneNumber.BuilderPhoneNumber = PhoneNumber.BuilderPhoneNumber() input.readTag(4, WireType.LENGTH_DELIMITED) val expectedSize = input.readInt32NoTag() - tmp.readFrom(input) + tmp.mergeFrom(input) if (expectedSize != tmp.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${tmp.getSize()}") } readSize += tmp.getSize() + WireFormat.getTagSize(4, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(tmp.getSize()) phones.add(tmp.build()) @@ -252,7 +252,7 @@ class Person private constructor (name: kotlin.String = "", id: Int = 0, email: val tmp: PhoneNumber.BuilderPhoneNumber = PhoneNumber.BuilderPhoneNumber() input.readTag(4, WireType.LENGTH_DELIMITED) val expectedSize = input.readInt32NoTag() - tmp.readFrom(input) + tmp.mergeFrom(input) if (expectedSize != tmp.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${tmp.getSize()}") } readSize += tmp.getSize() + WireFormat.getTagSize(4, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(tmp.getSize()) phones.add(tmp.build()) @@ -261,7 +261,7 @@ class Person private constructor (name: kotlin.String = "", id: Int = 0, email: 5 -> someBytes = input.readBytesNoTag() } return true} - fun parseFrom(input: CodedInputStream): BuilderPerson { + fun parseFrom(input: CodedInputStream): Person.BuilderPerson { while(parseFieldFrom(input)) {} return this } @@ -292,7 +292,7 @@ class Person private constructor (name: kotlin.String = "", id: Int = 0, email: } fun mergeFrom (input: CodedInputStream) { - val builder = BuilderPerson() + val builder = Person.BuilderPerson() mergeWith(builder.parseFrom(input).build())} fun getSize(): Int { var size = 0 @@ -344,19 +344,19 @@ class AddressBook private constructor (people: MutableList = mutableLi class BuilderAddressBook constructor (people: MutableList = mutableListOf()) { var people : MutableList private set - fun setPeople(value: MutableList ): BuilderAddressBook { + fun setPeople(value: MutableList ): AddressBook.BuilderAddressBook { people = value return this } - fun setPerson(index: Int, value: Person): BuilderAddressBook { + fun setPerson(index: Int, value: Person): Person.BuilderPerson { people[index] = value return this } - fun addPerson(value: Person): BuilderAddressBook { + fun addPerson(value: Person): Person.BuilderPerson { people.add(value) return this } - fun addAllPerson(value: Iterable): BuilderAddressBook { + fun addAllPerson(value: Iterable): Person.BuilderPerson { for (item in value) { people.add(item) } @@ -368,7 +368,7 @@ class AddressBook private constructor (people: MutableList = mutableLi this.people = people } - fun readFrom (input: CodedInputStream): BuilderAddressBook { + fun readFrom (input: CodedInputStream): AddressBook.BuilderAddressBook { val tag = input.readTag(1, WireType.LENGTH_DELIMITED) val expectedSize = input.readInt32NoTag() var readSize = 0 @@ -376,7 +376,7 @@ class AddressBook private constructor (people: MutableList = mutableLi val tmp: Person.BuilderPerson = Person.BuilderPerson() input.readTag(1, WireType.LENGTH_DELIMITED) val expectedSize = input.readInt32NoTag() - tmp.readFrom(input) + tmp.mergeFrom(input) if (expectedSize != tmp.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${tmp.getSize()}") } readSize += tmp.getSize() + WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(tmp.getSize()) people.add(tmp.build()) @@ -402,7 +402,7 @@ class AddressBook private constructor (people: MutableList = mutableLi val tmp: Person.BuilderPerson = Person.BuilderPerson() input.readTag(1, WireType.LENGTH_DELIMITED) val expectedSize = input.readInt32NoTag() - tmp.readFrom(input) + tmp.mergeFrom(input) if (expectedSize != tmp.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${tmp.getSize()}") } readSize += tmp.getSize() + WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(tmp.getSize()) people.add(tmp.build()) @@ -410,7 +410,7 @@ class AddressBook private constructor (people: MutableList = mutableLi } } return true} - fun parseFrom(input: CodedInputStream): BuilderAddressBook { + fun parseFrom(input: CodedInputStream): AddressBook.BuilderAddressBook { while(parseFieldFrom(input)) {} return this } @@ -433,7 +433,7 @@ class AddressBook private constructor (people: MutableList = mutableLi } fun mergeFrom (input: CodedInputStream) { - val builder = BuilderAddressBook() + val builder = AddressBook.BuilderAddressBook() mergeWith(builder.parseFrom(input).build())} fun getSize(): Int { var size = 0 diff --git a/proto/compiler/src/nested-msg.kt b/proto/compiler/src/nested-msg.kt new file mode 100644 index 00000000000..5659b2ff539 --- /dev/null +++ b/proto/compiler/src/nested-msg.kt @@ -0,0 +1,315 @@ +class Level1 private constructor (field1: Level2 = Level1.Level2.BuilderLevel2().build()) { + var field1 : Level2 + private set + + + init { + this.field1 = field1 + } + class Level2 private constructor (field2: Level3 = Level1.Level2.Level3.BuilderLevel3().build()) { + var field2 : Level3 + private set + + + init { + this.field2 = field2 + } + class Level3 private constructor (field3: Level4 = Level1.Level2.Level3.Level4.BuilderLevel4().build()) { + var field3 : Level4 + private set + + + init { + this.field3 = field3 + } + class Level4 private constructor (field4: kotlin.String = "") { + var field4 : kotlin.String + private set + + + init { + this.field4 = field4 + } + + fun writeTo (output: CodedOutputStream): Unit { + output.writeString (4, field4) + } + + class BuilderLevel4 constructor (field4: kotlin.String = "") { + var field4 : kotlin.String + private set + fun setField4(value: kotlin.String): Level1.Level2.Level3.Level4.BuilderLevel4 { + field4 = value + return this + } + + + init { + this.field4 = field4 + } + + fun readFrom (input: CodedInputStream): Level1.Level2.Level3.Level4.BuilderLevel4 { + field4 = input.readString(4) + return this +} + + fun build(): Level4 { + return Level4(field4) + } + + fun parseFieldFrom(input: CodedInputStream): Boolean { + if (input.isAtEnd()) { return false } + val tag = input.readInt32NoTag() + if (tag == 0) { return false } + val fieldNumber = WireFormat.getTagFieldNumber(tag) + val wireType = WireFormat.getTagWireType(tag) + when(fieldNumber) { + 4 -> field4 = input.readStringNoTag() + } + return true} + fun parseFrom(input: CodedInputStream): Level1.Level2.Level3.Level4.BuilderLevel4 { + while(parseFieldFrom(input)) {} + return this + } + fun getSize(): Int { + var size = 0 + size += WireFormat.getStringSize(4, field4) + return size + } + } + + + fun mergeWith (other: Level4) { + field4 = other.field4 + } + + fun mergeFrom (input: CodedInputStream) { + val builder = Level1.Level2.Level3.Level4.BuilderLevel4() + mergeWith(builder.parseFrom(input).build())} + fun getSize(): Int { + var size = 0 + size += WireFormat.getStringSize(4, field4) + return size + } + } + + + fun writeTo (output: CodedOutputStream): Unit { + output.writeTag(3, WireType.LENGTH_DELIMITED) + output.writeInt32NoTag(field3.getSize()) + field3.writeTo(output) + } + + class BuilderLevel3 constructor (field3: Level4 = Level1.Level2.Level3.Level4.BuilderLevel4().build()) { + var field3 : Level4 + private set + fun setField3(value: Level4): Level1.Level2.Level3.BuilderLevel3 { + field3 = value + return this + } + + + init { + this.field3 = field3 + } + + fun readFrom (input: CodedInputStream): Level1.Level2.Level3.BuilderLevel3 { + input.readTag(3, WireType.LENGTH_DELIMITED) + val expectedSize = input.readInt32NoTag() + field3.mergeFrom(input) + if (expectedSize != field3.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${field3.getSize()}") } + return this +} + + fun build(): Level3 { + return Level3(field3) + } + + fun parseFieldFrom(input: CodedInputStream): Boolean { + if (input.isAtEnd()) { return false } + val tag = input.readInt32NoTag() + if (tag == 0) { return false } + val fieldNumber = WireFormat.getTagFieldNumber(tag) + val wireType = WireFormat.getTagWireType(tag) + when(fieldNumber) { + 3 -> { + input.readTag(3, WireType.LENGTH_DELIMITED) + val expectedSize = input.readInt32NoTag() + field3.mergeFrom(input) + if (expectedSize != field3.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${field3.getSize()}") } + } + } + return true} + fun parseFrom(input: CodedInputStream): Level1.Level2.Level3.BuilderLevel3 { + while(parseFieldFrom(input)) {} + return this + } + fun getSize(): Int { + var size = 0 + size += field3.getSize() + WireFormat.getTagSize(3, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(field3.getSize()) + return size + } + } + + + fun mergeWith (other: Level3) { + field3 = other.field3 + } + + fun mergeFrom (input: CodedInputStream) { + val builder = Level1.Level2.Level3.BuilderLevel3() + mergeWith(builder.parseFrom(input).build())} + fun getSize(): Int { + var size = 0 + size += field3.getSize() + WireFormat.getTagSize(3, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(field3.getSize()) + return size + } + } + + + fun writeTo (output: CodedOutputStream): Unit { + output.writeTag(2, WireType.LENGTH_DELIMITED) + output.writeInt32NoTag(field2.getSize()) + field2.writeTo(output) + } + + class BuilderLevel2 constructor (field2: Level3 = Level1.Level2.Level3.BuilderLevel3().build()) { + var field2 : Level3 + private set + fun setField2(value: Level3): Level1.Level2.BuilderLevel2 { + field2 = value + return this + } + + + init { + this.field2 = field2 + } + + fun readFrom (input: CodedInputStream): Level1.Level2.BuilderLevel2 { + input.readTag(2, WireType.LENGTH_DELIMITED) + val expectedSize = input.readInt32NoTag() + field2.mergeFrom(input) + if (expectedSize != field2.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${field2.getSize()}") } + return this +} + + fun build(): Level2 { + return Level2(field2) + } + + fun parseFieldFrom(input: CodedInputStream): Boolean { + if (input.isAtEnd()) { return false } + val tag = input.readInt32NoTag() + if (tag == 0) { return false } + val fieldNumber = WireFormat.getTagFieldNumber(tag) + val wireType = WireFormat.getTagWireType(tag) + when(fieldNumber) { + 2 -> { + input.readTag(2, WireType.LENGTH_DELIMITED) + val expectedSize = input.readInt32NoTag() + field2.mergeFrom(input) + if (expectedSize != field2.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${field2.getSize()}") } + } + } + return true} + fun parseFrom(input: CodedInputStream): Level1.Level2.BuilderLevel2 { + while(parseFieldFrom(input)) {} + return this + } + fun getSize(): Int { + var size = 0 + size += field2.getSize() + WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(field2.getSize()) + return size + } + } + + + fun mergeWith (other: Level2) { + field2 = other.field2 + } + + fun mergeFrom (input: CodedInputStream) { + val builder = Level1.Level2.BuilderLevel2() + mergeWith(builder.parseFrom(input).build())} + fun getSize(): Int { + var size = 0 + size += field2.getSize() + WireFormat.getTagSize(2, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(field2.getSize()) + return size + } + } + + + fun writeTo (output: CodedOutputStream): Unit { + output.writeTag(1, WireType.LENGTH_DELIMITED) + output.writeInt32NoTag(field1.getSize()) + field1.writeTo(output) + } + + class BuilderLevel1 constructor (field1: Level2 = Level1.Level2.BuilderLevel2().build()) { + var field1 : Level2 + private set + fun setField1(value: Level2): Level1.BuilderLevel1 { + field1 = value + return this + } + + + init { + this.field1 = field1 + } + + fun readFrom (input: CodedInputStream): Level1.BuilderLevel1 { + input.readTag(1, WireType.LENGTH_DELIMITED) + val expectedSize = input.readInt32NoTag() + field1.mergeFrom(input) + if (expectedSize != field1.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${field1.getSize()}") } + return this +} + + fun build(): Level1 { + return Level1(field1) + } + + fun parseFieldFrom(input: CodedInputStream): Boolean { + if (input.isAtEnd()) { return false } + val tag = input.readInt32NoTag() + if (tag == 0) { return false } + val fieldNumber = WireFormat.getTagFieldNumber(tag) + val wireType = WireFormat.getTagWireType(tag) + when(fieldNumber) { + 1 -> { + input.readTag(1, WireType.LENGTH_DELIMITED) + val expectedSize = input.readInt32NoTag() + field1.mergeFrom(input) + if (expectedSize != field1.getSize()) { throw InvalidProtocolBufferException ("Expected size ${expectedSize} got ${field1.getSize()}") } + } + } + return true} + fun parseFrom(input: CodedInputStream): Level1.BuilderLevel1 { + while(parseFieldFrom(input)) {} + return this + } + fun getSize(): Int { + var size = 0 + size += field1.getSize() + WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(field1.getSize()) + return size + } + } + + + fun mergeWith (other: Level1) { + field1 = other.field1 + } + + fun mergeFrom (input: CodedInputStream) { + val builder = Level1.BuilderLevel1() + mergeWith(builder.parseFrom(input).build())} + fun getSize(): Int { + var size = 0 + size += field1.getSize() + WireFormat.getTagSize(1, WireType.LENGTH_DELIMITED) + WireFormat.getVarint32Size(field1.getSize()) + return size + } +} + +