Java Thrift libraries no longer use specially defined UInt32 etc. classes
Summary: There was really no need for these now that we are getting rid of unsigned, they should all just use the builtin int and long types
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664741 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/java/src/protocol/TBinaryProtocol.java b/lib/java/src/protocol/TBinaryProtocol.java
index b2e77d9..a759005 100644
--- a/lib/java/src/protocol/TBinaryProtocol.java
+++ b/lib/java/src/protocol/TBinaryProtocol.java
@@ -2,7 +2,6 @@
import com.facebook.thrift.TException;
import com.facebook.thrift.transport.TTransport;
-import com.facebook.thrift.types.*;
/**
* Binary protocol implementation for thrift.
@@ -10,227 +9,176 @@
* @author Mark Slee <mcslee@facebook.com>
*/
public class TBinaryProtocol implements TProtocol {
- public int writeStructBegin (TTransport out,
- TStruct struct) throws TException {
- return 0;
+ public void writeStructBegin(TTransport out, TStruct struct) throws TException {}
+
+ public void writeStructEnd(TTransport out) throws TException {}
+
+ public void writeFieldBegin(TTransport out, TField field) throws TException {
+ writeByte(out, field.type);
+ writeI32(out, field.id);
}
- public int writeStructEnd (TTransport out) throws TException {
- return 0;
+ public void writeFieldEnd(TTransport out) throws TException {}
+
+ public void writeFieldStop(TTransport out) throws TException {
+ writeByte(out, TType.STOP);
}
- public int writeFieldBegin (TTransport out,
- TField field) throws TException {
- return
- writeByte(out, field.type.getCode()) +
- writeI32(out, field.id);
+ public void writeMapBegin(TTransport out, TMap map) throws TException {
+ writeByte(out, map.keyType);
+ writeByte(out, map.valueType);
+ writeI32(out, map.size);
}
- public int writeFieldEnd (TTransport out) throws TException {
- return 0;
+ public void writeMapEnd(TTransport out) throws TException {}
+
+ public void writeListBegin(TTransport out, TList list) throws TException {
+ writeByte(out, list.elemType);
+ writeI32(out, list.size);
}
- public int writeFieldStop (TTransport out) throws TException {
- return
- writeByte(out, TType.STOP.getCode());
+ public void writeListEnd(TTransport out) throws TException {}
+
+ public void writeSetBegin(TTransport out, TSet set) throws TException {
+ writeByte(out, set.elemType);
+ writeI32(out, set.size);
}
- public int writeMapBegin (TTransport out,
- TMap map) throws TException {
- return
- writeByte(out, map.keyType.getCode()) +
- writeByte(out, map.valueType.getCode()) +
- writeI32(out, map.size);
+ public void writeSetEnd(TTransport out) throws TException {}
+
+ byte[] bout = new byte[1];
+ public void writeByte(TTransport out, byte b) throws TException {
+ bout[0] = b;
+ out.write(bout, 0, 1);
}
- public int writeMapEnd (TTransport out) throws TException {
- return 0;
+ public void writeU32(TTransport out, int u32) throws TException {
+ writeI32(out, u32);
}
- public int writeListBegin (TTransport out,
- TList list) throws TException {
- return
- writeByte(out, list.elemType.getCode()) +
- writeI32(out, list.size);
+ byte[] i32out = new byte[4];
+ public void writeI32(TTransport out, int i32) throws TException {
+ i32out[0] = (byte)(0xff & (i32 >> 24));
+ i32out[1] = (byte)(0xff & (i32 >> 16));
+ i32out[2] = (byte)(0xff & (i32 >> 8));
+ i32out[3] = (byte)(0xff & (i32));
+ out.write(i32out, 0, 4);
}
- public int writeListEnd (TTransport out) throws TException {
- return 0;
+ public void writeU64(TTransport out, long u64) throws TException {
+ writeI64(out, u64);
}
- public int writeSetBegin (TTransport out,
- TSet set) throws TException {
- return
- writeByte(out, set.elemType.getCode()) +
- writeI32(out, set.size);
+ byte[] i64out = new byte[8];
+ public void writeI64(TTransport out, long i64) throws TException {
+ i64out[0] = (byte)(0xff & (i64 >> 56));
+ i64out[1] = (byte)(0xff & (i64 >> 48));
+ i64out[2] = (byte)(0xff & (i64 >> 40));
+ i64out[3] = (byte)(0xff & (i64 >> 32));
+ i64out[4] = (byte)(0xff & (i64 >> 24));
+ i64out[5] = (byte)(0xff & (i64 >> 16));
+ i64out[6] = (byte)(0xff & (i64 >> 8));
+ i64out[7] = (byte)(0xff & (i64));
+ out.write(i64out, 0, 8);
}
- public int writeSetEnd (TTransport out) throws TException {
- return 0;
- }
-
- public int writeByte (TTransport out,
- UInt8 b) throws TException {
- out.write(b.data(), 0, 1);
- return 1;
- }
-
- public int writeU32 (TTransport out,
- UInt32 u32) throws TException {
- out.write(u32.data(), 0, 4);
- return 4;
- }
-
- public int writeI32 (TTransport out,
- Int32 i32) throws TException {
- out.write(i32.data(), 0, 4);
- return 4;
- }
-
- public int writeU64 (TTransport out,
- UInt64 u64) throws TException {
- out.write(u64.data(), 0, 8);
- return 8;
- }
-
- public int writeI64 (TTransport out,
- Int64 i64) throws TException {
- out.write(i64.data(), 0, 8);
- return 8;
- }
-
- public int writeString (TTransport out,
- TString str) throws TException {
- byte[] dat = str.value.getBytes();
- int sent = writeI32(out, new Int32(dat.length));
+ public void writeString(TTransport out, String str) throws TException {
+ byte[] dat = str.getBytes();
+ writeI32(out, dat.length);
out.write(dat, 0, dat.length);
- return sent + dat.length;
}
/**
* Reading methods.
*/
- public int readStructBegin (TTransport in,
- TStruct struct) throws TException {
- struct.name = "";
- return 0;
+ public TStruct readStructBegin(TTransport in) throws TException {
+ return new TStruct();
}
- public int readStructEnd (TTransport in) throws TException {
- return 0;
- }
+ public void readStructEnd(TTransport in) throws TException {}
- public int readFieldBegin (TTransport in,
- TField field) throws TException {
- int recv = 0;
- UInt8 t = new UInt8();
-
- recv += readByte(in, t);
- field.type = TType.getType(t);
- if (field.type.equals(TType.STOP)) {
- field.id = new Int32(0);
- return recv;
+ public TField readFieldBegin(TTransport in) throws TException {
+ TField field = new TField();
+ field.type = readByte(in);
+ if (field.type != TType.STOP) {
+ field.id = readI32(in);
}
- recv += readI32(in, field.id);
- return recv;
+ return field;
}
- public int readFieldEnd (TTransport in) throws TException {
- return 0;
- }
+ public void readFieldEnd(TTransport in) throws TException {}
- public int readMapBegin (TTransport in,
- TMap map) throws TException {
- int recv = 0;
- UInt8 t = new UInt8();
- recv += readByte(in, t);
- map.keyType = TType.getType(t);
- recv += readByte(in, t);
- map.valueType = TType.getType(t);
- recv += readI32(in, map.size);
- return recv;
+ public TMap readMapBegin(TTransport in) throws TException {
+ TMap map = new TMap();
+ map.keyType = readByte(in);
+ map.valueType = readByte(in);
+ map.size = readI32(in);
+ return map;
}
- public int readMapEnd (TTransport in) throws TException {
- return 0;
+ public void readMapEnd(TTransport in) throws TException {}
+
+ public TList readListBegin(TTransport in) throws TException {
+ TList list = new TList();
+ list.elemType = readByte(in);
+ list.size = readI32(in);
+ return list;
}
- public int readListBegin (TTransport in,
- TList list) throws TException {
- int recv = 0;
- UInt8 t = new UInt8();
- recv += readByte(in, t);
- list.elemType = TType.getType(t);
- recv += readI32(in, list.size);
- return recv;
+ public void readListEnd(TTransport in) throws TException {}
+
+ public TSet readSetBegin(TTransport in) throws TException {
+ TSet set = new TSet();
+ set.elemType = readByte(in);
+ set.size = readI32(in);
+ return set;
}
- public int readListEnd (TTransport in) throws TException {
- return 0;
+ public void readSetEnd(TTransport in) throws TException {}
+
+ byte[] bin = new byte[1];
+ public byte readByte(TTransport in) throws TException {
+ in.readAll(bin, 0, 1);
+ return bin[0];
}
- public int readSetBegin (TTransport in,
- TSet set) throws TException {
- int recv = 0;
- UInt8 t = new UInt8();
- recv += readByte(in, t);
- set.elemType = TType.getType(t);
- recv += readI32(in, set.size);
- return recv;
+ public int readU32(TTransport in) throws TException {
+ return readI32(in);
}
- public int readSetEnd (TTransport in) throws TException {
- return 0;
+ byte[] i32rd = new byte[4];
+ public int readI32(TTransport in) throws TException {
+ in.readAll(i32rd, 0, 4);
+ return
+ ((i32rd[0] & 0xff) << 24) |
+ ((i32rd[1] & 0xff) << 16) |
+ ((i32rd[2] & 0xff) << 8) |
+ ((i32rd[3] & 0xff));
}
- public int readByte (TTransport in,
- UInt8 b) throws TException {
- byte[] buf = new byte[1];
- in.readAll(buf, 0, 1);
- b.read(buf, 0);
- return 1;
- }
-
- public int readU32 (TTransport in,
- UInt32 u32) throws TException {
- byte[] buf = new byte[4];
- in.readAll(buf, 0, 4);
- u32.read(buf, 0);
- return 4;
- }
-
- public int readI32 (TTransport in,
- Int32 i32) throws TException {
- byte[] buf = new byte[4];
- in.readAll(buf, 0, 4);
- i32.read(buf, 0);
- return 4;
- }
-
- public int readU64 (TTransport in,
- UInt64 u64) throws TException {
- byte[] buf = new byte[8];
- in.readAll(buf, 0, 8);
- u64.read(buf, 0);
- return 8;
+ public long readU64(TTransport in) throws TException {
+ return readI64(in);
}
- public int readI64 (TTransport in,
- Int64 i64) throws TException {
- byte[] buf = new byte[8];
- in.readAll(buf, 0, 8);
- i64.read(buf, 0);
- return 8;
+ byte[] i64rd = new byte[8];
+ public long readI64(TTransport in) throws TException {
+ in.readAll(i64rd, 0, 8);
+ return
+ ((long)(i64rd[0] & 0xff) << 56) |
+ ((long)(i64rd[1] & 0xff) << 48) |
+ ((long)(i64rd[2] & 0xff) << 40) |
+ ((long)(i64rd[3] & 0xff) << 32) |
+ ((long)(i64rd[4] & 0xff) << 24) |
+ ((long)(i64rd[5] & 0xff) << 16) |
+ ((long)(i64rd[6] & 0xff) << 8) |
+ ((long)(i64rd[7] & 0xff));
}
- public int readString (TTransport in,
- TString s) throws TException {
- Int32 size = new Int32();
- int recv = readI32(in, size);
- byte[] buf = new byte[size.get()];
- in.readAll(buf, 0, size.get());
- s.value = new String(buf);
- return recv + size.get();
+ public String readString(TTransport in) throws TException {
+ int size = readI32(in);
+ byte[] buf = new byte[size];
+ in.readAll(buf, 0, size);
+ return new String(buf);
}
}
diff --git a/lib/java/src/protocol/TField.java b/lib/java/src/protocol/TField.java
index d758c68..50570fb 100644
--- a/lib/java/src/protocol/TField.java
+++ b/lib/java/src/protocol/TField.java
@@ -1,7 +1,5 @@
package com.facebook.thrift.protocol;
-import com.facebook.thrift.types.*;
-
/**
* Helper class that encapsulates field metadata.
*
@@ -10,17 +8,13 @@
public class TField {
public TField() {}
- public TField(String n, TType t, int i) {
- this(n, t, new Int32(i));
- }
-
- public TField(String n, TType t, Int32 i) {
+ public TField(String n, byte t, int i) {
name = n;
type = t;
id = i;
}
public String name = "";
- public TType type = TType.STOP;
- public Int32 id = new Int32();
+ public byte type = TType.STOP;
+ public int id = 0;
}
diff --git a/lib/java/src/protocol/TList.java b/lib/java/src/protocol/TList.java
index ff76ffd..0528619 100644
--- a/lib/java/src/protocol/TList.java
+++ b/lib/java/src/protocol/TList.java
@@ -1,7 +1,5 @@
package com.facebook.thrift.protocol;
-import com.facebook.thrift.types.*;
-
/**
* Helper class that encapsulates list metadata.
*
@@ -10,15 +8,11 @@
public class TList {
public TList() {}
- public TList(TType t, int s) {
- this(t, new Int32(s));
- }
-
- public TList(TType t, Int32 s) {
+ public TList(byte t, int s) {
elemType = t;
size = s;
}
- public TType elemType = TType.STOP;
- public Int32 size = new Int32();
+ public byte elemType = TType.STOP;
+ public int size = 0;
}
diff --git a/lib/java/src/protocol/TMap.java b/lib/java/src/protocol/TMap.java
index f251fa6..e8d18e1 100644
--- a/lib/java/src/protocol/TMap.java
+++ b/lib/java/src/protocol/TMap.java
@@ -1,7 +1,5 @@
package com.facebook.thrift.protocol;
-import com.facebook.thrift.types.*;
-
/**
* Helper class that encapsulates map metadata.
*
@@ -10,17 +8,13 @@
public class TMap {
public TMap() {}
- public TMap(TType k, TType v, int s) {
- this(k, v, new Int32(s));
- }
-
- public TMap(TType k, TType v, Int32 s) {
+ public TMap(byte k, byte v, int s) {
keyType = k;
valueType = v;
size = s;
}
- public TType keyType = TType.STOP;
- public TType valueType = TType.STOP;
- public Int32 size = new Int32();;
+ public byte keyType = TType.STOP;
+ public byte valueType = TType.STOP;
+ public int size = 0;
}
diff --git a/lib/java/src/protocol/TProtocol.java b/lib/java/src/protocol/TProtocol.java
index f44eb9e..a60becb 100644
--- a/lib/java/src/protocol/TProtocol.java
+++ b/lib/java/src/protocol/TProtocol.java
@@ -1,6 +1,5 @@
package com.facebook.thrift.protocol;
-import com.facebook.thrift.types.*;
import com.facebook.thrift.TException;
import com.facebook.thrift.transport.TTransport;
@@ -15,95 +14,85 @@
* Writing methods.
*/
- public int writeStructBegin (TTransport out,
- TStruct struct) throws TException;
- public int writeStructEnd (TTransport out) throws TException;
+ public void writeStructBegin (TTransport out,
+ TStruct struct) throws TException;
- public int writeFieldBegin (TTransport out,
- TField field) throws TException;
+ public void writeStructEnd (TTransport out) throws TException;
- public int writeFieldEnd (TTransport out) throws TException;
+ public void writeFieldBegin (TTransport out,
+ TField field) throws TException;
- public int writeFieldStop (TTransport out) throws TException;
+ public void writeFieldEnd (TTransport out) throws TException;
- public int writeMapBegin (TTransport out,
- TMap map) throws TException;
+ public void writeFieldStop (TTransport out) throws TException;
- public int writeMapEnd (TTransport out) throws TException;
+ public void writeMapBegin (TTransport out,
+ TMap map) throws TException;
- public int writeListBegin (TTransport out,
- TList list) throws TException;
+ public void writeMapEnd (TTransport out) throws TException;
- public int writeListEnd (TTransport out) throws TException;
+ public void writeListBegin (TTransport out,
+ TList list) throws TException;
- public int writeSetBegin (TTransport out,
- TSet set) throws TException;
+ public void writeListEnd (TTransport out) throws TException;
- public int writeSetEnd (TTransport out) throws TException;
+ public void writeSetBegin (TTransport out,
+ TSet set) throws TException;
- public int writeByte (TTransport out,
- UInt8 b) throws TException;
+ public void writeSetEnd (TTransport out) throws TException;
- public int writeU32 (TTransport out,
- UInt32 u32) throws TException;
+ public void writeByte (TTransport out,
+ byte b) throws TException;
- public int writeI32 (TTransport out,
- Int32 i32) throws TException;
+ public void writeU32 (TTransport out,
+ int u32) throws TException;
- public int writeU64 (TTransport out,
- UInt64 u64) throws TException;
+ public void writeI32 (TTransport out,
+ int i32) throws TException;
- public int writeI64 (TTransport out,
- Int64 i64) throws TException;
+ public void writeU64 (TTransport out,
+ long u64) throws TException;
- public int writeString (TTransport out,
- TString str) throws TException;
+ public void writeI64 (TTransport out,
+ long i64) throws TException;
+
+ public void writeString (TTransport out,
+ String str) throws TException;
/**
* Reading methods.
*/
- public int readStructBegin (TTransport in,
- TStruct struct) throws TException;
+ public TStruct readStructBegin (TTransport in) throws TException;
- public int readStructEnd (TTransport in) throws TException;
+ public void readStructEnd (TTransport in) throws TException;
- public int readFieldBegin (TTransport in,
- TField field) throws TException;
+ public TField readFieldBegin (TTransport in) throws TException;
- public int readFieldEnd (TTransport in) throws TException;
+ public void readFieldEnd (TTransport in) throws TException;
- public int readMapBegin (TTransport in,
- TMap map) throws TException;
+ public TMap readMapBegin (TTransport in) throws TException;
- public int readMapEnd (TTransport in) throws TException;
+ public void readMapEnd (TTransport in) throws TException;
- public int readListBegin (TTransport in,
- TList list) throws TException;
+ public TList readListBegin (TTransport in) throws TException;
- public int readListEnd (TTransport in) throws TException;
+ public void readListEnd (TTransport in) throws TException;
- public int readSetBegin (TTransport in,
- TSet set) throws TException;
+ public TSet readSetBegin (TTransport in) throws TException;
- public int readSetEnd (TTransport in) throws TException;
+ public void readSetEnd (TTransport in) throws TException;
- public int readByte (TTransport in,
- UInt8 b) throws TException;
+ public byte readByte (TTransport in) throws TException;
- public int readU32 (TTransport in,
- UInt32 u32) throws TException;
+ public int readU32 (TTransport in) throws TException;
- public int readI32 (TTransport in,
- Int32 i32) throws TException;
+ public int readI32 (TTransport in) throws TException;
- public int readU64 (TTransport in,
- UInt64 u64) throws TException;
+ public long readU64 (TTransport in) throws TException;
- public int readI64 (TTransport in,
- Int64 i64) throws TException;
+ public long readI64 (TTransport in) throws TException;
- public int readString (TTransport in,
- TString s) throws TException;
+ public String readString (TTransport in) throws TException;
}
diff --git a/lib/java/src/protocol/TProtocolUtil.java b/lib/java/src/protocol/TProtocolUtil.java
index b182139..b8e5afe 100644
--- a/lib/java/src/protocol/TProtocolUtil.java
+++ b/lib/java/src/protocol/TProtocolUtil.java
@@ -1,6 +1,5 @@
package com.facebook.thrift.protocol;
-import com.facebook.thrift.types.*;
import com.facebook.thrift.TException;
import com.facebook.thrift.transport.TTransport;
@@ -11,94 +10,68 @@
* @author Mark Slee <mcslee@facebook.com>
*/
public class TProtocolUtil {
- public static int skip(TProtocol prot, TTransport in, TType type)
+ public static void skip(TProtocol prot, TTransport in, byte type)
throws TException {
switch (type) {
- case BYTE:
+ case TType.BYTE:
{
- UInt8 b = new UInt8();
- return prot.readByte(in, b);
+ prot.readByte(in);
}
- case U32:
+ case TType.U32:
+ case TType.I32:
{
- UInt32 u32 = new UInt32();
- return prot.readU32(in, u32);
+ prot.readI32(in);
}
- case I32:
+ case TType.U64:
+ case TType.I64:
{
- Int32 i32 = new Int32();
- return prot.readI32(in, i32);
+ prot.readI64(in);
}
- case U64:
+ case TType.STRING:
{
- UInt64 u64 = new UInt64();
- return prot.readU64(in, u64);
+ prot.readString(in);
}
- case I64:
+ case TType.STRUCT:
{
- Int64 i64 = new Int64();
- return prot.readI64(in, i64);
- }
- case STRING:
- {
- TString s = new TString();
- return prot.readString(in, s);
- }
- case STRUCT:
- {
- int result = 0;
- TString name = new TString();
- TStruct struct = new TStruct();
- TField field = new TField();
- result += prot.readStructBegin(in, struct);
+ prot.readStructBegin(in);
while (true) {
- result += prot.readFieldBegin(in, field);
- if (field.type.equals(TType.STOP)) {
+ TField field = prot.readFieldBegin(in);
+ if (field.type == TType.STOP) {
break;
}
- result += skip(prot, in, field.type);
- result += prot.readFieldEnd(in);
+ skip(prot, in, field.type);
+ prot.readFieldEnd(in);
}
- result += prot.readStructEnd(in);
- return result;
+ prot.readStructEnd(in);
}
- case MAP:
+ case TType.MAP:
{
- int result = 0;
- TMap map = new TMap();
- result += prot.readMapBegin(in, map);
- for (int i = 0; i < map.size.get(); i++) {
- result += skip(prot, in, map.keyType);
- result += skip(prot, in, map.valueType);
+ TMap map = prot.readMapBegin(in);
+ for (int i = 0; i < map.size; i++) {
+ skip(prot, in, map.keyType);
+ skip(prot, in, map.valueType);
}
- result += prot.readMapEnd(in);
- return result;
+ prot.readMapEnd(in);
}
- case SET:
- {
- int result = 0;
- TSet set = new TSet();
- result += prot.readSetBegin(in, set);
- for (int i = 0; i < set.size.get(); i++) {
- result += skip(prot, in, set.elemType);
+ case TType.SET:
+ {
+ TSet set = prot.readSetBegin(in);
+ for (int i = 0; i < set.size; i++) {
+ skip(prot, in, set.elemType);
}
- result += prot.readSetEnd(in);
- return result;
+ prot.readSetEnd(in);
}
- case LIST:
+ case TType.LIST:
{
- int result = 0;
- TList list = new TList();
- result += prot.readListBegin(in, list);
- for (int i = 0; i < list.size.get(); i++) {
- result += skip(prot, in, list.elemType);
+ TList list = prot.readListBegin(in);
+ for (int i = 0; i < list.size; i++) {
+ skip(prot, in, list.elemType);
}
- result += prot.readListEnd(in);
- return result;
+ prot.readListEnd(in);
}
default:
- return 0;
+ return;
}
}
}
diff --git a/lib/java/src/protocol/TSet.java b/lib/java/src/protocol/TSet.java
index fa6e24d..542f3f5 100644
--- a/lib/java/src/protocol/TSet.java
+++ b/lib/java/src/protocol/TSet.java
@@ -1,7 +1,5 @@
package com.facebook.thrift.protocol;
-import com.facebook.thrift.types.*;
-
/**
* Helper class that encapsulates set metadata.
*
@@ -10,15 +8,11 @@
public class TSet {
public TSet() {}
- public TSet(TType t, int s) {
- this(t, new Int32(s));
- }
-
- public TSet(TType t, Int32 s) {
+ public TSet(byte t, int s) {
elemType = t;
size = s;
}
- public TType elemType = TType.STOP;
- public Int32 size = new Int32();
+ public byte elemType = TType.STOP;
+ public int size = 0;
}
diff --git a/lib/java/src/protocol/TStruct.java b/lib/java/src/protocol/TStruct.java
index 2fbcb8f..b8b94ce 100644
--- a/lib/java/src/protocol/TStruct.java
+++ b/lib/java/src/protocol/TStruct.java
@@ -1,7 +1,5 @@
package com.facebook.thrift.protocol;
-import com.facebook.thrift.types.*;
-
/**
* Helper class that encapsulates struct metadata.
*
diff --git a/lib/java/src/protocol/TType.java b/lib/java/src/protocol/TType.java
index 21b7914..96f06d3 100644
--- a/lib/java/src/protocol/TType.java
+++ b/lib/java/src/protocol/TType.java
@@ -1,82 +1,22 @@
package com.facebook.thrift.protocol;
-import com.facebook.thrift.types.UInt8;
-
/**
* Type constants in the Thrift protocol.
*
* @author Mark Slee <mcslee@facebook.com>
*/
-public enum TType {
- STOP (1),
- BYTE (2),
- U16 (3),
- I16 (4),
- U32 (5),
- I32 (6),
- U64 (7),
- I64 (8),
- STRING (9),
- STRUCT (10),
- MAP (11),
- SET (12),
- LIST (13);
-
- /** U8 identifier */
- private UInt8 code_;
-
- /**
- * Constructor to create a TType object from its code.
- *
- * @param code The identifier code for this type
- */
- private TType(int code) {
- code_ = new UInt8((byte)code);
- }
-
- /**
- * Accessor for the code.
- */
- public UInt8 getCode() {
- return code_;
- }
-
- /**
- * Static method to get a type object from a byte.
- *
- * @param code The type code
- */
- public static TType getType(UInt8 code) {
- switch (code.get()) {
- case 1:
- return STOP;
- case 2:
- return BYTE;
- case 3:
- return U16;
- case 4:
- return I16;
- case 5:
- return U32;
- case 6:
- return I32;
- case 7:
- return U64;
- case 8:
- return I64;
- case 9:
- return STRING;
- case 10:
- return STRUCT;
- case 11:
- return MAP;
- case 12:
- return SET;
- case 13:
- return LIST;
- default:
- System.err.println("WARNING: Unidentified type code: " + code.get());
- return STOP;
- }
- }
+public final class TType {
+ public static final byte STOP = 1;
+ public static final byte BYTE = 2;
+ public static final byte U16 = 3;
+ public static final byte I16 = 4;
+ public static final byte U32 = 5;
+ public static final byte I32 = 6;
+ public static final byte U64 = 7;
+ public static final byte I64 = 8;
+ public static final byte STRING = 9;
+ public static final byte STRUCT = 10;
+ public static final byte MAP = 11;
+ public static final byte SET = 12;
+ public static final byte LIST = 13;
}