activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r702614 - in /activemq/sandbox/activemq-protobuf: activemq-protobuf-test/src/test/java/com/google/protobuf/ activemq-protobuf/src/main/java/org/apache/activemq/protobuf/ activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/
Date Tue, 07 Oct 2008 20:18:39 GMT
Author: chirino
Date: Tue Oct  7 13:18:39 2008
New Revision: 702614

URL: http://svn.apache.org/viewvc?rev=702614&view=rev
Log:
Cleaned up the Message interface so that it's obvious and easy to use Framed and Unframed
encoding of the messages.
 

Modified:
    activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/GeneratedMessageTest.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/WireFormatTest.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/BaseMessage.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/Message.java
    activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/GeneratedMessageTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/GeneratedMessageTest.java?rev=702614&r1=702613&r2=702614&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/GeneratedMessageTest.java
(original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/GeneratedMessageTest.java
Tue Oct  7 13:18:39 2008
@@ -111,6 +111,6 @@
         .setNestedEnum(MessageWithNoOuter.NestedEnum.BAZ)
         .setForeignEnum(EnumWithNoOuter.BAR)
         ;
-    assertEquals(message.toString(), MessageWithNoOuter.parseFrom(message.toByteArray()).toString());
+    assertEquals(message.toString(), MessageWithNoOuter.parseUnframed(message.toUnframedByteArray()).toString());
   }
 }

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/WireFormatTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/WireFormatTest.java?rev=702614&r1=702613&r2=702614&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/WireFormatTest.java
(original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf-test/src/test/java/com/google/protobuf/WireFormatTest.java
Tue Oct  7 13:18:39 2008
@@ -28,10 +28,10 @@
   public void testSerialization() throws Exception {
     TestAllTypes message = TestUtil.getAllSet();
 
-    byte[] rawBytes = message.toByteArray();
-    assertEquals(rawBytes.length, message.serializedSize());
+    byte[] rawBytes = message.toUnframedByteArray();
+    assertEquals(rawBytes.length, message.serializedSizeUnframed());
 
-    TestAllTypes message2 = TestAllTypes.parseFrom(rawBytes);
+    TestAllTypes message2 = TestAllTypes.parseUnframed(rawBytes);
 
     TestUtil.assertAllFieldsSet(message2);
   }

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/BaseMessage.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/BaseMessage.java?rev=702614&r1=702613&r2=702614&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/BaseMessage.java
(original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/BaseMessage.java
Tue Oct  7 13:18:39 2008
@@ -16,115 +16,98 @@
  */
 package org.apache.activemq.protobuf;
 
-import com.google.protobuf.ByteString;
-import com.google.protobuf.CodedInputStream;
-import com.google.protobuf.CodedOutputStream;
-import com.google.protobuf.ExtensionRegistry;
-import com.google.protobuf.InvalidProtocolBufferException;
-
-import static org.apache.activemq.protobuf.WireInfo.*;
+import static org.apache.activemq.protobuf.WireInfo.WIRETYPE_END_GROUP;
+import static org.apache.activemq.protobuf.WireInfo.WIRETYPE_LENGTH_DELIMITED;
+import static org.apache.activemq.protobuf.WireInfo.WIRETYPE_START_GROUP;
+import static org.apache.activemq.protobuf.WireInfo.makeTag;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 
+import com.google.protobuf.ByteString;
+import com.google.protobuf.CodedInputStream;
+import com.google.protobuf.CodedOutputStream;
+import com.google.protobuf.InvalidProtocolBufferException;
+
 abstract public class BaseMessage<T> implements Message<T> {
 
     protected int memoizedSerializedSize = -1;
-
-    static protected <T> void addAll(Iterable<T> values, Collection<? super
T> list) {
-        if (values instanceof Collection) {
-            @SuppressWarnings("unsafe")
-            Collection<T> collection = (Collection<T>)values;
-            list.addAll(collection);
-        } else {
-            for (T value : values) {
-                list.add(value);
-            }
-        }
-    }
     
     abstract public T clone() throws CloneNotSupportedException;
 
-    static protected void writeGroup(CodedOutputStream output, int tag, BaseMessage message)
throws IOException {
-        output.writeTag(tag, WIRETYPE_START_GROUP);
-        message.writePartialTo(output);
-        output.writeTag(tag, WIRETYPE_END_GROUP);
-    }
-
-    static protected void writeMessage(CodedOutputStream output, int tag, BaseMessage message)
throws IOException {
-        output.writeTag(tag, WIRETYPE_LENGTH_DELIMITED);
-        output.writeRawVarint32(message.serializedSize());
-        message.writePartialTo(output);
-    }
-
-    static protected <T extends BaseMessage> T readGroup(CodedInputStream input, ExtensionRegistry
extensionRegistry, int tag, T group) throws IOException {
-        group.mergeFrom(input, extensionRegistry);
-        input.checkLastTagWas(makeTag(tag, WIRETYPE_END_GROUP));
-        return group;
-    }
-
-    static protected <T extends BaseMessage> T readMessage(CodedInputStream input,
ExtensionRegistry extensionRegistry, T message) throws IOException {
-        int length = input.readRawVarint32();
-        int oldLimit = input.pushLimit(length);
-        message.mergeFrom(input, extensionRegistry);
-        input.checkLastTagWas(0);
-        input.popLimit(oldLimit);
-        return message;
-    }
-
-    static protected int computeGroupSize(int tag, BaseMessage message) {
-        return CodedOutputStream.computeTagSize(tag) * 2 + message.serializedSize();
-    }
+    ///////////////////////////////////////////////////////////////////
+    // Write related helpers.
+    ///////////////////////////////////////////////////////////////////
 
-    static protected int computeMessageSize(int tag, BaseMessage message) {
-        int t = message.serializedSize();
-        return CodedOutputStream.computeTagSize(tag) + CodedOutputStream.computeRawVarint32Size(t)
+ t;
-    }
-
-    public T mergeFrom(CodedInputStream input) throws IOException {
-        return mergeFrom(input, ExtensionRegistry.getEmptyRegistry());
+    public void writeFramed(CodedOutputStream output) throws IOException {
+        output.writeRawVarint32(serializedSizeUnframed());
+        writeUnframed(output);
     }
 
-    public byte[] toByteArray() {
+    public byte[] toUnframedByteArray() {
         try {
-            byte[] result = new byte[serializedSize()];
+            byte[] result = new byte[serializedSizeUnframed()];
             CodedOutputStream output = CodedOutputStream.newInstance(result);
-            writePartialTo(output);
+            writeUnframed(output);
             output.checkNoSpaceLeft();
             return result;
         } catch (IOException e) {
             throw new RuntimeException("Serializing to a byte array threw an IOException
" + "(should never happen).", e);
         }
     }
-
-    protected List<String> prefix(List<String> missingFields, String prefix)
{
-        ArrayList<String> rc = new ArrayList<String>(missingFields.size());
-        for (String v : missingFields) {
-            rc.add(prefix+v);
+    
+    
+	public byte[] toFramedByteArray() {
+        try {
+            byte[] result = new byte[serializedSizeFramed()];
+            CodedOutputStream output = CodedOutputStream.newInstance(result);
+            writeFramed(output);
+            output.checkNoSpaceLeft();
+            return result;
+        } catch (IOException e) {
+            throw new RuntimeException("Serializing to a byte array threw an IOException
" + "(should never happen).", e);
         }
-        return rc;
-    }
+	}
+    
+	public void writeFramed(OutputStream output) throws IOException {
+        CodedOutputStream codedOutput = CodedOutputStream.newInstance(output);
+        writeFramed(codedOutput);
+        codedOutput.flush();
+	}
 
-    public void writeTo(OutputStream output) throws IOException {
+    public void writeUnframed(OutputStream output) throws IOException {
         CodedOutputStream codedOutput = CodedOutputStream.newInstance(output);
-        writeTo(codedOutput);
+        writeUnframed(codedOutput);
         codedOutput.flush();
     }
     
-    public void writeTo(CodedOutputStream output) throws java.io.IOException {
-        writePartialTo(output);
-        output.writeTag(0, WIRETYPE_END_GROUP);
+    public int serializedSizeFramed() {
+        int t = serializedSizeUnframed();
+        return CodedOutputStream.computeRawVarint32Size(t) + t;
+
+    }
+
+    ///////////////////////////////////////////////////////////////////
+    // Read related helpers.
+    ///////////////////////////////////////////////////////////////////
+
+    public T mergeFramed(CodedInputStream input) throws IOException {
+        int length = input.readRawVarint32();
+        int oldLimit = input.pushLimit(length);
+        T rc=  mergeUnframed(input);
+        input.checkLastTagWas(0);
+        input.popLimit(oldLimit);
+        return rc;
     }
 
-    public T mergeFrom(ByteString data) throws InvalidProtocolBufferException {
+    public T mergeUnframed(ByteString data) throws InvalidProtocolBufferException {
         try {
             CodedInputStream input = data.newCodedInput();
-            mergeFrom(input);
+            mergeUnframed(input);
             input.checkLastTagWas(0);
             return (T)this;
         } catch (InvalidProtocolBufferException e) {
@@ -133,11 +116,11 @@
             throw new RuntimeException("Reading from a ByteString threw an IOException (should
" + "never happen).", e);
         }
     }
-
-    public T mergeFrom(ByteString data, ExtensionRegistry extensionRegistry) throws InvalidProtocolBufferException
{
+    
+    public T mergeFramed(ByteString data) throws InvalidProtocolBufferException {
         try {
             CodedInputStream input = data.newCodedInput();
-            mergeFrom(input, extensionRegistry);
+            mergeFramed(input);
             input.checkLastTagWas(0);
             return (T)this;
         } catch (InvalidProtocolBufferException e) {
@@ -147,10 +130,10 @@
         }
     }
 
-    public T mergeFrom(byte[] data) throws InvalidProtocolBufferException {
+    public T mergeUnframed(byte[] data) throws InvalidProtocolBufferException {
         try {
             CodedInputStream input = CodedInputStream.newInstance(data);
-            mergeFrom(input);
+            mergeUnframed(input);
             input.checkLastTagWas(0);
             return (T)this;
         } catch (InvalidProtocolBufferException e) {
@@ -159,11 +142,11 @@
             throw new RuntimeException("Reading from a byte array threw an IOException (should
" + "never happen).", e);
         }
     }
-
-    public T mergeFrom(byte[] data, ExtensionRegistry extensionRegistry) throws InvalidProtocolBufferException
{
+    
+    public T mergeFramed(byte[] data) throws InvalidProtocolBufferException {
         try {
             CodedInputStream input = CodedInputStream.newInstance(data);
-            mergeFrom(input, extensionRegistry);
+            mergeFramed(input);
             input.checkLastTagWas(0);
             return (T)this;
         } catch (InvalidProtocolBufferException e) {
@@ -173,16 +156,122 @@
         }
     }
 
-    public T mergeFrom(InputStream input) throws IOException {
+    public T mergeUnframed(InputStream input) throws IOException {
         CodedInputStream codedInput = CodedInputStream.newInstance(input);
-        mergeFrom(codedInput);
+        mergeUnframed(codedInput);
         return (T)this;
     }
+    
+    public T mergeFramed(InputStream input) throws IOException {
+		int length = readRawVarint32(input);
+		byte []data = new byte[length];
+		int pos = 0;
+		while( pos < length ) {
+			int r = input.read(data, pos, length-pos);
+			if( r < 0 ) {
+				throw new InvalidProtocolBufferException("Input stream ended before a full message frame
could be read.");	
+			}
+			pos+=r;
+		}
+		return mergeUnframed(data);
+    }
+
+    ///////////////////////////////////////////////////////////////////
+    // Internal implementation methods.
+    ///////////////////////////////////////////////////////////////////
+    static protected <T> void addAll(Iterable<T> values, Collection<? super
T> list) {
+        if (values instanceof Collection) {
+            @SuppressWarnings("unsafe")
+            Collection<T> collection = (Collection<T>)values;
+            list.addAll(collection);
+        } else {
+            for (T value : values) {
+                list.add(value);
+            }
+        }
+    }
+    
+    static protected void writeGroup(CodedOutputStream output, int tag, BaseMessage message)
throws IOException {
+        output.writeTag(tag, WIRETYPE_START_GROUP);
+        message.writeUnframed(output);
+        output.writeTag(tag, WIRETYPE_END_GROUP);
+    }
 
-    public T mergeFrom(InputStream input, ExtensionRegistry extensionRegistry) throws IOException
{
-        CodedInputStream codedInput = CodedInputStream.newInstance(input);
-        mergeFrom(codedInput, extensionRegistry);
-        return (T)this;
+    static protected <T extends BaseMessage> T readGroup(CodedInputStream input, int
tag, T group) throws IOException {
+        group.mergeUnframed(input);
+        input.checkLastTagWas(makeTag(tag, WIRETYPE_END_GROUP));
+        return group;
+    }
+
+    static protected int computeGroupSize(int tag, BaseMessage message) {
+        return CodedOutputStream.computeTagSize(tag) * 2 + message.serializedSizeUnframed();
     }
 
+
+    static protected void writeMessage(CodedOutputStream output, int tag, BaseMessage message)
throws IOException {
+        output.writeTag(tag, WIRETYPE_LENGTH_DELIMITED);
+        message.writeFramed(output);
+    }
+    
+    static protected int computeMessageSize(int tag, BaseMessage message) {
+        return CodedOutputStream.computeTagSize(tag) + message.serializedSizeFramed();
+    }
+    
+    protected List<String> prefix(List<String> missingFields, String prefix)
{
+        ArrayList<String> rc = new ArrayList<String>(missingFields.size());
+        for (String v : missingFields) {
+            rc.add(prefix+v);
+        }
+        return rc;
+    }
+
+
+    /**
+     * Read a raw Varint from the stream.  If larger than 32 bits, discard the
+     * upper bits.
+     */
+    static protected int readRawVarint32(InputStream is) throws IOException {
+      byte tmp = readRawByte(is);
+      if (tmp >= 0) {
+        return tmp;
+      }
+      int result = tmp & 0x7f;
+      if ((tmp = readRawByte(is)) >= 0) {
+        result |= tmp << 7;
+      } else {
+        result |= (tmp & 0x7f) << 7;
+        if ((tmp = readRawByte(is)) >= 0) {
+          result |= tmp << 14;
+        } else {
+          result |= (tmp & 0x7f) << 14;
+          if ((tmp = readRawByte(is)) >= 0) {
+            result |= tmp << 21;
+          } else {
+            result |= (tmp & 0x7f) << 21;
+            result |= (tmp = readRawByte(is)) << 28;
+            if (tmp < 0) {
+              // Discard upper 32 bits.
+              for (int i = 0; i < 5; i++) {
+                if (readRawByte(is) >= 0) return result;
+              }
+              throw new InvalidProtocolBufferException(
+              "CodedInputStream encountered a malformed varint.");
+            }
+          }
+        }
+      }
+      return result;
+    }
+
+    static protected byte readRawByte(InputStream is) throws IOException {
+    	int rc = is.read();
+    	if( rc == -1 ) {
+	        throw new InvalidProtocolBufferException(
+	        	      "While parsing a protocol message, the input ended unexpectedly " +
+	        	      "in the middle of a field.  This could mean either than the " +
+	        	      "input has been truncated or that an embedded message " +
+	        	      "misreported its own length.");
+    	}
+    	return (byte) rc;
+    }
 }

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/Message.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/Message.java?rev=702614&r1=702613&r2=702614&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/Message.java
(original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/Message.java
Tue Oct  7 13:18:39 2008
@@ -16,56 +16,59 @@
  */
 package org.apache.activemq.protobuf;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
 import com.google.protobuf.ByteString;
 import com.google.protobuf.CodedInputStream;
 import com.google.protobuf.CodedOutputStream;
-import com.google.protobuf.ExtensionRegistry;
 import com.google.protobuf.InvalidProtocolBufferException;
 
-import static org.apache.activemq.protobuf.WireInfo.*;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
 public interface Message<T> {
 
-    public T mergeFrom(T other);
-
-    public T mergeFrom(CodedInputStream input) throws IOException;
-
-    public T mergeFrom(CodedInputStream input, ExtensionRegistry extensionRegistry) throws
IOException;
-
-    public void writeTo(CodedOutputStream output) throws java.io.IOException;
-
     public T clone() throws CloneNotSupportedException;
 
-    public int serializedSize();
+    public int serializedSizeUnframed();
+    
+    public int serializedSizeFramed();
 
     public void clear();
 
     public T assertInitialized() throws com.google.protobuf.UninitializedMessageException;
 
-    public byte[] toByteArray();
+    public T mergeFrom(T other);
+
 
-    public void writePartialTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException;
+    public T mergeUnframed(byte[] data) throws InvalidProtocolBufferException;
     
-    public void writeTo(OutputStream output) throws IOException;
-
-    public T mergeFrom(ByteString data) throws InvalidProtocolBufferException;
+    public T mergeFramed(byte[] data) throws InvalidProtocolBufferException;
 
-    public T mergeFrom(ByteString data, ExtensionRegistry extensionRegistry) throws InvalidProtocolBufferException;
+    public T mergeUnframed(CodedInputStream input) throws IOException;
+    
+    public T mergeFramed(CodedInputStream input) throws IOException;
+    
+    public T mergeUnframed(ByteString data) throws InvalidProtocolBufferException;
 
-    public T mergeFrom(byte[] data) throws InvalidProtocolBufferException;
+    public T mergeFramed(ByteString data) throws InvalidProtocolBufferException;
+    
+    public T mergeUnframed(InputStream input) throws IOException;
+    
+    public T mergeFramed(InputStream input) throws IOException;
 
-    public T mergeFrom(byte[] data, ExtensionRegistry extensionRegistry) throws InvalidProtocolBufferException;
+    
 
-    public T mergeFrom(InputStream input) throws IOException;
+    public byte[] toUnframedByteArray();
+   
+    public byte[] toFramedByteArray();
+    
+    public void writeUnframed(CodedOutputStream output) throws java.io.IOException;
+    
+    public void writeFramed(CodedOutputStream output) throws java.io.IOException;
+    
+    public void writeUnframed(OutputStream output) throws IOException;
+    
+    public void writeFramed(OutputStream output) throws java.io.IOException;
 
-    public T mergeFrom(InputStream input, ExtensionRegistry extensionRegistry) throws IOException;
 
 }

Modified: activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java?rev=702614&r1=702613&r2=702614&view=diff
==============================================================================
--- activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java
(original)
+++ activemq/sandbox/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/JavaGenerator.java
Tue Oct  7 13:18:39 2008
@@ -23,8 +23,6 @@
 import static org.apache.activemq.protobuf.WireInfo.WIRETYPE_VARINT;
 import static org.apache.activemq.protobuf.WireInfo.makeTag;
 
-import com.google.protobuf.ByteString;
-
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -53,6 +51,7 @@
     private String optimizeFor;
     private ArrayList<String> errors = new ArrayList<String>();
     private boolean multipleFiles;
+	private boolean defferedUnmarshall;
 
     public static void main(String[] args) {
         
@@ -124,6 +123,7 @@
         outerClassName = javaClassName(proto);
         optimizeFor = getOption(proto.getOptions(), "optimize_for", "SPEED");
         multipleFiles = isMultipleFilesEnabled(proto);
+        defferedUnmarshall = Boolean.getBoolean(getOption(proto.getOptions(), "deferred_unmarshall",
"false"));
         
         if( multipleFiles ) {
             generateProtoFile();
@@ -288,6 +288,9 @@
             }
         }
 
+//        if( defferedUnmarshall ) {
+//        }
+
         // Generate the field accessors..
         for (FieldDescriptor field : m.getFields().values()) {
             generateFieldAccessor(className, field);
@@ -317,7 +320,7 @@
         generateMethodVisitor(m);
                 
         generateMethodType(m, className);
-        
+                
         unindent();
         p("}");
         p();
@@ -408,54 +411,68 @@
     }
     
     private void generateMethodParseFrom(MessageDescriptor m, String className) {
-        p("public static "+className+" parseFrom(com.google.protobuf.ByteString data) throws
com.google.protobuf.InvalidProtocolBufferException {");
+        p("public static "+className+" parseUnframed(com.google.protobuf.CodedInputStream
data) throws com.google.protobuf.InvalidProtocolBufferException, java.io.IOException {");
         indent();
-        p("return new "+className+"().mergeFrom(data).checktInitialized();");
+        p("return new "+className+"().mergeUnframed(data).checktInitialized();");
         unindent();
         p("}");
         p();
 
-        p("public static "+className+" parseFrom(com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistry
extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException {");
+        p("public static "+className+" parseUnframed(com.google.protobuf.ByteString data)
throws com.google.protobuf.InvalidProtocolBufferException {");
         indent();
-        p("return new "+className+"().mergeFrom(data, extensionRegistry).checktInitialized();");
+        p("return new "+className+"().mergeUnframed(data).checktInitialized();");
         unindent();
         p("}");
         p();
 
-        p("public static "+className+" parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException
{");
+        p("public static "+className+" parseUnframed(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException
{");
         indent();
-        p("return new "+className+"().mergeFrom(data).checktInitialized();");
+        p("return new "+className+"().mergeUnframed(data).checktInitialized();");
         unindent();
         p("}");
         p();
-
-        p("public static "+className+" parseFrom(byte[] data, com.google.protobuf.ExtensionRegistry
extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException {");
+        
+        p("public static "+className+" parseUnframed(java.io.InputStream data) throws com.google.protobuf.InvalidProtocolBufferException,
java.io.IOException {");
+        indent();
+        p("return new "+className+"().mergeUnframed(data).checktInitialized();");
+        unindent();
+        p("}");
+        p();
+        
+        p("public static "+className+" parseFramed(com.google.protobuf.CodedInputStream data)
throws com.google.protobuf.InvalidProtocolBufferException, java.io.IOException {");
         indent();
-        p("return new "+className+"().mergeFrom(data,extensionRegistry).checktInitialized();");
+        p("return new "+className+"().mergeFramed(data).checktInitialized();");
         unindent();
         p("}");
         p();
         
-        p("public static "+className+" parseFrom(java.io.InputStream data) throws com.google.protobuf.InvalidProtocolBufferException,
java.io.IOException {");
+        p("public static "+className+" parseFramed(com.google.protobuf.ByteString data) throws
com.google.protobuf.InvalidProtocolBufferException {");
         indent();
-        p("return new "+className+"().mergeFrom(data).checktInitialized();");
+        p("return new "+className+"().mergeFramed(data).checktInitialized();");
         unindent();
         p("}");
         p();
 
-        p("public static "+className+" parseFrom(java.io.InputStream data, com.google.protobuf.ExtensionRegistry
extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException, java.io.IOException
{");
+        p("public static "+className+" parseFramed(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException
{");
         indent();
-        p("return new "+className+"().mergeFrom(data,extensionRegistry).checktInitialized();");
+        p("return new "+className+"().mergeFramed(data).checktInitialized();");
         unindent();
         p("}");
-        p();        
+        p();
+        
+        p("public static "+className+" parseFramed(java.io.InputStream data) throws com.google.protobuf.InvalidProtocolBufferException,
java.io.IOException {");
+        indent();
+        p("return new "+className+"().mergeFramed(data).checktInitialized();");
+        unindent();
+        p("}");
+        p();
     }
 
     /**
      * @param m
      */
     private void generateMethodSerializedSize(MessageDescriptor m) {
-        p("public int serializedSize() {");
+        p("public int serializedSizeUnframed() {");
         indent();
         p("if (memoizedSerializedSize != -1)");
         p("   return memoizedSerializedSize;");
@@ -534,7 +551,7 @@
      * @param m
      */
     private void generateMethodWriteTo(MessageDescriptor m) {
-        p("public void writePartialTo(com.google.protobuf.CodedOutputStream output) throws
java.io.IOException {");
+        p("public void writeUnframed(com.google.protobuf.CodedOutputStream output) throws
java.io.IOException {");
         indent();
         for (FieldDescriptor field : m.getFields().values()) {
             String uname = uCamel(field.getName());
@@ -608,32 +625,20 @@
      * @param className
      */
     private void generateMethodMergeFromStream(MessageDescriptor m, String className) {
-        p("public "+className+" mergeFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistry
extensionRegistry) throws java.io.IOException {");
+        p("public "+className+" mergeUnframed(com.google.protobuf.CodedInputStream input)
throws java.io.IOException {");
         indent(); {
-          //TODO: handle unknown fields
-          // UnknownFieldSet.Builder unknownFields = com.google.protobuf.UnknownFieldSet.newBuilder(this.unknownFields);
-            
           p("while (true) {");
           indent(); {
               p("int tag = input.readTag();");
-              // Is it an end group tag?
               p("if ((tag & 0x07) == 4) {");
               p("   return this;");
               p("}");
               
               p("switch (tag) {");
-              // The end of stream..
               p("case 0:");
-//              p("   this.setUnknownFields(unknownFields.build());");
               p("   return this;");
               p("default: {");
-              
-              //TODO: handle unknown field types.
-//              p("   if (!parseUnknownField(input, unknownFields, extensionRegistry, tag))
{");
-//              p("       this.setUnknownFields(unknownFields.build());");
-//              p("       return this;");
-//              p("   }");
-              
+
               p("   break;");
               p("}");
               
@@ -645,9 +650,6 @@
                   if( repeated ) {
                       setter = "get"+uname+"List().add";
                   }
-                  
-                  
-                  
                   if( field.getType()==FieldDescriptor.STRING_TYPE ) {
                       p("case "+makeTag(field.getTag(), WIRETYPE_LENGTH_DELIMITED)+":");
                       indent();
@@ -731,15 +733,15 @@
                       indent();
                       String type = javaType(field);
                       if( repeated ) {
-                          p(setter+"(readGroup(input, extensionRegistry, "+field.getTag()+",
new "+type+"()));");
+                          p(setter+"(readGroup(input, "+field.getTag()+", new "+type+"()));");
                       } else {
                           p("if (has"+uname+"()) {");
                           indent();
-                          p("readGroup(input, extensionRegistry, "+field.getTag()+", get"+uname+"());");
+                          p("readGroup(input, "+field.getTag()+", get"+uname+"());");
                           unindent();
                           p("} else {");
                           indent();
-                          p(setter+"(readGroup(input, extensionRegistry, "+field.getTag()+",new
"+type+"()));");
+                          p(setter+"(readGroup(input, "+field.getTag()+",new "+type+"()));");
                           unindent();
                           p("}");
                       }
@@ -749,15 +751,15 @@
                       indent();
                       String type = javaType(field);
                       if( repeated ) {
-                          p(setter+"(readMessage(input, extensionRegistry, new "+type+"()));");
+                          p(setter+"(new "+type+"().mergeFramed(input));");
                       } else {
                           p("if (has"+uname+"()) {");
                           indent();
-                          p("readMessage(input, extensionRegistry,get"+uname+"());");
+                          p("get"+uname+"().mergeFramed(input);");
                           unindent();
                           p("} else {");
                           indent();
-                          p(setter+"(readMessage(input, extensionRegistry, new "+type+"()));");
+                          p(setter+"(new "+type+"().mergeFramed(input));");
                           unindent();
                           p("}");
                       }



Mime
View raw message