Micha Kops avatar Micha Kops committed 9b7b0e8

Google Protocol Buffers Tutorial Sources added

Comments (0)

Files changed (6)

protocol-buffer-sample/.classpath

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

protocol-buffer-sample/.project

+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>protocol-buffer-sample</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+	</natures>
+</projectDescription>

protocol-buffer-sample/pom.xml

+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>com.hascode.examples.protocol-buffer</groupId>
+	<artifactId>protocol-buffer-sample</artifactId>
+	<version>0.0.1-SNAPSHOT</version>
+	<dependencies>
+		<dependency>
+			<groupId>com.google.protobuf</groupId>
+			<artifactId>protobuf-java</artifactId>
+			<version>2.3.0</version>
+			<scope>compile</scope>
+		</dependency>
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<artifactId>maven-antrun-plugin</artifactId>
+				<executions>
+					<execution>
+						<id>generate-sources</id>
+						<phase>generate-sources</phase>
+						<configuration>
+							<tasks>
+								<exec executable="protoc">
+									<arg value="--java_out=src/main/java" />
+									<arg value="src/main/protobuf/todo_provider.proto" />
+								</exec>
+							</tasks>
+							<sourceRoot>src/main/java</sourceRoot>
+						</configuration>
+						<goals>
+							<goal>run</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.0.2</version>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+				</configuration>
+			</plugin>
+
+		</plugins>
+	</build>
+
+
+</project>

protocol-buffer-sample/src/main/java/com/hascode/examples/protocol_buffer/Main.java

+package com.hascode.examples.protocol_buffer;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import com.hascode.examples.protocol_buffer.TodoProvider.Todo;
+import com.hascode.examples.protocol_buffer.TodoProvider.Todos;
+import com.hascode.examples.protocol_buffer.TodoProvider.Todo.Priority;
+
+public class Main {
+	public static void main(String[] args) throws IOException {
+		// write some todos to file
+		Todo todo1 = Todo.newBuilder().setTitle("Do the laundry").setPriority(
+				Priority.MEDIUM).build();
+		Todo todo2 = Todo.newBuilder().setTitle("Write the tutorial")
+				.setPriority(Priority.HIGH).build();
+		Todos todos = Todos.newBuilder().addTodos(todo1).addTodos(todo2)
+				.build();
+		FileOutputStream os = new FileOutputStream("/tmp/todo.data");
+		todos.writeTo(os);
+		os.close();
+
+		// read todos from file
+		FileInputStream is = new FileInputStream("/tmp/todo.data");
+		Todos.newBuilder().build();
+		Todos newTodos = Todos.parseFrom(is);
+		for (Todo todo : newTodos.getTodosList()) {
+			System.out.println("Reading todo - title: " + todo.getTitle()
+					+ " priority: " + todo.getPriority());
+		}
+	}
+}

protocol-buffer-sample/src/main/java/com/hascode/examples/protocol_buffer/TodoProvider.java

+// Generated by the protocol buffer compiler.  DO NOT EDIT!
+// source: src/main/protobuf/todo_provider.proto
+
+package com.hascode.examples.protocol_buffer;
+
+public final class TodoProvider {
+  private TodoProvider() {}
+  public static void registerAllExtensions(
+      com.google.protobuf.ExtensionRegistry registry) {
+  }
+  public static final class Todo extends
+      com.google.protobuf.GeneratedMessage {
+    // Use Todo.newBuilder() to construct.
+    private Todo() {
+      initFields();
+    }
+    private Todo(boolean noInit) {}
+    
+    private static final Todo defaultInstance;
+    public static Todo getDefaultInstance() {
+      return defaultInstance;
+    }
+    
+    public Todo getDefaultInstanceForType() {
+      return defaultInstance;
+    }
+    
+    public static final com.google.protobuf.Descriptors.Descriptor
+        getDescriptor() {
+      return com.hascode.examples.protocol_buffer.TodoProvider.internal_static_examples_Todo_descriptor;
+    }
+    
+    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+        internalGetFieldAccessorTable() {
+      return com.hascode.examples.protocol_buffer.TodoProvider.internal_static_examples_Todo_fieldAccessorTable;
+    }
+    
+    public enum Priority
+        implements com.google.protobuf.ProtocolMessageEnum {
+      NORMAL(0, 1),
+      MEDIUM(1, 2),
+      HIGH(2, 3),
+      ;
+      
+      
+      public final int getNumber() { return value; }
+      
+      public static Priority valueOf(int value) {
+        switch (value) {
+          case 1: return NORMAL;
+          case 2: return MEDIUM;
+          case 3: return HIGH;
+          default: return null;
+        }
+      }
+      
+      public static com.google.protobuf.Internal.EnumLiteMap<Priority>
+          internalGetValueMap() {
+        return internalValueMap;
+      }
+      private static com.google.protobuf.Internal.EnumLiteMap<Priority>
+          internalValueMap =
+            new com.google.protobuf.Internal.EnumLiteMap<Priority>() {
+              public Priority findValueByNumber(int number) {
+                return Priority.valueOf(number)
+      ;        }
+            };
+      
+      public final com.google.protobuf.Descriptors.EnumValueDescriptor
+          getValueDescriptor() {
+        return getDescriptor().getValues().get(index);
+      }
+      public final com.google.protobuf.Descriptors.EnumDescriptor
+          getDescriptorForType() {
+        return getDescriptor();
+      }
+      public static final com.google.protobuf.Descriptors.EnumDescriptor
+          getDescriptor() {
+        return com.hascode.examples.protocol_buffer.TodoProvider.Todo.getDescriptor().getEnumTypes().get(0);
+      }
+      
+      private static final Priority[] VALUES = {
+        NORMAL, MEDIUM, HIGH, 
+      };
+      public static Priority valueOf(
+          com.google.protobuf.Descriptors.EnumValueDescriptor desc) {
+        if (desc.getType() != getDescriptor()) {
+          throw new java.lang.IllegalArgumentException(
+            "EnumValueDescriptor is not for this type.");
+        }
+        return VALUES[desc.getIndex()];
+      }
+      private final int index;
+      private final int value;
+      private Priority(int index, int value) {
+        this.index = index;
+        this.value = value;
+      }
+      
+      static {
+        com.hascode.examples.protocol_buffer.TodoProvider.getDescriptor();
+      }
+      
+      // @@protoc_insertion_point(enum_scope:examples.Todo.Priority)
+    }
+    
+    // required string title = 1;
+    public static final int TITLE_FIELD_NUMBER = 1;
+    private boolean hasTitle;
+    private java.lang.String title_ = "";
+    public boolean hasTitle() { return hasTitle; }
+    public java.lang.String getTitle() { return title_; }
+    
+    // optional .examples.Todo.Priority priority = 2;
+    public static final int PRIORITY_FIELD_NUMBER = 2;
+    private boolean hasPriority;
+    private com.hascode.examples.protocol_buffer.TodoProvider.Todo.Priority priority_;
+    public boolean hasPriority() { return hasPriority; }
+    public com.hascode.examples.protocol_buffer.TodoProvider.Todo.Priority getPriority() { return priority_; }
+    
+    private void initFields() {
+      priority_ = com.hascode.examples.protocol_buffer.TodoProvider.Todo.Priority.NORMAL;
+    }
+    public final boolean isInitialized() {
+      if (!hasTitle) return false;
+      return true;
+    }
+    
+    public void writeTo(com.google.protobuf.CodedOutputStream output)
+                        throws java.io.IOException {
+      getSerializedSize();
+      if (hasTitle()) {
+        output.writeString(1, getTitle());
+      }
+      if (hasPriority()) {
+        output.writeEnum(2, getPriority().getNumber());
+      }
+      getUnknownFields().writeTo(output);
+    }
+    
+    private int memoizedSerializedSize = -1;
+    public int getSerializedSize() {
+      int size = memoizedSerializedSize;
+      if (size != -1) return size;
+    
+      size = 0;
+      if (hasTitle()) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeStringSize(1, getTitle());
+      }
+      if (hasPriority()) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeEnumSize(2, getPriority().getNumber());
+      }
+      size += getUnknownFields().getSerializedSize();
+      memoizedSerializedSize = size;
+      return size;
+    }
+    
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todo parseFrom(
+        com.google.protobuf.ByteString data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data).buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todo parseFrom(
+        com.google.protobuf.ByteString data,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data, extensionRegistry)
+               .buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todo parseFrom(byte[] data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data).buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todo parseFrom(
+        byte[] data,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data, extensionRegistry)
+               .buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todo parseFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input).buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todo parseFrom(
+        java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input, extensionRegistry)
+               .buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todo parseDelimitedFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      Builder builder = newBuilder();
+      if (builder.mergeDelimitedFrom(input)) {
+        return builder.buildParsed();
+      } else {
+        return null;
+      }
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todo parseDelimitedFrom(
+        java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws java.io.IOException {
+      Builder builder = newBuilder();
+      if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
+        return builder.buildParsed();
+      } else {
+        return null;
+      }
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todo parseFrom(
+        com.google.protobuf.CodedInputStream input)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input).buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todo parseFrom(
+        com.google.protobuf.CodedInputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input, extensionRegistry)
+               .buildParsed();
+    }
+    
+    public static Builder newBuilder() { return Builder.create(); }
+    public Builder newBuilderForType() { return newBuilder(); }
+    public static Builder newBuilder(com.hascode.examples.protocol_buffer.TodoProvider.Todo prototype) {
+      return newBuilder().mergeFrom(prototype);
+    }
+    public Builder toBuilder() { return newBuilder(this); }
+    
+    public static final class Builder extends
+        com.google.protobuf.GeneratedMessage.Builder<Builder> {
+      private com.hascode.examples.protocol_buffer.TodoProvider.Todo result;
+      
+      // Construct using com.hascode.examples.protocol_buffer.TodoProvider.Todo.newBuilder()
+      private Builder() {}
+      
+      private static Builder create() {
+        Builder builder = new Builder();
+        builder.result = new com.hascode.examples.protocol_buffer.TodoProvider.Todo();
+        return builder;
+      }
+      
+      protected com.hascode.examples.protocol_buffer.TodoProvider.Todo internalGetResult() {
+        return result;
+      }
+      
+      public Builder clear() {
+        if (result == null) {
+          throw new IllegalStateException(
+            "Cannot call clear() after build().");
+        }
+        result = new com.hascode.examples.protocol_buffer.TodoProvider.Todo();
+        return this;
+      }
+      
+      public Builder clone() {
+        return create().mergeFrom(result);
+      }
+      
+      public com.google.protobuf.Descriptors.Descriptor
+          getDescriptorForType() {
+        return com.hascode.examples.protocol_buffer.TodoProvider.Todo.getDescriptor();
+      }
+      
+      public com.hascode.examples.protocol_buffer.TodoProvider.Todo getDefaultInstanceForType() {
+        return com.hascode.examples.protocol_buffer.TodoProvider.Todo.getDefaultInstance();
+      }
+      
+      public boolean isInitialized() {
+        return result.isInitialized();
+      }
+      public com.hascode.examples.protocol_buffer.TodoProvider.Todo build() {
+        if (result != null && !isInitialized()) {
+          throw newUninitializedMessageException(result);
+        }
+        return buildPartial();
+      }
+      
+      private com.hascode.examples.protocol_buffer.TodoProvider.Todo buildParsed()
+          throws com.google.protobuf.InvalidProtocolBufferException {
+        if (!isInitialized()) {
+          throw newUninitializedMessageException(
+            result).asInvalidProtocolBufferException();
+        }
+        return buildPartial();
+      }
+      
+      public com.hascode.examples.protocol_buffer.TodoProvider.Todo buildPartial() {
+        if (result == null) {
+          throw new IllegalStateException(
+            "build() has already been called on this Builder.");
+        }
+        com.hascode.examples.protocol_buffer.TodoProvider.Todo returnMe = result;
+        result = null;
+        return returnMe;
+      }
+      
+      public Builder mergeFrom(com.google.protobuf.Message other) {
+        if (other instanceof com.hascode.examples.protocol_buffer.TodoProvider.Todo) {
+          return mergeFrom((com.hascode.examples.protocol_buffer.TodoProvider.Todo)other);
+        } else {
+          super.mergeFrom(other);
+          return this;
+        }
+      }
+      
+      public Builder mergeFrom(com.hascode.examples.protocol_buffer.TodoProvider.Todo other) {
+        if (other == com.hascode.examples.protocol_buffer.TodoProvider.Todo.getDefaultInstance()) return this;
+        if (other.hasTitle()) {
+          setTitle(other.getTitle());
+        }
+        if (other.hasPriority()) {
+          setPriority(other.getPriority());
+        }
+        this.mergeUnknownFields(other.getUnknownFields());
+        return this;
+      }
+      
+      public Builder mergeFrom(
+          com.google.protobuf.CodedInputStream input,
+          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+          throws java.io.IOException {
+        com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+          com.google.protobuf.UnknownFieldSet.newBuilder(
+            this.getUnknownFields());
+        while (true) {
+          int tag = input.readTag();
+          switch (tag) {
+            case 0:
+              this.setUnknownFields(unknownFields.build());
+              return this;
+            default: {
+              if (!parseUnknownField(input, unknownFields,
+                                     extensionRegistry, tag)) {
+                this.setUnknownFields(unknownFields.build());
+                return this;
+              }
+              break;
+            }
+            case 10: {
+              setTitle(input.readString());
+              break;
+            }
+            case 16: {
+              int rawValue = input.readEnum();
+              com.hascode.examples.protocol_buffer.TodoProvider.Todo.Priority value = com.hascode.examples.protocol_buffer.TodoProvider.Todo.Priority.valueOf(rawValue);
+              if (value == null) {
+                unknownFields.mergeVarintField(2, rawValue);
+              } else {
+                setPriority(value);
+              }
+              break;
+            }
+          }
+        }
+      }
+      
+      
+      // required string title = 1;
+      public boolean hasTitle() {
+        return result.hasTitle();
+      }
+      public java.lang.String getTitle() {
+        return result.getTitle();
+      }
+      public Builder setTitle(java.lang.String value) {
+        if (value == null) {
+    throw new NullPointerException();
+  }
+  result.hasTitle = true;
+        result.title_ = value;
+        return this;
+      }
+      public Builder clearTitle() {
+        result.hasTitle = false;
+        result.title_ = getDefaultInstance().getTitle();
+        return this;
+      }
+      
+      // optional .examples.Todo.Priority priority = 2;
+      public boolean hasPriority() {
+        return result.hasPriority();
+      }
+      public com.hascode.examples.protocol_buffer.TodoProvider.Todo.Priority getPriority() {
+        return result.getPriority();
+      }
+      public Builder setPriority(com.hascode.examples.protocol_buffer.TodoProvider.Todo.Priority value) {
+        if (value == null) {
+          throw new NullPointerException();
+        }
+        result.hasPriority = true;
+        result.priority_ = value;
+        return this;
+      }
+      public Builder clearPriority() {
+        result.hasPriority = false;
+        result.priority_ = com.hascode.examples.protocol_buffer.TodoProvider.Todo.Priority.NORMAL;
+        return this;
+      }
+      
+      // @@protoc_insertion_point(builder_scope:examples.Todo)
+    }
+    
+    static {
+      defaultInstance = new Todo(true);
+      com.hascode.examples.protocol_buffer.TodoProvider.internalForceInit();
+      defaultInstance.initFields();
+    }
+    
+    // @@protoc_insertion_point(class_scope:examples.Todo)
+  }
+  
+  public static final class Todos extends
+      com.google.protobuf.GeneratedMessage {
+    // Use Todos.newBuilder() to construct.
+    private Todos() {
+      initFields();
+    }
+    private Todos(boolean noInit) {}
+    
+    private static final Todos defaultInstance;
+    public static Todos getDefaultInstance() {
+      return defaultInstance;
+    }
+    
+    public Todos getDefaultInstanceForType() {
+      return defaultInstance;
+    }
+    
+    public static final com.google.protobuf.Descriptors.Descriptor
+        getDescriptor() {
+      return com.hascode.examples.protocol_buffer.TodoProvider.internal_static_examples_Todos_descriptor;
+    }
+    
+    protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
+        internalGetFieldAccessorTable() {
+      return com.hascode.examples.protocol_buffer.TodoProvider.internal_static_examples_Todos_fieldAccessorTable;
+    }
+    
+    // repeated .examples.Todo todos = 1;
+    public static final int TODOS_FIELD_NUMBER = 1;
+    private java.util.List<com.hascode.examples.protocol_buffer.TodoProvider.Todo> todos_ =
+      java.util.Collections.emptyList();
+    public java.util.List<com.hascode.examples.protocol_buffer.TodoProvider.Todo> getTodosList() {
+      return todos_;
+    }
+    public int getTodosCount() { return todos_.size(); }
+    public com.hascode.examples.protocol_buffer.TodoProvider.Todo getTodos(int index) {
+      return todos_.get(index);
+    }
+    
+    private void initFields() {
+    }
+    public final boolean isInitialized() {
+      for (com.hascode.examples.protocol_buffer.TodoProvider.Todo element : getTodosList()) {
+        if (!element.isInitialized()) return false;
+      }
+      return true;
+    }
+    
+    public void writeTo(com.google.protobuf.CodedOutputStream output)
+                        throws java.io.IOException {
+      getSerializedSize();
+      for (com.hascode.examples.protocol_buffer.TodoProvider.Todo element : getTodosList()) {
+        output.writeMessage(1, element);
+      }
+      getUnknownFields().writeTo(output);
+    }
+    
+    private int memoizedSerializedSize = -1;
+    public int getSerializedSize() {
+      int size = memoizedSerializedSize;
+      if (size != -1) return size;
+    
+      size = 0;
+      for (com.hascode.examples.protocol_buffer.TodoProvider.Todo element : getTodosList()) {
+        size += com.google.protobuf.CodedOutputStream
+          .computeMessageSize(1, element);
+      }
+      size += getUnknownFields().getSerializedSize();
+      memoizedSerializedSize = size;
+      return size;
+    }
+    
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todos parseFrom(
+        com.google.protobuf.ByteString data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data).buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todos parseFrom(
+        com.google.protobuf.ByteString data,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data, extensionRegistry)
+               .buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todos parseFrom(byte[] data)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data).buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todos parseFrom(
+        byte[] data,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws com.google.protobuf.InvalidProtocolBufferException {
+      return newBuilder().mergeFrom(data, extensionRegistry)
+               .buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todos parseFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input).buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todos parseFrom(
+        java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input, extensionRegistry)
+               .buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todos parseDelimitedFrom(java.io.InputStream input)
+        throws java.io.IOException {
+      Builder builder = newBuilder();
+      if (builder.mergeDelimitedFrom(input)) {
+        return builder.buildParsed();
+      } else {
+        return null;
+      }
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todos parseDelimitedFrom(
+        java.io.InputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws java.io.IOException {
+      Builder builder = newBuilder();
+      if (builder.mergeDelimitedFrom(input, extensionRegistry)) {
+        return builder.buildParsed();
+      } else {
+        return null;
+      }
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todos parseFrom(
+        com.google.protobuf.CodedInputStream input)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input).buildParsed();
+    }
+    public static com.hascode.examples.protocol_buffer.TodoProvider.Todos parseFrom(
+        com.google.protobuf.CodedInputStream input,
+        com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+        throws java.io.IOException {
+      return newBuilder().mergeFrom(input, extensionRegistry)
+               .buildParsed();
+    }
+    
+    public static Builder newBuilder() { return Builder.create(); }
+    public Builder newBuilderForType() { return newBuilder(); }
+    public static Builder newBuilder(com.hascode.examples.protocol_buffer.TodoProvider.Todos prototype) {
+      return newBuilder().mergeFrom(prototype);
+    }
+    public Builder toBuilder() { return newBuilder(this); }
+    
+    public static final class Builder extends
+        com.google.protobuf.GeneratedMessage.Builder<Builder> {
+      private com.hascode.examples.protocol_buffer.TodoProvider.Todos result;
+      
+      // Construct using com.hascode.examples.protocol_buffer.TodoProvider.Todos.newBuilder()
+      private Builder() {}
+      
+      private static Builder create() {
+        Builder builder = new Builder();
+        builder.result = new com.hascode.examples.protocol_buffer.TodoProvider.Todos();
+        return builder;
+      }
+      
+      protected com.hascode.examples.protocol_buffer.TodoProvider.Todos internalGetResult() {
+        return result;
+      }
+      
+      public Builder clear() {
+        if (result == null) {
+          throw new IllegalStateException(
+            "Cannot call clear() after build().");
+        }
+        result = new com.hascode.examples.protocol_buffer.TodoProvider.Todos();
+        return this;
+      }
+      
+      public Builder clone() {
+        return create().mergeFrom(result);
+      }
+      
+      public com.google.protobuf.Descriptors.Descriptor
+          getDescriptorForType() {
+        return com.hascode.examples.protocol_buffer.TodoProvider.Todos.getDescriptor();
+      }
+      
+      public com.hascode.examples.protocol_buffer.TodoProvider.Todos getDefaultInstanceForType() {
+        return com.hascode.examples.protocol_buffer.TodoProvider.Todos.getDefaultInstance();
+      }
+      
+      public boolean isInitialized() {
+        return result.isInitialized();
+      }
+      public com.hascode.examples.protocol_buffer.TodoProvider.Todos build() {
+        if (result != null && !isInitialized()) {
+          throw newUninitializedMessageException(result);
+        }
+        return buildPartial();
+      }
+      
+      private com.hascode.examples.protocol_buffer.TodoProvider.Todos buildParsed()
+          throws com.google.protobuf.InvalidProtocolBufferException {
+        if (!isInitialized()) {
+          throw newUninitializedMessageException(
+            result).asInvalidProtocolBufferException();
+        }
+        return buildPartial();
+      }
+      
+      public com.hascode.examples.protocol_buffer.TodoProvider.Todos buildPartial() {
+        if (result == null) {
+          throw new IllegalStateException(
+            "build() has already been called on this Builder.");
+        }
+        if (result.todos_ != java.util.Collections.EMPTY_LIST) {
+          result.todos_ =
+            java.util.Collections.unmodifiableList(result.todos_);
+        }
+        com.hascode.examples.protocol_buffer.TodoProvider.Todos returnMe = result;
+        result = null;
+        return returnMe;
+      }
+      
+      public Builder mergeFrom(com.google.protobuf.Message other) {
+        if (other instanceof com.hascode.examples.protocol_buffer.TodoProvider.Todos) {
+          return mergeFrom((com.hascode.examples.protocol_buffer.TodoProvider.Todos)other);
+        } else {
+          super.mergeFrom(other);
+          return this;
+        }
+      }
+      
+      public Builder mergeFrom(com.hascode.examples.protocol_buffer.TodoProvider.Todos other) {
+        if (other == com.hascode.examples.protocol_buffer.TodoProvider.Todos.getDefaultInstance()) return this;
+        if (!other.todos_.isEmpty()) {
+          if (result.todos_.isEmpty()) {
+            result.todos_ = new java.util.ArrayList<com.hascode.examples.protocol_buffer.TodoProvider.Todo>();
+          }
+          result.todos_.addAll(other.todos_);
+        }
+        this.mergeUnknownFields(other.getUnknownFields());
+        return this;
+      }
+      
+      public Builder mergeFrom(
+          com.google.protobuf.CodedInputStream input,
+          com.google.protobuf.ExtensionRegistryLite extensionRegistry)
+          throws java.io.IOException {
+        com.google.protobuf.UnknownFieldSet.Builder unknownFields =
+          com.google.protobuf.UnknownFieldSet.newBuilder(
+            this.getUnknownFields());
+        while (true) {
+          int tag = input.readTag();
+          switch (tag) {
+            case 0:
+              this.setUnknownFields(unknownFields.build());
+              return this;
+            default: {
+              if (!parseUnknownField(input, unknownFields,
+                                     extensionRegistry, tag)) {
+                this.setUnknownFields(unknownFields.build());
+                return this;
+              }
+              break;
+            }
+            case 10: {
+              com.hascode.examples.protocol_buffer.TodoProvider.Todo.Builder subBuilder = com.hascode.examples.protocol_buffer.TodoProvider.Todo.newBuilder();
+              input.readMessage(subBuilder, extensionRegistry);
+              addTodos(subBuilder.buildPartial());
+              break;
+            }
+          }
+        }
+      }
+      
+      
+      // repeated .examples.Todo todos = 1;
+      public java.util.List<com.hascode.examples.protocol_buffer.TodoProvider.Todo> getTodosList() {
+        return java.util.Collections.unmodifiableList(result.todos_);
+      }
+      public int getTodosCount() {
+        return result.getTodosCount();
+      }
+      public com.hascode.examples.protocol_buffer.TodoProvider.Todo getTodos(int index) {
+        return result.getTodos(index);
+      }
+      public Builder setTodos(int index, com.hascode.examples.protocol_buffer.TodoProvider.Todo value) {
+        if (value == null) {
+          throw new NullPointerException();
+        }
+        result.todos_.set(index, value);
+        return this;
+      }
+      public Builder setTodos(int index, com.hascode.examples.protocol_buffer.TodoProvider.Todo.Builder builderForValue) {
+        result.todos_.set(index, builderForValue.build());
+        return this;
+      }
+      public Builder addTodos(com.hascode.examples.protocol_buffer.TodoProvider.Todo value) {
+        if (value == null) {
+          throw new NullPointerException();
+        }
+        if (result.todos_.isEmpty()) {
+          result.todos_ = new java.util.ArrayList<com.hascode.examples.protocol_buffer.TodoProvider.Todo>();
+        }
+        result.todos_.add(value);
+        return this;
+      }
+      public Builder addTodos(com.hascode.examples.protocol_buffer.TodoProvider.Todo.Builder builderForValue) {
+        if (result.todos_.isEmpty()) {
+          result.todos_ = new java.util.ArrayList<com.hascode.examples.protocol_buffer.TodoProvider.Todo>();
+        }
+        result.todos_.add(builderForValue.build());
+        return this;
+      }
+      public Builder addAllTodos(
+          java.lang.Iterable<? extends com.hascode.examples.protocol_buffer.TodoProvider.Todo> values) {
+        if (result.todos_.isEmpty()) {
+          result.todos_ = new java.util.ArrayList<com.hascode.examples.protocol_buffer.TodoProvider.Todo>();
+        }
+        super.addAll(values, result.todos_);
+        return this;
+      }
+      public Builder clearTodos() {
+        result.todos_ = java.util.Collections.emptyList();
+        return this;
+      }
+      
+      // @@protoc_insertion_point(builder_scope:examples.Todos)
+    }
+    
+    static {
+      defaultInstance = new Todos(true);
+      com.hascode.examples.protocol_buffer.TodoProvider.internalForceInit();
+      defaultInstance.initFields();
+    }
+    
+    // @@protoc_insertion_point(class_scope:examples.Todos)
+  }
+  
+  private static com.google.protobuf.Descriptors.Descriptor
+    internal_static_examples_Todo_descriptor;
+  private static
+    com.google.protobuf.GeneratedMessage.FieldAccessorTable
+      internal_static_examples_Todo_fieldAccessorTable;
+  private static com.google.protobuf.Descriptors.Descriptor
+    internal_static_examples_Todos_descriptor;
+  private static
+    com.google.protobuf.GeneratedMessage.FieldAccessorTable
+      internal_static_examples_Todos_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%src/main/protobuf/todo_provider.proto\022" +
+      "\010examples\"n\n\004Todo\022\r\n\005title\030\001 \002(\t\022)\n\010prio" +
+      "rity\030\002 \001(\0162\027.examples.Todo.Priority\",\n\010P" +
+      "riority\022\n\n\006NORMAL\020\001\022\n\n\006MEDIUM\020\002\022\010\n\004HIGH\020" +
+      "\003\"&\n\005Todos\022\035\n\005todos\030\001 \003(\0132\016.examples.Tod" +
+      "oB4\n$com.hascode.examples.protocol_buffe" +
+      "rB\014TodoProvider"
+    };
+    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;
+          internal_static_examples_Todo_descriptor =
+            getDescriptor().getMessageTypes().get(0);
+          internal_static_examples_Todo_fieldAccessorTable = new
+            com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+              internal_static_examples_Todo_descriptor,
+              new java.lang.String[] { "Title", "Priority", },
+              com.hascode.examples.protocol_buffer.TodoProvider.Todo.class,
+              com.hascode.examples.protocol_buffer.TodoProvider.Todo.Builder.class);
+          internal_static_examples_Todos_descriptor =
+            getDescriptor().getMessageTypes().get(1);
+          internal_static_examples_Todos_fieldAccessorTable = new
+            com.google.protobuf.GeneratedMessage.FieldAccessorTable(
+              internal_static_examples_Todos_descriptor,
+              new java.lang.String[] { "Todos", },
+              com.hascode.examples.protocol_buffer.TodoProvider.Todos.class,
+              com.hascode.examples.protocol_buffer.TodoProvider.Todos.Builder.class);
+          return null;
+        }
+      };
+    com.google.protobuf.Descriptors.FileDescriptor
+      .internalBuildGeneratedFileFrom(descriptorData,
+        new com.google.protobuf.Descriptors.FileDescriptor[] {
+        }, assigner);
+  }
+  
+  public static void internalForceInit() {}
+  
+  // @@protoc_insertion_point(outer_class_scope)
+}

protocol-buffer-sample/src/main/protobuf/todo_provider.proto

+package examples;
+
+option java_package = "com.hascode.examples.protocol_buffer";
+option java_outer_classname = "TodoProvider";
+
+message Todo {
+	required string title = 1;
+	enum Priority {
+		NORMAL = 1;
+		MEDIUM = 2;
+		HIGH = 3;
+	}
+	
+	optional Priority priority = 2;
+}
+
+message Todos {
+	repeated Todo todos = 1;
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.