You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2009/06/03 21:20:33 UTC
svn commit: r781514 [4/6] - in /activemq/sandbox/activemq-flow: ./
activemq-all/ activemq-bio/ activemq-bio/src/main/java/org/apache/activemq/
activemq-bio/src/main/java/org/apache/activemq/transport/tcp/
activemq-broker/ activemq-broker/src/main/java/...
Modified: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedInputStream.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedInputStream.java?rev=781514&r1=781513&r2=781514&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedInputStream.java (original)
+++ activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedInputStream.java Wed Jun 3 19:20:13 2009
@@ -1,419 +1,419 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc.
-// http://code.google.com/p/protobuf/
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package org.apache.activemq.protobuf;
-
-import java.io.EOFException;
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-
-/**
- * Reads and decodes protocol message fields.
- *
- * This class contains two kinds of methods: methods that read specific protocol
- * message constructs and field types (e.g. {@link #readTag()} and
- * {@link #readInt32()}) and methods that read low-level values (e.g.
- * {@link #readRawVarint32()} and {@link #readRawBytes}). If you are reading
- * encoded protocol messages, you should use the former methods, but if you are
- * reading some other format of your own design, use the latter.
- *
- * @author kenton@google.com Kenton Varda
- */
-public final class CodedInputStream extends FilterInputStream {
-
- private int lastTag = 0;
- private int limit = Integer.MAX_VALUE;
- private int pos;
- private BufferInputStream bis;
-
- public CodedInputStream(InputStream in) {
- super(in);
- if( in.getClass() == BufferInputStream.class ) {
- bis = (BufferInputStream)in;
- }
- }
-
- public CodedInputStream(Buffer data) {
- this(new BufferInputStream(data));
- limit = data.length;
- }
-
- public CodedInputStream(byte[] data) {
- this(new BufferInputStream(data));
- limit = data.length;
- }
-
- /**
- * Attempt to read a field tag, returning zero if we have reached EOF.
- * Protocol message parsers use this to read tags, since a protocol message
- * may legally end wherever a tag occurs, and zero is not a valid tag
- * number.
- */
- public int readTag() throws IOException {
- if( pos >= limit ) {
- lastTag=0;
- return 0;
- }
- try {
- lastTag = readRawVarint32();
- if (lastTag == 0) {
- // If we actually read zero, that's not a valid tag.
- throw InvalidProtocolBufferException.invalidTag();
- }
- return lastTag;
- } catch (EOFException e) {
- lastTag=0;
- return 0;
- }
- }
-
-
- /**
- * 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
- * tag.
- *
- * @throws InvalidProtocolBufferException
- * {@code value} does not match the last tag.
- */
- public void checkLastTagWas(int value) throws InvalidProtocolBufferException {
- if (lastTag != value) {
- throw InvalidProtocolBufferException.invalidEndTag();
- }
- }
-
- /**
- * Reads and discards a single field, given its tag value.
- *
- * @return {@code false} if the tag is an endgroup tag, in which case
- * nothing is skipped. Otherwise, returns {@code true}.
- */
- public boolean skipField(int tag) throws IOException {
- switch (WireFormat.getTagWireType(tag)) {
- case WireFormat.WIRETYPE_VARINT:
- readInt32();
- return true;
- case WireFormat.WIRETYPE_FIXED64:
- readRawLittleEndian64();
- return true;
- case WireFormat.WIRETYPE_LENGTH_DELIMITED:
- skipRawBytes(readRawVarint32());
- return true;
- case WireFormat.WIRETYPE_START_GROUP:
- skipMessage();
- checkLastTagWas(WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP));
- return true;
- case WireFormat.WIRETYPE_END_GROUP:
- return false;
- case WireFormat.WIRETYPE_FIXED32:
- readRawLittleEndian32();
- return true;
- default:
- throw InvalidProtocolBufferException.invalidWireType();
- }
- }
-
- /**
- * Reads and discards an entire message. This will read either until EOF or
- * until an endgroup tag, whichever comes first.
- */
- public void skipMessage() throws IOException {
- while (true) {
- int tag = readTag();
- if (tag == 0 || !skipField(tag))
- return;
- }
- }
-
- // -----------------------------------------------------------------
-
- /** Read a {@code double} field value from the stream. */
- public double readDouble() throws IOException {
- return Double.longBitsToDouble(readRawLittleEndian64());
- }
-
- /** Read a {@code float} field value from the stream. */
- public float readFloat() throws IOException {
- return Float.intBitsToFloat(readRawLittleEndian32());
- }
-
- /** Read a {@code uint64} field value from the stream. */
- public long readUInt64() throws IOException {
- return readRawVarint64();
- }
-
- /** Read an {@code int64} field value from the stream. */
- public long readInt64() throws IOException {
- return readRawVarint64();
- }
-
- /** Read an {@code int32} field value from the stream. */
- public int readInt32() throws IOException {
- return readRawVarint32();
- }
-
- /** Read a {@code fixed64} field value from the stream. */
- public long readFixed64() throws IOException {
- return readRawLittleEndian64();
- }
-
- /** Read a {@code fixed32} field value from the stream. */
- public int readFixed32() throws IOException {
- return readRawLittleEndian32();
- }
-
- /** Read a {@code bool} field value from the stream. */
- public boolean readBool() throws IOException {
- return readRawVarint32() != 0;
- }
-
- /** Read a {@code string} field value from the stream. */
- public String readString() throws IOException {
- int size = readRawVarint32();
- Buffer data = readRawBytes(size);
- return new String(data.data, data.offset, data.length, "UTF-8");
- }
-
- /** Read a {@code bytes} field value from the stream. */
- public Buffer readBytes() throws IOException {
- int size = readRawVarint32();
- return readRawBytes(size);
- }
-
- /** Read a {@code uint32} field value from the stream. */
- public int readUInt32() throws IOException {
- return readRawVarint32();
- }
-
- /**
- * Read an enum field value from the stream. Caller is responsible for
- * converting the numeric value to an actual enum.
- */
- public int readEnum() throws IOException {
- return readRawVarint32();
- }
-
- /** Read an {@code sfixed32} field value from the stream. */
- public int readSFixed32() throws IOException {
- return readRawLittleEndian32();
- }
-
- /** Read an {@code sfixed64} field value from the stream. */
- public long readSFixed64() throws IOException {
- return readRawLittleEndian64();
- }
-
- /** Read an {@code sint32} field value from the stream. */
- public int readSInt32() throws IOException {
- return decodeZigZag32(readRawVarint32());
- }
-
- /** Read an {@code sint64} field value from the stream. */
- public long readSInt64() throws IOException {
- return decodeZigZag64(readRawVarint64());
- }
-
- // =================================================================
-
- /**
- * Read a raw Varint from the stream. If larger than 32 bits, discard the
- * upper bits.
- */
- public int readRawVarint32() throws IOException {
- byte tmp = readRawByte();
- if (tmp >= 0) {
- return tmp;
- }
- int result = tmp & 0x7f;
- if ((tmp = readRawByte()) >= 0) {
- result |= tmp << 7;
- } else {
- result |= (tmp & 0x7f) << 7;
- if ((tmp = readRawByte()) >= 0) {
- result |= tmp << 14;
- } else {
- result |= (tmp & 0x7f) << 14;
- if ((tmp = readRawByte()) >= 0) {
- result |= tmp << 21;
- } else {
- result |= (tmp & 0x7f) << 21;
- result |= (tmp = readRawByte()) << 28;
- if (tmp < 0) {
- // Discard upper 32 bits.
- for (int i = 0; i < 5; i++) {
- if (readRawByte() >= 0)
- return result;
- }
- throw InvalidProtocolBufferException.malformedVarint();
- }
- }
- }
- }
- return result;
- }
-
- /** Read a raw Varint from the stream. */
- public long readRawVarint64() throws IOException {
- int shift = 0;
- long result = 0;
- while (shift < 64) {
- byte b = readRawByte();
- result |= (long) (b & 0x7F) << shift;
- if ((b & 0x80) == 0)
- return result;
- shift += 7;
- }
- throw InvalidProtocolBufferException.malformedVarint();
- }
-
- /** Read a 32-bit little-endian integer from the stream. */
- public int readRawLittleEndian32() throws IOException {
- byte b1 = readRawByte();
- byte b2 = readRawByte();
- byte b3 = readRawByte();
- byte b4 = readRawByte();
- return (((int) b1 & 0xff)) | (((int) b2 & 0xff) << 8) | (((int) b3 & 0xff) << 16) | (((int) b4 & 0xff) << 24);
- }
-
- /** Read a 64-bit little-endian integer from the stream. */
- public long readRawLittleEndian64() throws IOException {
- byte b1 = readRawByte();
- byte b2 = readRawByte();
- byte b3 = readRawByte();
- byte b4 = readRawByte();
- byte b5 = readRawByte();
- byte b6 = readRawByte();
- byte b7 = readRawByte();
- byte b8 = readRawByte();
- return (((long) b1 & 0xff)) | (((long) b2 & 0xff) << 8) | (((long) b3 & 0xff) << 16) | (((long) b4 & 0xff) << 24) | (((long) b5 & 0xff) << 32) | (((long) b6 & 0xff) << 40) | (((long) b7 & 0xff) << 48) | (((long) b8 & 0xff) << 56);
- }
-
- /**
- * Decode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers into
- * values that can be efficiently encoded with varint. (Otherwise, negative
- * values must be sign-extended to 64 bits to be varint encoded, thus always
- * taking 10 bytes on the wire.)
- *
- * @param n
- * An unsigned 32-bit integer, stored in a signed int because
- * Java has no explicit unsigned support.
- * @return A signed 32-bit integer.
- */
- public static int decodeZigZag32(int n) {
- return (n >>> 1) ^ -(n & 1);
- }
-
- /**
- * Decode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into
- * values that can be efficiently encoded with varint. (Otherwise, negative
- * values must be sign-extended to 64 bits to be varint encoded, thus always
- * taking 10 bytes on the wire.)
- *
- * @param n
- * An unsigned 64-bit integer, stored in a signed int because
- * Java has no explicit unsigned support.
- * @return A signed 64-bit integer.
- */
- public static long decodeZigZag64(long n) {
- return (n >>> 1) ^ -(n & 1);
- }
-
- /**
- * Read one byte from the input.
- *
- * @throws InvalidProtocolBufferException
- * The end of the stream or the current limit was reached.
- */
- public byte readRawByte() throws IOException {
- if( pos >= limit ) {
- throw new EOFException();
- }
- int rc = in.read();
- if( rc < 0 ) {
- throw new EOFException();
- }
- pos++;
- return (byte)( rc & 0xFF);
- }
-
- /**
- * Read a fixed size of bytes from the input.
- *
- * @throws InvalidProtocolBufferException
- * The end of the stream or the current limit was reached.
- */
- public Buffer readRawBytes(int size) throws IOException {
- if( size == 0) {
- return new Buffer(new byte[]{});
- }
- if( this.pos+size > limit ) {
- throw new EOFException();
- }
-
- // If the underlying stream is a ByteArrayInputStream
- // then we can avoid an array copy.
- if( bis!=null ) {
- Buffer rc = bis.readBuffer(size);
- if( rc==null || rc.getLength() < size ) {
- throw new EOFException();
- }
- this.pos += rc.getLength();
- return rc;
- }
-
- // Otherwise we, have to do it the old fasioned way
- byte[] rc = new byte[size];
- int c;
- int pos=0;
- while( pos < size ) {
- c = in.read(rc, pos, size-pos);
- if( c < 0 ) {
- throw new EOFException();
- }
- this.pos += c;
- pos += c;
- }
-
- return new Buffer(rc);
- }
-
- /**
- * Reads and discards {@code size} bytes.
- *
- * @throws InvalidProtocolBufferException
- * The end of the stream or the current limit was reached.
- */
- public void skipRawBytes(int size) throws IOException {
- int pos = 0;
- while (pos < size) {
- int n = (int) in.skip(size - pos);
- pos += n;
- }
- }
-
- public int pushLimit(int limit) {
- int rc = this.limit;
- this.limit = pos+limit;
- return rc;
- }
-
- public void popLimit(int limit) {
- this.limit = limit;
- }
-
-}
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc.
+// http://code.google.com/p/protobuf/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.activemq.protobuf;
+
+import java.io.EOFException;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+
+/**
+ * Reads and decodes protocol message fields.
+ *
+ * This class contains two kinds of methods: methods that read specific protocol
+ * message constructs and field types (e.g. {@link #readTag()} and
+ * {@link #readInt32()}) and methods that read low-level values (e.g.
+ * {@link #readRawVarint32()} and {@link #readRawBytes}). If you are reading
+ * encoded protocol messages, you should use the former methods, but if you are
+ * reading some other format of your own design, use the latter.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public final class CodedInputStream extends FilterInputStream {
+
+ private int lastTag = 0;
+ private int limit = Integer.MAX_VALUE;
+ private int pos;
+ private BufferInputStream bis;
+
+ public CodedInputStream(InputStream in) {
+ super(in);
+ if( in.getClass() == BufferInputStream.class ) {
+ bis = (BufferInputStream)in;
+ }
+ }
+
+ public CodedInputStream(Buffer data) {
+ this(new BufferInputStream(data));
+ limit = data.length;
+ }
+
+ public CodedInputStream(byte[] data) {
+ this(new BufferInputStream(data));
+ limit = data.length;
+ }
+
+ /**
+ * Attempt to read a field tag, returning zero if we have reached EOF.
+ * Protocol message parsers use this to read tags, since a protocol message
+ * may legally end wherever a tag occurs, and zero is not a valid tag
+ * number.
+ */
+ public int readTag() throws IOException {
+ if( pos >= limit ) {
+ lastTag=0;
+ return 0;
+ }
+ try {
+ lastTag = readRawVarint32();
+ if (lastTag == 0) {
+ // If we actually read zero, that's not a valid tag.
+ throw InvalidProtocolBufferException.invalidTag();
+ }
+ return lastTag;
+ } catch (EOFException e) {
+ lastTag=0;
+ return 0;
+ }
+ }
+
+
+ /**
+ * 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
+ * tag.
+ *
+ * @throws InvalidProtocolBufferException
+ * {@code value} does not match the last tag.
+ */
+ public void checkLastTagWas(int value) throws InvalidProtocolBufferException {
+ if (lastTag != value) {
+ throw InvalidProtocolBufferException.invalidEndTag();
+ }
+ }
+
+ /**
+ * Reads and discards a single field, given its tag value.
+ *
+ * @return {@code false} if the tag is an endgroup tag, in which case
+ * nothing is skipped. Otherwise, returns {@code true}.
+ */
+ public boolean skipField(int tag) throws IOException {
+ switch (WireFormat.getTagWireType(tag)) {
+ case WireFormat.WIRETYPE_VARINT:
+ readInt32();
+ return true;
+ case WireFormat.WIRETYPE_FIXED64:
+ readRawLittleEndian64();
+ return true;
+ case WireFormat.WIRETYPE_LENGTH_DELIMITED:
+ skipRawBytes(readRawVarint32());
+ return true;
+ case WireFormat.WIRETYPE_START_GROUP:
+ skipMessage();
+ checkLastTagWas(WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP));
+ return true;
+ case WireFormat.WIRETYPE_END_GROUP:
+ return false;
+ case WireFormat.WIRETYPE_FIXED32:
+ readRawLittleEndian32();
+ return true;
+ default:
+ throw InvalidProtocolBufferException.invalidWireType();
+ }
+ }
+
+ /**
+ * Reads and discards an entire message. This will read either until EOF or
+ * until an endgroup tag, whichever comes first.
+ */
+ public void skipMessage() throws IOException {
+ while (true) {
+ int tag = readTag();
+ if (tag == 0 || !skipField(tag))
+ return;
+ }
+ }
+
+ // -----------------------------------------------------------------
+
+ /** Read a {@code double} field value from the stream. */
+ public double readDouble() throws IOException {
+ return Double.longBitsToDouble(readRawLittleEndian64());
+ }
+
+ /** Read a {@code float} field value from the stream. */
+ public float readFloat() throws IOException {
+ return Float.intBitsToFloat(readRawLittleEndian32());
+ }
+
+ /** Read a {@code uint64} field value from the stream. */
+ public long readUInt64() throws IOException {
+ return readRawVarint64();
+ }
+
+ /** Read an {@code int64} field value from the stream. */
+ public long readInt64() throws IOException {
+ return readRawVarint64();
+ }
+
+ /** Read an {@code int32} field value from the stream. */
+ public int readInt32() throws IOException {
+ return readRawVarint32();
+ }
+
+ /** Read a {@code fixed64} field value from the stream. */
+ public long readFixed64() throws IOException {
+ return readRawLittleEndian64();
+ }
+
+ /** Read a {@code fixed32} field value from the stream. */
+ public int readFixed32() throws IOException {
+ return readRawLittleEndian32();
+ }
+
+ /** Read a {@code bool} field value from the stream. */
+ public boolean readBool() throws IOException {
+ return readRawVarint32() != 0;
+ }
+
+ /** Read a {@code string} field value from the stream. */
+ public String readString() throws IOException {
+ int size = readRawVarint32();
+ Buffer data = readRawBytes(size);
+ return new String(data.data, data.offset, data.length, "UTF-8");
+ }
+
+ /** Read a {@code bytes} field value from the stream. */
+ public Buffer readBytes() throws IOException {
+ int size = readRawVarint32();
+ return readRawBytes(size);
+ }
+
+ /** Read a {@code uint32} field value from the stream. */
+ public int readUInt32() throws IOException {
+ return readRawVarint32();
+ }
+
+ /**
+ * Read an enum field value from the stream. Caller is responsible for
+ * converting the numeric value to an actual enum.
+ */
+ public int readEnum() throws IOException {
+ return readRawVarint32();
+ }
+
+ /** Read an {@code sfixed32} field value from the stream. */
+ public int readSFixed32() throws IOException {
+ return readRawLittleEndian32();
+ }
+
+ /** Read an {@code sfixed64} field value from the stream. */
+ public long readSFixed64() throws IOException {
+ return readRawLittleEndian64();
+ }
+
+ /** Read an {@code sint32} field value from the stream. */
+ public int readSInt32() throws IOException {
+ return decodeZigZag32(readRawVarint32());
+ }
+
+ /** Read an {@code sint64} field value from the stream. */
+ public long readSInt64() throws IOException {
+ return decodeZigZag64(readRawVarint64());
+ }
+
+ // =================================================================
+
+ /**
+ * Read a raw Varint from the stream. If larger than 32 bits, discard the
+ * upper bits.
+ */
+ public int readRawVarint32() throws IOException {
+ byte tmp = readRawByte();
+ if (tmp >= 0) {
+ return tmp;
+ }
+ int result = tmp & 0x7f;
+ if ((tmp = readRawByte()) >= 0) {
+ result |= tmp << 7;
+ } else {
+ result |= (tmp & 0x7f) << 7;
+ if ((tmp = readRawByte()) >= 0) {
+ result |= tmp << 14;
+ } else {
+ result |= (tmp & 0x7f) << 14;
+ if ((tmp = readRawByte()) >= 0) {
+ result |= tmp << 21;
+ } else {
+ result |= (tmp & 0x7f) << 21;
+ result |= (tmp = readRawByte()) << 28;
+ if (tmp < 0) {
+ // Discard upper 32 bits.
+ for (int i = 0; i < 5; i++) {
+ if (readRawByte() >= 0)
+ return result;
+ }
+ throw InvalidProtocolBufferException.malformedVarint();
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ /** Read a raw Varint from the stream. */
+ public long readRawVarint64() throws IOException {
+ int shift = 0;
+ long result = 0;
+ while (shift < 64) {
+ byte b = readRawByte();
+ result |= (long) (b & 0x7F) << shift;
+ if ((b & 0x80) == 0)
+ return result;
+ shift += 7;
+ }
+ throw InvalidProtocolBufferException.malformedVarint();
+ }
+
+ /** Read a 32-bit little-endian integer from the stream. */
+ public int readRawLittleEndian32() throws IOException {
+ byte b1 = readRawByte();
+ byte b2 = readRawByte();
+ byte b3 = readRawByte();
+ byte b4 = readRawByte();
+ return (((int) b1 & 0xff)) | (((int) b2 & 0xff) << 8) | (((int) b3 & 0xff) << 16) | (((int) b4 & 0xff) << 24);
+ }
+
+ /** Read a 64-bit little-endian integer from the stream. */
+ public long readRawLittleEndian64() throws IOException {
+ byte b1 = readRawByte();
+ byte b2 = readRawByte();
+ byte b3 = readRawByte();
+ byte b4 = readRawByte();
+ byte b5 = readRawByte();
+ byte b6 = readRawByte();
+ byte b7 = readRawByte();
+ byte b8 = readRawByte();
+ return (((long) b1 & 0xff)) | (((long) b2 & 0xff) << 8) | (((long) b3 & 0xff) << 16) | (((long) b4 & 0xff) << 24) | (((long) b5 & 0xff) << 32) | (((long) b6 & 0xff) << 40) | (((long) b7 & 0xff) << 48) | (((long) b8 & 0xff) << 56);
+ }
+
+ /**
+ * Decode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers into
+ * values that can be efficiently encoded with varint. (Otherwise, negative
+ * values must be sign-extended to 64 bits to be varint encoded, thus always
+ * taking 10 bytes on the wire.)
+ *
+ * @param n
+ * An unsigned 32-bit integer, stored in a signed int because
+ * Java has no explicit unsigned support.
+ * @return A signed 32-bit integer.
+ */
+ public static int decodeZigZag32(int n) {
+ return (n >>> 1) ^ -(n & 1);
+ }
+
+ /**
+ * Decode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into
+ * values that can be efficiently encoded with varint. (Otherwise, negative
+ * values must be sign-extended to 64 bits to be varint encoded, thus always
+ * taking 10 bytes on the wire.)
+ *
+ * @param n
+ * An unsigned 64-bit integer, stored in a signed int because
+ * Java has no explicit unsigned support.
+ * @return A signed 64-bit integer.
+ */
+ public static long decodeZigZag64(long n) {
+ return (n >>> 1) ^ -(n & 1);
+ }
+
+ /**
+ * Read one byte from the input.
+ *
+ * @throws InvalidProtocolBufferException
+ * The end of the stream or the current limit was reached.
+ */
+ public byte readRawByte() throws IOException {
+ if( pos >= limit ) {
+ throw new EOFException();
+ }
+ int rc = in.read();
+ if( rc < 0 ) {
+ throw new EOFException();
+ }
+ pos++;
+ return (byte)( rc & 0xFF);
+ }
+
+ /**
+ * Read a fixed size of bytes from the input.
+ *
+ * @throws InvalidProtocolBufferException
+ * The end of the stream or the current limit was reached.
+ */
+ public Buffer readRawBytes(int size) throws IOException {
+ if( size == 0) {
+ return new Buffer(new byte[]{});
+ }
+ if( this.pos+size > limit ) {
+ throw new EOFException();
+ }
+
+ // If the underlying stream is a ByteArrayInputStream
+ // then we can avoid an array copy.
+ if( bis!=null ) {
+ Buffer rc = bis.readBuffer(size);
+ if( rc==null || rc.getLength() < size ) {
+ throw new EOFException();
+ }
+ this.pos += rc.getLength();
+ return rc;
+ }
+
+ // Otherwise we, have to do it the old fasioned way
+ byte[] rc = new byte[size];
+ int c;
+ int pos=0;
+ while( pos < size ) {
+ c = in.read(rc, pos, size-pos);
+ if( c < 0 ) {
+ throw new EOFException();
+ }
+ this.pos += c;
+ pos += c;
+ }
+
+ return new Buffer(rc);
+ }
+
+ /**
+ * Reads and discards {@code size} bytes.
+ *
+ * @throws InvalidProtocolBufferException
+ * The end of the stream or the current limit was reached.
+ */
+ public void skipRawBytes(int size) throws IOException {
+ int pos = 0;
+ while (pos < size) {
+ int n = (int) in.skip(size - pos);
+ pos += n;
+ }
+ }
+
+ public int pushLimit(int limit) {
+ int rc = this.limit;
+ this.limit = pos+limit;
+ return rc;
+ }
+
+ public void popLimit(int limit) {
+ this.limit = limit;
+ }
+
+}
Propchange: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedOutputStream.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedOutputStream.java?rev=781514&r1=781513&r2=781514&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedOutputStream.java (original)
+++ activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedOutputStream.java Wed Jun 3 19:20:13 2009
@@ -1,482 +1,482 @@
-//Protocol Buffers - Google's data interchange format
-//Copyright 2008 Google Inc.
-//http://code.google.com/p/protobuf/
-//
-//Licensed under the Apache License, Version 2.0 (the "License");
-//you may not use this file except in compliance with the License.
-//You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-//Unless required by applicable law or agreed to in writing, software
-//distributed under the License is distributed on an "AS IS" BASIS,
-//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//See the License for the specific language governing permissions and
-//limitations under the License.
-package org.apache.activemq.protobuf;
-
-import java.io.FilterOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-
-/**
- * Encodes and writes protocol message fields.
- *
- * <p>
- * This class contains two kinds of methods: methods that write specific
- * protocol message constructs and field types (e.g. {@link #writeTag} and
- * {@link #writeInt32}) and methods that write low-level values (e.g.
- * {@link #writeRawVarint32} and {@link #writeRawBytes}). If you are writing
- * encoded protocol messages, you should use the former methods, but if you are
- * writing some other format of your own design, use the latter.
- *
- * <p>
- * This class is totally unsynchronized.
- *
- * @author kneton@google.com Kenton Varda
- */
-public final class CodedOutputStream extends FilterOutputStream {
-
- private BufferOutputStream bos;
-
- public CodedOutputStream(OutputStream os) {
- super(os);
- if( os instanceof BufferOutputStream ) {
- bos = (BufferOutputStream)os;
- }
- }
-
- public CodedOutputStream(byte[] data) {
- super(new BufferOutputStream(data));
- }
-
- public CodedOutputStream(Buffer data) {
- super(new BufferOutputStream(data));
- }
-
- // -----------------------------------------------------------------
-
- /** Write a {@code double} field, including tag, to the stream. */
- public void writeDouble(int fieldNumber, double value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
- writeRawLittleEndian64(Double.doubleToRawLongBits(value));
- }
-
- /** Write a {@code float} field, including tag, to the stream. */
- public void writeFloat(int fieldNumber, float value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
- writeRawLittleEndian32(Float.floatToRawIntBits(value));
- }
-
- /** Write a {@code uint64} field, including tag, to the stream. */
- public void writeUInt64(int fieldNumber, long value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
- writeRawVarint64(value);
- }
-
- /** Write an {@code int64} field, including tag, to the stream. */
- public void writeInt64(int fieldNumber, long value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
- writeRawVarint64(value);
- }
-
- /** Write an {@code int32} field, including tag, to the stream. */
- public void writeInt32(int fieldNumber, int value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
- if (value >= 0) {
- writeRawVarint32(value);
- } else {
- // Must sign-extend.
- writeRawVarint64(value);
- }
- }
-
- /** Write a {@code fixed64} field, including tag, to the stream. */
- public void writeFixed64(int fieldNumber, long value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
- writeRawLittleEndian64(value);
- }
-
- /** Write a {@code fixed32} field, including tag, to the stream. */
- public void writeFixed32(int fieldNumber, int value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
- writeRawLittleEndian32(value);
- }
-
- /** Write a {@code bool} field, including tag, to the stream. */
- public void writeBool(int fieldNumber, boolean value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
- writeRawByte(value ? 1 : 0);
- }
-
- /** Write a {@code string} field, including tag, to the stream. */
- public void writeString(int fieldNumber, String value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
- // Unfortunately there does not appear to be any way to tell Java to
- // encode
- // UTF-8 directly into our buffer, so we have to let it create its own
- // byte
- // array and then copy.
- byte[] bytes = value.getBytes("UTF-8");
- writeRawVarint32(bytes.length);
- writeRawBytes(bytes);
- }
-
- /** Write a {@code bytes} field, including tag, to the stream. */
- public void writeBytes(int fieldNumber, Buffer value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
- writeRawVarint32(value.length);
- writeRawBytes(value.data, value.offset, value.length);
- }
-
- /** Write a {@code uint32} field, including tag, to the stream. */
- public void writeUInt32(int fieldNumber, int value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
- writeRawVarint32(value);
- }
-
- /**
- * Write an enum field, including tag, to the stream. Caller is responsible
- * for converting the enum value to its numeric value.
- */
- public void writeEnum(int fieldNumber, int value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
- writeRawVarint32(value);
- }
-
- /** Write an {@code sfixed32} field, including tag, to the stream. */
- public void writeSFixed32(int fieldNumber, int value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
- writeRawLittleEndian32(value);
- }
-
- /** Write an {@code sfixed64} field, including tag, to the stream. */
- public void writeSFixed64(int fieldNumber, long value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
- writeRawLittleEndian64(value);
- }
-
- /** Write an {@code sint32} field, including tag, to the stream. */
- public void writeSInt32(int fieldNumber, int value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
- writeRawVarint32(encodeZigZag32(value));
- }
-
- /** Write an {@code sint64} field, including tag, to the stream. */
- public void writeSInt64(int fieldNumber, long value) throws IOException {
- writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
- writeRawVarint64(encodeZigZag64(value));
- }
-
- // =================================================================
-
- /**
- * Compute the number of bytes that would be needed to encode a {@code
- * double} field, including tag.
- */
- public static int computeDoubleSize(int fieldNumber, double value) {
- return computeTagSize(fieldNumber) + LITTLE_ENDIAN_64_SIZE;
- }
-
- /**
- * Compute the number of bytes that would be needed to encode a {@code
- * float} field, including tag.
- */
- public static int computeFloatSize(int fieldNumber, float value) {
- return computeTagSize(fieldNumber) + LITTLE_ENDIAN_32_SIZE;
- }
-
- /**
- * Compute the number of bytes that would be needed to encode a {@code
- * uint64} field, including tag.
- */
- public static int computeUInt64Size(int fieldNumber, long value) {
- return computeTagSize(fieldNumber) + computeRawVarint64Size(value);
- }
-
- /**
- * Compute the number of bytes that would be needed to encode an {@code
- * int64} field, including tag.
- */
- public static int computeInt64Size(int fieldNumber, long value) {
- return computeTagSize(fieldNumber) + computeRawVarint64Size(value);
- }
-
- /**
- * Compute the number of bytes that would be needed to encode an {@code
- * int32} field, including tag.
- */
- public static int computeInt32Size(int fieldNumber, int value) {
- if (value >= 0) {
- return computeTagSize(fieldNumber) + computeRawVarint32Size(value);
- } else {
- // Must sign-extend.
- return computeTagSize(fieldNumber) + 10;
- }
- }
-
- /**
- * Compute the number of bytes that would be needed to encode a {@code
- * fixed64} field, including tag.
- */
- public static int computeFixed64Size(int fieldNumber, long value) {
- return computeTagSize(fieldNumber) + LITTLE_ENDIAN_64_SIZE;
- }
-
- /**
- * Compute the number of bytes that would be needed to encode a {@code
- * fixed32} field, including tag.
- */
- public static int computeFixed32Size(int fieldNumber, int value) {
- return computeTagSize(fieldNumber) + LITTLE_ENDIAN_32_SIZE;
- }
-
- /**
- * Compute the number of bytes that would be needed to encode a {@code bool}
- * field, including tag.
- */
- public static int computeBoolSize(int fieldNumber, boolean value) {
- return computeTagSize(fieldNumber) + 1;
- }
-
- /**
- * Compute the number of bytes that would be needed to encode a {@code
- * string} field, including tag.
- */
- public static int computeStringSize(int fieldNumber, String value) {
- try {
- byte[] bytes = value.getBytes("UTF-8");
- return computeTagSize(fieldNumber) + computeRawVarint32Size(bytes.length) + bytes.length;
- } catch (java.io.UnsupportedEncodingException e) {
- throw new RuntimeException("UTF-8 not supported.", e);
- }
- }
-
- /**
- * Compute the number of bytes that would be needed to encode a {@code
- * bytes} field, including tag.
- */
- public static int computeBytesSize(int fieldNumber, Buffer value) {
- return computeTagSize(fieldNumber) + computeRawVarint32Size(value.length) + value.length;
- }
-
- /**
- * Compute the number of bytes that would be needed to encode a {@code
- * uint32} field, including tag.
- */
- public static int computeUInt32Size(int fieldNumber, int value) {
- return computeTagSize(fieldNumber) + computeRawVarint32Size(value);
- }
-
- /**
- * Compute the number of bytes that would be needed to encode an enum field,
- * including tag. Caller is responsible for converting the enum value to its
- * numeric value.
- */
- public static int computeEnumSize(int fieldNumber, int value) {
- return computeTagSize(fieldNumber) + computeRawVarint32Size(value);
- }
-
- /**
- * Compute the number of bytes that would be needed to encode an {@code
- * sfixed32} field, including tag.
- */
- public static int computeSFixed32Size(int fieldNumber, int value) {
- return computeTagSize(fieldNumber) + LITTLE_ENDIAN_32_SIZE;
- }
-
- /**
- * Compute the number of bytes that would be needed to encode an {@code
- * sfixed64} field, including tag.
- */
- public static int computeSFixed64Size(int fieldNumber, long value) {
- return computeTagSize(fieldNumber) + LITTLE_ENDIAN_64_SIZE;
- }
-
- /**
- * Compute the number of bytes that would be needed to encode an {@code
- * sint32} field, including tag.
- */
- public static int computeSInt32Size(int fieldNumber, int value) {
- return computeTagSize(fieldNumber) + computeRawVarint32Size(encodeZigZag32(value));
- }
-
- /**
- * Compute the number of bytes that would be needed to encode an {@code
- * sint64} field, including tag.
- */
- public static int computeSInt64Size(int fieldNumber, long value) {
- return computeTagSize(fieldNumber) + computeRawVarint64Size(encodeZigZag64(value));
- }
-
- /** Write a single byte. */
- public void writeRawByte(byte value) throws IOException {
- out.write(value);
- }
-
- /** Write a single byte, represented by an integer value. */
- public void writeRawByte(int value) throws IOException {
- writeRawByte((byte) value);
- }
-
- /** Write an array of bytes. */
- public void writeRawBytes(byte[] value) throws IOException {
- writeRawBytes(value, 0, value.length);
- }
-
- /** Write part of an array of bytes. */
- public void writeRawBytes(byte[] value, int offset, int length) throws IOException {
- out.write(value, offset, length);
- }
-
- public void writeRawBytes(Buffer data) throws IOException {
- out.write(data.data, data.offset, data.length);
- }
-
- /** Encode and write a tag. */
- public void writeTag(int fieldNumber, int wireType) throws IOException {
- writeRawVarint32(WireFormat.makeTag(fieldNumber, wireType));
- }
-
- /** Compute the number of bytes that would be needed to encode a tag. */
- public static int computeTagSize(int fieldNumber) {
- return computeRawVarint32Size(WireFormat.makeTag(fieldNumber, 0));
- }
-
- /**
- * Encode and write a varint. {@code value} is treated as unsigned, so it
- * won't be sign-extended if negative.
- */
- public void writeRawVarint32(int value) throws IOException {
- while (true) {
- if ((value & ~0x7F) == 0) {
- writeRawByte(value);
- return;
- } else {
- writeRawByte((value & 0x7F) | 0x80);
- value >>>= 7;
- }
- }
- }
-
- /**
- * Compute the number of bytes that would be needed to encode a varint.
- * {@code value} is treated as unsigned, so it won't be sign-extended if
- * negative.
- */
- public static int computeRawVarint32Size(int value) {
- if ((value & (0xffffffff << 7)) == 0)
- return 1;
- if ((value & (0xffffffff << 14)) == 0)
- return 2;
- if ((value & (0xffffffff << 21)) == 0)
- return 3;
- if ((value & (0xffffffff << 28)) == 0)
- return 4;
- return 5;
- }
-
- /** Encode and write a varint. */
- public void writeRawVarint64(long value) throws IOException {
- while (true) {
- if ((value & ~0x7FL) == 0) {
- writeRawByte((int) value);
- return;
- } else {
- writeRawByte(((int) value & 0x7F) | 0x80);
- value >>>= 7;
- }
- }
- }
-
- /** Compute the number of bytes that would be needed to encode a varint. */
- public static int computeRawVarint64Size(long value) {
- if ((value & (0xffffffffffffffffL << 7)) == 0)
- return 1;
- if ((value & (0xffffffffffffffffL << 14)) == 0)
- return 2;
- if ((value & (0xffffffffffffffffL << 21)) == 0)
- return 3;
- if ((value & (0xffffffffffffffffL << 28)) == 0)
- return 4;
- if ((value & (0xffffffffffffffffL << 35)) == 0)
- return 5;
- if ((value & (0xffffffffffffffffL << 42)) == 0)
- return 6;
- if ((value & (0xffffffffffffffffL << 49)) == 0)
- return 7;
- if ((value & (0xffffffffffffffffL << 56)) == 0)
- return 8;
- if ((value & (0xffffffffffffffffL << 63)) == 0)
- return 9;
- return 10;
- }
-
- /** Write a little-endian 32-bit integer. */
- public void writeRawLittleEndian32(int value) throws IOException {
- writeRawByte((value) & 0xFF);
- writeRawByte((value >> 8) & 0xFF);
- writeRawByte((value >> 16) & 0xFF);
- writeRawByte((value >> 24) & 0xFF);
- }
-
- public static final int LITTLE_ENDIAN_32_SIZE = 4;
-
- /** Write a little-endian 64-bit integer. */
- public void writeRawLittleEndian64(long value) throws IOException {
- writeRawByte((int) (value) & 0xFF);
- writeRawByte((int) (value >> 8) & 0xFF);
- writeRawByte((int) (value >> 16) & 0xFF);
- writeRawByte((int) (value >> 24) & 0xFF);
- writeRawByte((int) (value >> 32) & 0xFF);
- writeRawByte((int) (value >> 40) & 0xFF);
- writeRawByte((int) (value >> 48) & 0xFF);
- writeRawByte((int) (value >> 56) & 0xFF);
- }
-
- public static final int LITTLE_ENDIAN_64_SIZE = 8;
-
- /**
- * Encode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers into
- * values that can be efficiently encoded with varint. (Otherwise, negative
- * values must be sign-extended to 64 bits to be varint encoded, thus always
- * taking 10 bytes on the wire.)
- *
- * @param n
- * A signed 32-bit integer.
- * @return An unsigned 32-bit integer, stored in a signed int because Java
- * has no explicit unsigned support.
- */
- public static int encodeZigZag32(int n) {
- // Note: the right-shift must be arithmetic
- return (n << 1) ^ (n >> 31);
- }
-
- /**
- * Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into
- * values that can be efficiently encoded with varint. (Otherwise, negative
- * values must be sign-extended to 64 bits to be varint encoded, thus always
- * taking 10 bytes on the wire.)
- *
- * @param n
- * A signed 64-bit integer.
- * @return An unsigned 64-bit integer, stored in a signed int because Java
- * has no explicit unsigned support.
- */
- public static long encodeZigZag64(long n) {
- // Note: the right-shift must be arithmetic
- return (n << 1) ^ (n >> 63);
- }
-
- public void checkNoSpaceLeft() {
- }
-
- public Buffer getNextBuffer(int size) throws IOException {
- if( bos==null ) {
- return null;
- }
- return bos.getNextBuffer(size);
- }
-
-}
+//Protocol Buffers - Google's data interchange format
+//Copyright 2008 Google Inc.
+//http://code.google.com/p/protobuf/
+//
+//Licensed under the Apache License, Version 2.0 (the "License");
+//you may not use this file except in compliance with the License.
+//You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing, software
+//distributed under the License is distributed on an "AS IS" BASIS,
+//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//See the License for the specific language governing permissions and
+//limitations under the License.
+package org.apache.activemq.protobuf;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+
+/**
+ * Encodes and writes protocol message fields.
+ *
+ * <p>
+ * This class contains two kinds of methods: methods that write specific
+ * protocol message constructs and field types (e.g. {@link #writeTag} and
+ * {@link #writeInt32}) and methods that write low-level values (e.g.
+ * {@link #writeRawVarint32} and {@link #writeRawBytes}). If you are writing
+ * encoded protocol messages, you should use the former methods, but if you are
+ * writing some other format of your own design, use the latter.
+ *
+ * <p>
+ * This class is totally unsynchronized.
+ *
+ * @author kneton@google.com Kenton Varda
+ */
+public final class CodedOutputStream extends FilterOutputStream {
+
+ private BufferOutputStream bos;
+
+ public CodedOutputStream(OutputStream os) {
+ super(os);
+ if( os instanceof BufferOutputStream ) {
+ bos = (BufferOutputStream)os;
+ }
+ }
+
+ public CodedOutputStream(byte[] data) {
+ super(new BufferOutputStream(data));
+ }
+
+ public CodedOutputStream(Buffer data) {
+ super(new BufferOutputStream(data));
+ }
+
+ // -----------------------------------------------------------------
+
+ /** Write a {@code double} field, including tag, to the stream. */
+ public void writeDouble(int fieldNumber, double value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
+ writeRawLittleEndian64(Double.doubleToRawLongBits(value));
+ }
+
+ /** Write a {@code float} field, including tag, to the stream. */
+ public void writeFloat(int fieldNumber, float value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
+ writeRawLittleEndian32(Float.floatToRawIntBits(value));
+ }
+
+ /** Write a {@code uint64} field, including tag, to the stream. */
+ public void writeUInt64(int fieldNumber, long value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeRawVarint64(value);
+ }
+
+ /** Write an {@code int64} field, including tag, to the stream. */
+ public void writeInt64(int fieldNumber, long value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeRawVarint64(value);
+ }
+
+ /** Write an {@code int32} field, including tag, to the stream. */
+ public void writeInt32(int fieldNumber, int value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ if (value >= 0) {
+ writeRawVarint32(value);
+ } else {
+ // Must sign-extend.
+ writeRawVarint64(value);
+ }
+ }
+
+ /** Write a {@code fixed64} field, including tag, to the stream. */
+ public void writeFixed64(int fieldNumber, long value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
+ writeRawLittleEndian64(value);
+ }
+
+ /** Write a {@code fixed32} field, including tag, to the stream. */
+ public void writeFixed32(int fieldNumber, int value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
+ writeRawLittleEndian32(value);
+ }
+
+ /** Write a {@code bool} field, including tag, to the stream. */
+ public void writeBool(int fieldNumber, boolean value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeRawByte(value ? 1 : 0);
+ }
+
+ /** Write a {@code string} field, including tag, to the stream. */
+ public void writeString(int fieldNumber, String value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ // Unfortunately there does not appear to be any way to tell Java to
+ // encode
+ // UTF-8 directly into our buffer, so we have to let it create its own
+ // byte
+ // array and then copy.
+ byte[] bytes = value.getBytes("UTF-8");
+ writeRawVarint32(bytes.length);
+ writeRawBytes(bytes);
+ }
+
+ /** Write a {@code bytes} field, including tag, to the stream. */
+ public void writeBytes(int fieldNumber, Buffer value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_LENGTH_DELIMITED);
+ writeRawVarint32(value.length);
+ writeRawBytes(value.data, value.offset, value.length);
+ }
+
+ /** Write a {@code uint32} field, including tag, to the stream. */
+ public void writeUInt32(int fieldNumber, int value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeRawVarint32(value);
+ }
+
+ /**
+ * Write an enum field, including tag, to the stream. Caller is responsible
+ * for converting the enum value to its numeric value.
+ */
+ public void writeEnum(int fieldNumber, int value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeRawVarint32(value);
+ }
+
+ /** Write an {@code sfixed32} field, including tag, to the stream. */
+ public void writeSFixed32(int fieldNumber, int value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED32);
+ writeRawLittleEndian32(value);
+ }
+
+ /** Write an {@code sfixed64} field, including tag, to the stream. */
+ public void writeSFixed64(int fieldNumber, long value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_FIXED64);
+ writeRawLittleEndian64(value);
+ }
+
+ /** Write an {@code sint32} field, including tag, to the stream. */
+ public void writeSInt32(int fieldNumber, int value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeRawVarint32(encodeZigZag32(value));
+ }
+
+ /** Write an {@code sint64} field, including tag, to the stream. */
+ public void writeSInt64(int fieldNumber, long value) throws IOException {
+ writeTag(fieldNumber, WireFormat.WIRETYPE_VARINT);
+ writeRawVarint64(encodeZigZag64(value));
+ }
+
+ // =================================================================
+
+ /**
+ * Compute the number of bytes that would be needed to encode a {@code
+ * double} field, including tag.
+ */
+ public static int computeDoubleSize(int fieldNumber, double value) {
+ return computeTagSize(fieldNumber) + LITTLE_ENDIAN_64_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a {@code
+ * float} field, including tag.
+ */
+ public static int computeFloatSize(int fieldNumber, float value) {
+ return computeTagSize(fieldNumber) + LITTLE_ENDIAN_32_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a {@code
+ * uint64} field, including tag.
+ */
+ public static int computeUInt64Size(int fieldNumber, long value) {
+ return computeTagSize(fieldNumber) + computeRawVarint64Size(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an {@code
+ * int64} field, including tag.
+ */
+ public static int computeInt64Size(int fieldNumber, long value) {
+ return computeTagSize(fieldNumber) + computeRawVarint64Size(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an {@code
+ * int32} field, including tag.
+ */
+ public static int computeInt32Size(int fieldNumber, int value) {
+ if (value >= 0) {
+ return computeTagSize(fieldNumber) + computeRawVarint32Size(value);
+ } else {
+ // Must sign-extend.
+ return computeTagSize(fieldNumber) + 10;
+ }
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a {@code
+ * fixed64} field, including tag.
+ */
+ public static int computeFixed64Size(int fieldNumber, long value) {
+ return computeTagSize(fieldNumber) + LITTLE_ENDIAN_64_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a {@code
+ * fixed32} field, including tag.
+ */
+ public static int computeFixed32Size(int fieldNumber, int value) {
+ return computeTagSize(fieldNumber) + LITTLE_ENDIAN_32_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a {@code bool}
+ * field, including tag.
+ */
+ public static int computeBoolSize(int fieldNumber, boolean value) {
+ return computeTagSize(fieldNumber) + 1;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a {@code
+ * string} field, including tag.
+ */
+ public static int computeStringSize(int fieldNumber, String value) {
+ try {
+ byte[] bytes = value.getBytes("UTF-8");
+ return computeTagSize(fieldNumber) + computeRawVarint32Size(bytes.length) + bytes.length;
+ } catch (java.io.UnsupportedEncodingException e) {
+ throw new RuntimeException("UTF-8 not supported.", e);
+ }
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a {@code
+ * bytes} field, including tag.
+ */
+ public static int computeBytesSize(int fieldNumber, Buffer value) {
+ return computeTagSize(fieldNumber) + computeRawVarint32Size(value.length) + value.length;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a {@code
+ * uint32} field, including tag.
+ */
+ public static int computeUInt32Size(int fieldNumber, int value) {
+ return computeTagSize(fieldNumber) + computeRawVarint32Size(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an enum field,
+ * including tag. Caller is responsible for converting the enum value to its
+ * numeric value.
+ */
+ public static int computeEnumSize(int fieldNumber, int value) {
+ return computeTagSize(fieldNumber) + computeRawVarint32Size(value);
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an {@code
+ * sfixed32} field, including tag.
+ */
+ public static int computeSFixed32Size(int fieldNumber, int value) {
+ return computeTagSize(fieldNumber) + LITTLE_ENDIAN_32_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an {@code
+ * sfixed64} field, including tag.
+ */
+ public static int computeSFixed64Size(int fieldNumber, long value) {
+ return computeTagSize(fieldNumber) + LITTLE_ENDIAN_64_SIZE;
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an {@code
+ * sint32} field, including tag.
+ */
+ public static int computeSInt32Size(int fieldNumber, int value) {
+ return computeTagSize(fieldNumber) + computeRawVarint32Size(encodeZigZag32(value));
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode an {@code
+ * sint64} field, including tag.
+ */
+ public static int computeSInt64Size(int fieldNumber, long value) {
+ return computeTagSize(fieldNumber) + computeRawVarint64Size(encodeZigZag64(value));
+ }
+
+ /** Write a single byte. */
+ public void writeRawByte(byte value) throws IOException {
+ out.write(value);
+ }
+
+ /** Write a single byte, represented by an integer value. */
+ public void writeRawByte(int value) throws IOException {
+ writeRawByte((byte) value);
+ }
+
+ /** Write an array of bytes. */
+ public void writeRawBytes(byte[] value) throws IOException {
+ writeRawBytes(value, 0, value.length);
+ }
+
+ /** Write part of an array of bytes. */
+ public void writeRawBytes(byte[] value, int offset, int length) throws IOException {
+ out.write(value, offset, length);
+ }
+
+ public void writeRawBytes(Buffer data) throws IOException {
+ out.write(data.data, data.offset, data.length);
+ }
+
+ /** Encode and write a tag. */
+ public void writeTag(int fieldNumber, int wireType) throws IOException {
+ writeRawVarint32(WireFormat.makeTag(fieldNumber, wireType));
+ }
+
+ /** Compute the number of bytes that would be needed to encode a tag. */
+ public static int computeTagSize(int fieldNumber) {
+ return computeRawVarint32Size(WireFormat.makeTag(fieldNumber, 0));
+ }
+
+ /**
+ * Encode and write a varint. {@code value} is treated as unsigned, so it
+ * won't be sign-extended if negative.
+ */
+ public void writeRawVarint32(int value) throws IOException {
+ while (true) {
+ if ((value & ~0x7F) == 0) {
+ writeRawByte(value);
+ return;
+ } else {
+ writeRawByte((value & 0x7F) | 0x80);
+ value >>>= 7;
+ }
+ }
+ }
+
+ /**
+ * Compute the number of bytes that would be needed to encode a varint.
+ * {@code value} is treated as unsigned, so it won't be sign-extended if
+ * negative.
+ */
+ public static int computeRawVarint32Size(int value) {
+ if ((value & (0xffffffff << 7)) == 0)
+ return 1;
+ if ((value & (0xffffffff << 14)) == 0)
+ return 2;
+ if ((value & (0xffffffff << 21)) == 0)
+ return 3;
+ if ((value & (0xffffffff << 28)) == 0)
+ return 4;
+ return 5;
+ }
+
+ /** Encode and write a varint. */
+ public void writeRawVarint64(long value) throws IOException {
+ while (true) {
+ if ((value & ~0x7FL) == 0) {
+ writeRawByte((int) value);
+ return;
+ } else {
+ writeRawByte(((int) value & 0x7F) | 0x80);
+ value >>>= 7;
+ }
+ }
+ }
+
+ /** Compute the number of bytes that would be needed to encode a varint. */
+ public static int computeRawVarint64Size(long value) {
+ if ((value & (0xffffffffffffffffL << 7)) == 0)
+ return 1;
+ if ((value & (0xffffffffffffffffL << 14)) == 0)
+ return 2;
+ if ((value & (0xffffffffffffffffL << 21)) == 0)
+ return 3;
+ if ((value & (0xffffffffffffffffL << 28)) == 0)
+ return 4;
+ if ((value & (0xffffffffffffffffL << 35)) == 0)
+ return 5;
+ if ((value & (0xffffffffffffffffL << 42)) == 0)
+ return 6;
+ if ((value & (0xffffffffffffffffL << 49)) == 0)
+ return 7;
+ if ((value & (0xffffffffffffffffL << 56)) == 0)
+ return 8;
+ if ((value & (0xffffffffffffffffL << 63)) == 0)
+ return 9;
+ return 10;
+ }
+
+ /** Write a little-endian 32-bit integer. */
+ public void writeRawLittleEndian32(int value) throws IOException {
+ writeRawByte((value) & 0xFF);
+ writeRawByte((value >> 8) & 0xFF);
+ writeRawByte((value >> 16) & 0xFF);
+ writeRawByte((value >> 24) & 0xFF);
+ }
+
+ public static final int LITTLE_ENDIAN_32_SIZE = 4;
+
+ /** Write a little-endian 64-bit integer. */
+ public void writeRawLittleEndian64(long value) throws IOException {
+ writeRawByte((int) (value) & 0xFF);
+ writeRawByte((int) (value >> 8) & 0xFF);
+ writeRawByte((int) (value >> 16) & 0xFF);
+ writeRawByte((int) (value >> 24) & 0xFF);
+ writeRawByte((int) (value >> 32) & 0xFF);
+ writeRawByte((int) (value >> 40) & 0xFF);
+ writeRawByte((int) (value >> 48) & 0xFF);
+ writeRawByte((int) (value >> 56) & 0xFF);
+ }
+
+ public static final int LITTLE_ENDIAN_64_SIZE = 8;
+
+ /**
+ * Encode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers into
+ * values that can be efficiently encoded with varint. (Otherwise, negative
+ * values must be sign-extended to 64 bits to be varint encoded, thus always
+ * taking 10 bytes on the wire.)
+ *
+ * @param n
+ * A signed 32-bit integer.
+ * @return An unsigned 32-bit integer, stored in a signed int because Java
+ * has no explicit unsigned support.
+ */
+ public static int encodeZigZag32(int n) {
+ // Note: the right-shift must be arithmetic
+ return (n << 1) ^ (n >> 31);
+ }
+
+ /**
+ * Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into
+ * values that can be efficiently encoded with varint. (Otherwise, negative
+ * values must be sign-extended to 64 bits to be varint encoded, thus always
+ * taking 10 bytes on the wire.)
+ *
+ * @param n
+ * A signed 64-bit integer.
+ * @return An unsigned 64-bit integer, stored in a signed int because Java
+ * has no explicit unsigned support.
+ */
+ public static long encodeZigZag64(long n) {
+ // Note: the right-shift must be arithmetic
+ return (n << 1) ^ (n >> 63);
+ }
+
+ public void checkNoSpaceLeft() {
+ }
+
+ public Buffer getNextBuffer(int size) throws IOException {
+ if( bos==null ) {
+ return null;
+ }
+ return bos.getNextBuffer(size);
+ }
+
+}
Propchange: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/CodedOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/DeferredDecodeMessage.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/InvalidProtocolBufferException.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/InvalidProtocolBufferException.java?rev=781514&r1=781513&r2=781514&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/InvalidProtocolBufferException.java (original)
+++ activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/InvalidProtocolBufferException.java Wed Jun 3 19:20:13 2009
@@ -1,66 +1,66 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc.
-// http://code.google.com/p/protobuf/
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package org.apache.activemq.protobuf;
-
-import java.io.IOException;
-
-/**
- * Thrown when a protocol message being parsed is invalid in some way, e.g. it
- * contains a malformed varint or a negative byte length.
- *
- * @author kenton@google.com Kenton Varda
- */
-public class InvalidProtocolBufferException extends IOException {
- private static final long serialVersionUID = 5685337441004132240L;
-
- public InvalidProtocolBufferException(String description) {
- super(description);
- }
-
- static InvalidProtocolBufferException truncatedMessage() {
- return 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.");
- }
-
- static InvalidProtocolBufferException negativeSize() {
- return new InvalidProtocolBufferException("CodedInputStream encountered an embedded string or message " + "which claimed to have negative size.");
- }
-
- static InvalidProtocolBufferException malformedVarint() {
- return new InvalidProtocolBufferException("CodedInputStream encountered a malformed varint.");
- }
-
- static InvalidProtocolBufferException invalidTag() {
- return new InvalidProtocolBufferException("Protocol message contained an invalid tag (zero).");
- }
-
- static InvalidProtocolBufferException invalidEndTag() {
- return new InvalidProtocolBufferException("Protocol message end-group tag did not match expected tag.");
- }
-
- static InvalidProtocolBufferException invalidWireType() {
- return new InvalidProtocolBufferException("Protocol message tag had invalid wire type.");
- }
-
- static InvalidProtocolBufferException recursionLimitExceeded() {
- return new InvalidProtocolBufferException("Protocol message had too many levels of nesting. May be malicious. " + "Use CodedInputStream.setRecursionLimit() to increase the depth limit.");
- }
-
- static InvalidProtocolBufferException sizeLimitExceeded() {
- return new InvalidProtocolBufferException("Protocol message was too large. May be malicious. " + "Use CodedInputStream.setSizeLimit() to increase the size limit.");
- }
-}
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc.
+// http://code.google.com/p/protobuf/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.activemq.protobuf;
+
+import java.io.IOException;
+
+/**
+ * Thrown when a protocol message being parsed is invalid in some way, e.g. it
+ * contains a malformed varint or a negative byte length.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public class InvalidProtocolBufferException extends IOException {
+ private static final long serialVersionUID = 5685337441004132240L;
+
+ public InvalidProtocolBufferException(String description) {
+ super(description);
+ }
+
+ static InvalidProtocolBufferException truncatedMessage() {
+ return 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.");
+ }
+
+ static InvalidProtocolBufferException negativeSize() {
+ return new InvalidProtocolBufferException("CodedInputStream encountered an embedded string or message " + "which claimed to have negative size.");
+ }
+
+ static InvalidProtocolBufferException malformedVarint() {
+ return new InvalidProtocolBufferException("CodedInputStream encountered a malformed varint.");
+ }
+
+ static InvalidProtocolBufferException invalidTag() {
+ return new InvalidProtocolBufferException("Protocol message contained an invalid tag (zero).");
+ }
+
+ static InvalidProtocolBufferException invalidEndTag() {
+ return new InvalidProtocolBufferException("Protocol message end-group tag did not match expected tag.");
+ }
+
+ static InvalidProtocolBufferException invalidWireType() {
+ return new InvalidProtocolBufferException("Protocol message tag had invalid wire type.");
+ }
+
+ static InvalidProtocolBufferException recursionLimitExceeded() {
+ return new InvalidProtocolBufferException("Protocol message had too many levels of nesting. May be malicious. " + "Use CodedInputStream.setRecursionLimit() to increase the depth limit.");
+ }
+
+ static InvalidProtocolBufferException sizeLimitExceeded() {
+ return new InvalidProtocolBufferException("Protocol message was too large. May be malicious. " + "Use CodedInputStream.setSizeLimit() to increase the size limit.");
+ }
+}
Propchange: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/InvalidProtocolBufferException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/Message.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/MessageBuffer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/MessageBufferSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/PBMessage.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/UninitializedMessageException.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/WireFormat.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/WireFormat.java?rev=781514&r1=781513&r2=781514&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/WireFormat.java (original)
+++ activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/WireFormat.java Wed Jun 3 19:20:13 2009
@@ -1,70 +1,70 @@
-// Protocol Buffers - Google's data interchange format
-// Copyright 2008 Google Inc.
-// http://code.google.com/p/protobuf/
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package org.apache.activemq.protobuf;
-
-/**
- * This class is used internally by the Protocol Buffer library and generated
- * message implementations. It is public only because those generated messages
- * do not reside in the {@code protocol2} package. Others should not use this
- * class directly.
- *
- * This class contains constants and helper functions useful for dealing with
- * the Protocol Buffer wire format.
- *
- * @author kenton@google.com Kenton Varda
- */
-public final class WireFormat {
- // Do not allow instantiation.
- private WireFormat() {
- }
-
- public static final int WIRETYPE_VARINT = 0;
- public static final int WIRETYPE_FIXED64 = 1;
- public static final int WIRETYPE_LENGTH_DELIMITED = 2;
- public static final int WIRETYPE_START_GROUP = 3;
- public static final int WIRETYPE_END_GROUP = 4;
- public static final int WIRETYPE_FIXED32 = 5;
-
- public static final int TAG_TYPE_BITS = 3;
- public static final int TAG_TYPE_MASK = (1 << TAG_TYPE_BITS) - 1;
-
- /** Given a tag value, determines the wire type (the lower 3 bits). */
- public static int getTagWireType(int tag) {
- return tag & TAG_TYPE_MASK;
- }
-
- /** Given a tag value, determines the field number (the upper 29 bits). */
- public static int getTagFieldNumber(int tag) {
- return tag >>> TAG_TYPE_BITS;
- }
-
- /** Makes a tag value given a field number and wire type. */
- public static int makeTag(int fieldNumber, int wireType) {
- return (fieldNumber << TAG_TYPE_BITS) | wireType;
- }
-
- // Field numbers for feilds in MessageSet wire format.
- public static final int MESSAGE_SET_ITEM = 1;
- public static final int MESSAGE_SET_TYPE_ID = 2;
- public static final int MESSAGE_SET_MESSAGE = 3;
-
- // Tag numbers.
- public static final int MESSAGE_SET_ITEM_TAG = makeTag(MESSAGE_SET_ITEM, WIRETYPE_START_GROUP);
- public static final int MESSAGE_SET_ITEM_END_TAG = makeTag(MESSAGE_SET_ITEM, WIRETYPE_END_GROUP);
- public static final int MESSAGE_SET_TYPE_ID_TAG = makeTag(MESSAGE_SET_TYPE_ID, WIRETYPE_VARINT);
- public static final int MESSAGE_SET_MESSAGE_TAG = makeTag(MESSAGE_SET_MESSAGE, WIRETYPE_LENGTH_DELIMITED);
-}
+// Protocol Buffers - Google's data interchange format
+// Copyright 2008 Google Inc.
+// http://code.google.com/p/protobuf/
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.activemq.protobuf;
+
+/**
+ * This class is used internally by the Protocol Buffer library and generated
+ * message implementations. It is public only because those generated messages
+ * do not reside in the {@code protocol2} package. Others should not use this
+ * class directly.
+ *
+ * This class contains constants and helper functions useful for dealing with
+ * the Protocol Buffer wire format.
+ *
+ * @author kenton@google.com Kenton Varda
+ */
+public final class WireFormat {
+ // Do not allow instantiation.
+ private WireFormat() {
+ }
+
+ public static final int WIRETYPE_VARINT = 0;
+ public static final int WIRETYPE_FIXED64 = 1;
+ public static final int WIRETYPE_LENGTH_DELIMITED = 2;
+ public static final int WIRETYPE_START_GROUP = 3;
+ public static final int WIRETYPE_END_GROUP = 4;
+ public static final int WIRETYPE_FIXED32 = 5;
+
+ public static final int TAG_TYPE_BITS = 3;
+ public static final int TAG_TYPE_MASK = (1 << TAG_TYPE_BITS) - 1;
+
+ /** Given a tag value, determines the wire type (the lower 3 bits). */
+ public static int getTagWireType(int tag) {
+ return tag & TAG_TYPE_MASK;
+ }
+
+ /** Given a tag value, determines the field number (the upper 29 bits). */
+ public static int getTagFieldNumber(int tag) {
+ return tag >>> TAG_TYPE_BITS;
+ }
+
+ /** Makes a tag value given a field number and wire type. */
+ public static int makeTag(int fieldNumber, int wireType) {
+ return (fieldNumber << TAG_TYPE_BITS) | wireType;
+ }
+
+ // Field numbers for feilds in MessageSet wire format.
+ public static final int MESSAGE_SET_ITEM = 1;
+ public static final int MESSAGE_SET_TYPE_ID = 2;
+ public static final int MESSAGE_SET_MESSAGE = 3;
+
+ // Tag numbers.
+ public static final int MESSAGE_SET_ITEM_TAG = makeTag(MESSAGE_SET_ITEM, WIRETYPE_START_GROUP);
+ public static final int MESSAGE_SET_ITEM_END_TAG = makeTag(MESSAGE_SET_ITEM, WIRETYPE_END_GROUP);
+ public static final int MESSAGE_SET_TYPE_ID_TAG = makeTag(MESSAGE_SET_TYPE_ID, WIRETYPE_VARINT);
+ public static final int MESSAGE_SET_MESSAGE_TAG = makeTag(MESSAGE_SET_MESSAGE, WIRETYPE_LENGTH_DELIMITED);
+}
Propchange: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/WireFormat.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/sandbox/activemq-flow/activemq-protobuf/activemq-protobuf/src/main/java/org/apache/activemq/protobuf/compiler/AltJavaGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native