Small optimization to avoid generating EOFExceptions while parsing from a in memory buffer.


git-svn-id: https://svn.apache.org/repos/asf/activemq/activemq-protobuf/trunk@744106 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedInputStream.java b/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedInputStream.java
index 8b47e87..96dcf89 100644
--- a/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedInputStream.java
+++ b/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedInputStream.java
@@ -49,10 +49,12 @@
 

     public CodedInputStream(Buffer data) {

         this(new BufferInputStream(data));

+        limit = data.length;

     }

 

     public CodedInputStream(byte[] data) {

         this(new BufferInputStream(data));

+        limit = data.length;

     }

 

     /**

@@ -62,6 +64,10 @@
      * number.

      */

     public int readTag() throws IOException {

+        if( pos >= limit ) {

+            lastTag=0;

+            return 0;

+        }

         try {

             lastTag = readRawVarint32();

             if (lastTag == 0) {

@@ -75,6 +81,7 @@
         }

     }

 

+    

     /**

      * Verifies that the last call to readTag() returned the given tag value.

      * This is used to verify that a nested group ended with the correct end