From f3c322b4a36ca67e77d53ae0bf337853812e4f14 Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Mon, 26 Jun 2006 23:52:22 +0000 Subject: [PATCH] Thrift: getting rid of U32s for map/list/set/string lengths and field ids etc. Summary: U32s are on the out. Make way for the I32. Reviewed By: aditya git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664718 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/protocol/TBinaryProtocol.cc | 39 +++++++++++----------- lib/cpp/protocol/TBinaryProtocol.h | 12 +++---- lib/cpp/protocol/TProtocol.h | 18 +++++----- lib/java/src/protocol/TBinaryProtocol.java | 30 ++++++++--------- lib/java/src/protocol/TField.java | 6 ++-- lib/java/src/protocol/TList.java | 6 ++-- lib/java/src/protocol/TMap.java | 6 ++-- lib/java/src/protocol/TSet.java | 6 ++-- 8 files changed, 62 insertions(+), 61 deletions(-) diff --git a/lib/cpp/protocol/TBinaryProtocol.cc b/lib/cpp/protocol/TBinaryProtocol.cc index 1f31c8dd..666a6a4e 100644 --- a/lib/cpp/protocol/TBinaryProtocol.cc +++ b/lib/cpp/protocol/TBinaryProtocol.cc @@ -16,7 +16,7 @@ uint32_t TBinaryProtocol::writeFieldBegin(TTransport* out, const uint16_t fieldId) const { return writeByte(out, (uint8_t)fieldType) + - writeU32(out, (uint32_t)fieldId); + writeI32(out, (int32_t)fieldId); } uint32_t TBinaryProtocol::writeFieldEnd(TTransport* out) const { @@ -31,11 +31,11 @@ uint32_t TBinaryProtocol::writeFieldStop(TTransport* out) const { uint32_t TBinaryProtocol::writeMapBegin(TTransport* out, const TType keyType, const TType valType, - const uint32_t size) const { + const int32_t size) const { return writeByte(out, (uint8_t)keyType) + writeByte(out, (uint8_t)valType) + - writeU32(out, size); + writeI32(out, (int32_t)size); } uint32_t TBinaryProtocol::writeMapEnd(TTransport* out) const { @@ -44,10 +44,10 @@ uint32_t TBinaryProtocol::writeMapEnd(TTransport* out) const { uint32_t TBinaryProtocol::writeListBegin(TTransport* out, const TType elemType, - const uint32_t size) const { + const int32_t size) const { return writeByte(out, (uint8_t) elemType) + - writeU32(out, size); + writeI32(out, (int32_t)size); } uint32_t TBinaryProtocol::writeListEnd(TTransport* out) const { @@ -56,10 +56,10 @@ uint32_t TBinaryProtocol::writeListEnd(TTransport* out) const { uint32_t TBinaryProtocol::writeSetBegin(TTransport* out, const TType elemType, - const uint32_t size) const { + const int32_t size) const { return writeByte(out, (uint8_t)elemType) + - writeU32(out, size); + writeI32(out, (int32_t)size); } uint32_t TBinaryProtocol::writeSetEnd(TTransport* out) const { @@ -102,7 +102,7 @@ uint32_t TBinaryProtocol::writeI64(TTransport* out, uint32_t TBinaryProtocol::writeString(TTransport* out, const string& str) const { - uint32_t result = writeU32(out, str.size()); + uint32_t result = writeI32(out, str.size()); out->write((uint8_t*)str.data(), str.size()); return result + str.size(); } @@ -133,8 +133,8 @@ uint32_t TBinaryProtocol::readFieldBegin(TTransport* in, fieldId = 0; return result; } - uint32_t id; - result += readU32(in, id); + int32_t id; + result += readI32(in, id); fieldId = (uint16_t)id; return result; } @@ -146,14 +146,14 @@ uint32_t TBinaryProtocol::readFieldEnd(TTransport* in) const { uint32_t TBinaryProtocol::readMapBegin(TTransport* in, TType& keyType, TType& valType, - uint32_t& size) const { + int32_t& size) const { uint8_t k, v; uint32_t result = 0; result += readByte(in, k); keyType = (TType)k; result += readByte(in, v); valType = (TType)v; - result += readU32(in, size); + result += readI32(in, size); return result; } @@ -163,12 +163,12 @@ uint32_t TBinaryProtocol::readMapEnd(TTransport* in) const { uint32_t TBinaryProtocol::readListBegin(TTransport* in, TType& elemType, - uint32_t& size) const { + int32_t& size) const { uint8_t e; uint32_t result = 0; result += readByte(in, e); elemType = (TType)e; - result += readU32(in, size); + result += readI32(in, size); return result; } @@ -178,12 +178,12 @@ uint32_t TBinaryProtocol::readListEnd(TTransport* in) const { uint32_t TBinaryProtocol::readSetBegin(TTransport* in, TType& elemType, - uint32_t& size) const { + int32_t& size) const { uint8_t e; uint32_t result = 0; result += readByte(in, e); elemType = (TType)e; - result += readU32(in, size); + result += readI32(in, size); return result; } @@ -237,10 +237,11 @@ uint32_t TBinaryProtocol::readI64(TTransport* in, uint32_t TBinaryProtocol::readString(TTransport* in, string& str) const { - uint32_t size, result; - result = readU32(in, size); + uint32_t result; + int32_t size; + result = readI32(in, size); uint8_t b[size]; in->readAll(b, size); str = string((char*)b, size); - return result+size; + return result + (uint32_t)size; } diff --git a/lib/cpp/protocol/TBinaryProtocol.h b/lib/cpp/protocol/TBinaryProtocol.h index e05bd9fc..ea0bd257 100644 --- a/lib/cpp/protocol/TBinaryProtocol.h +++ b/lib/cpp/protocol/TBinaryProtocol.h @@ -35,19 +35,19 @@ class TBinaryProtocol : public TProtocol { uint32_t writeMapBegin (TTransport* out, const TType keyType, const TType valType, - const uint32_t size) const; + const int32_t size) const; uint32_t writeMapEnd (TTransport* out) const; uint32_t writeListBegin (TTransport* out, const TType elemType, - const uint32_t size) const; + const int32_t size) const; uint32_t writeListEnd (TTransport* out) const; uint32_t writeSetBegin (TTransport* out, const TType elemType, - const uint32_t size) const; + const int32_t size) const; uint32_t writeSetEnd (TTransport* out) const; @@ -88,19 +88,19 @@ class TBinaryProtocol : public TProtocol { uint32_t readMapBegin (TTransport* in, TType& keyType, TType& valType, - uint32_t& size) const; + int32_t& size) const; uint32_t readMapEnd (TTransport* in) const; uint32_t readListBegin (TTransport* in, TType& elemType, - uint32_t& size) const; + int32_t& size) const; uint32_t readListEnd (TTransport* in) const; uint32_t readSetBegin (TTransport* in, TType& elemType, - uint32_t& size) const; + int32_t& size) const; uint32_t readSetEnd (TTransport* in) const; diff --git a/lib/cpp/protocol/TProtocol.h b/lib/cpp/protocol/TProtocol.h index fe2d6ef1..0007406d 100644 --- a/lib/cpp/protocol/TProtocol.h +++ b/lib/cpp/protocol/TProtocol.h @@ -73,19 +73,19 @@ class TProtocol { virtual uint32_t writeMapBegin (TTransport* out, const TType keyType, const TType valType, - const uint32_t size) const = 0; + const int32_t size) const = 0; virtual uint32_t writeMapEnd (TTransport* out) const = 0; virtual uint32_t writeListBegin (TTransport* out, const TType elemType, - const uint32_t size) const = 0; + const int32_t size) const = 0; virtual uint32_t writeListEnd (TTransport* out) const = 0; virtual uint32_t writeSetBegin (TTransport* out, const TType elemType, - const uint32_t size) const = 0; + const int32_t size) const = 0; virtual uint32_t writeSetEnd (TTransport* out) const = 0; @@ -126,19 +126,19 @@ class TProtocol { virtual uint32_t readMapBegin (TTransport* in, TType& keyType, TType& valType, - uint32_t& size) const = 0; + int32_t& size) const = 0; virtual uint32_t readMapEnd (TTransport* in) const = 0; virtual uint32_t readListBegin (TTransport* in, TType& elemType, - uint32_t& size) const = 0; + int32_t& size) const = 0; virtual uint32_t readListEnd (TTransport* in) const = 0; virtual uint32_t readSetBegin (TTransport* in, TType& elemType, - uint32_t& size) const = 0; + int32_t& size) const = 0; virtual uint32_t readSetEnd (TTransport* in) const = 0; @@ -218,7 +218,7 @@ class TProtocol { uint32_t result = 0; TType keyType; TType valType; - uint32_t i, size; + int32_t i, size; result += readMapBegin(in, keyType, valType, size); for (i = 0; i < size; i++) { result += skip(in, keyType); @@ -231,7 +231,7 @@ class TProtocol { { uint32_t result = 0; TType elemType; - uint32_t i, size; + int32_t i, size; result += readSetBegin(in, elemType, size); for (i = 0; i < size; i++) { result += skip(in, elemType); @@ -243,7 +243,7 @@ class TProtocol { { uint32_t result = 0; TType elemType; - uint32_t i, size; + int32_t i, size; result += readListBegin(in, elemType, size); for (i = 0; i < size; i++) { result += skip(in, elemType); diff --git a/lib/java/src/protocol/TBinaryProtocol.java b/lib/java/src/protocol/TBinaryProtocol.java index 3aaa06bd..b2e77d93 100644 --- a/lib/java/src/protocol/TBinaryProtocol.java +++ b/lib/java/src/protocol/TBinaryProtocol.java @@ -23,7 +23,7 @@ public class TBinaryProtocol implements TProtocol { TField field) throws TException { return writeByte(out, field.type.getCode()) + - writeU32(out, field.id); + writeI32(out, field.id); } public int writeFieldEnd (TTransport out) throws TException { @@ -40,7 +40,7 @@ public class TBinaryProtocol implements TProtocol { return writeByte(out, map.keyType.getCode()) + writeByte(out, map.valueType.getCode()) + - writeU32(out, map.size); + writeI32(out, map.size); } public int writeMapEnd (TTransport out) throws TException { @@ -51,7 +51,7 @@ public class TBinaryProtocol implements TProtocol { TList list) throws TException { return writeByte(out, list.elemType.getCode()) + - writeU32(out, list.size); + writeI32(out, list.size); } public int writeListEnd (TTransport out) throws TException { @@ -62,7 +62,7 @@ public class TBinaryProtocol implements TProtocol { TSet set) throws TException { return writeByte(out, set.elemType.getCode()) + - writeU32(out, set.size); + writeI32(out, set.size); } public int writeSetEnd (TTransport out) throws TException { @@ -102,7 +102,7 @@ public class TBinaryProtocol implements TProtocol { public int writeString (TTransport out, TString str) throws TException { byte[] dat = str.value.getBytes(); - int sent = writeU32(out, new UInt32(dat.length)); + int sent = writeI32(out, new Int32(dat.length)); out.write(dat, 0, dat.length); return sent + dat.length; } @@ -129,10 +129,10 @@ public class TBinaryProtocol implements TProtocol { recv += readByte(in, t); field.type = TType.getType(t); if (field.type.equals(TType.STOP)) { - field.id = new UInt32(0); + field.id = new Int32(0); return recv; } - recv += readU32(in, field.id); + recv += readI32(in, field.id); return recv; } @@ -148,7 +148,7 @@ public class TBinaryProtocol implements TProtocol { map.keyType = TType.getType(t); recv += readByte(in, t); map.valueType = TType.getType(t); - recv += readU32(in, map.size); + recv += readI32(in, map.size); return recv; } @@ -162,7 +162,7 @@ public class TBinaryProtocol implements TProtocol { UInt8 t = new UInt8(); recv += readByte(in, t); list.elemType = TType.getType(t); - recv += readU32(in, list.size); + recv += readI32(in, list.size); return recv; } @@ -176,7 +176,7 @@ public class TBinaryProtocol implements TProtocol { UInt8 t = new UInt8(); recv += readByte(in, t); set.elemType = TType.getType(t); - recv += readU32(in, set.size); + recv += readI32(in, set.size); return recv; } @@ -226,11 +226,11 @@ public class TBinaryProtocol implements TProtocol { public int readString (TTransport in, TString s) throws TException { - UInt32 size = new UInt32(); - int recv = readU32(in, size); - byte[] buf = new byte[size.toInt()]; - in.readAll(buf, 0, size.toInt()); + 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.toInt(); + return recv + size.get(); } } diff --git a/lib/java/src/protocol/TField.java b/lib/java/src/protocol/TField.java index 83f1fc35..d758c68b 100644 --- a/lib/java/src/protocol/TField.java +++ b/lib/java/src/protocol/TField.java @@ -11,10 +11,10 @@ public class TField { public TField() {} public TField(String n, TType t, int i) { - this(n, t, new UInt32(i)); + this(n, t, new Int32(i)); } - public TField(String n, TType t, UInt32 i) { + public TField(String n, TType t, Int32 i) { name = n; type = t; id = i; @@ -22,5 +22,5 @@ public class TField { public String name = ""; public TType type = TType.STOP; - public UInt32 id = new UInt32(); + public Int32 id = new Int32(); } diff --git a/lib/java/src/protocol/TList.java b/lib/java/src/protocol/TList.java index 6eac06b1..ff76ffd5 100644 --- a/lib/java/src/protocol/TList.java +++ b/lib/java/src/protocol/TList.java @@ -11,14 +11,14 @@ public class TList { public TList() {} public TList(TType t, int s) { - this(t, new UInt32(s)); + this(t, new Int32(s)); } - public TList(TType t, UInt32 s) { + public TList(TType t, Int32 s) { elemType = t; size = s; } public TType elemType = TType.STOP; - public UInt32 size = new UInt32(); + public Int32 size = new Int32(); } diff --git a/lib/java/src/protocol/TMap.java b/lib/java/src/protocol/TMap.java index 84eb4689..f251fa67 100644 --- a/lib/java/src/protocol/TMap.java +++ b/lib/java/src/protocol/TMap.java @@ -11,10 +11,10 @@ public class TMap { public TMap() {} public TMap(TType k, TType v, int s) { - this(k, v, new UInt32(s)); + this(k, v, new Int32(s)); } - public TMap(TType k, TType v, UInt32 s) { + public TMap(TType k, TType v, Int32 s) { keyType = k; valueType = v; size = s; @@ -22,5 +22,5 @@ public class TMap { public TType keyType = TType.STOP; public TType valueType = TType.STOP; - public UInt32 size = new UInt32();; + public Int32 size = new Int32();; } diff --git a/lib/java/src/protocol/TSet.java b/lib/java/src/protocol/TSet.java index e0dcf769..fa6e24dc 100644 --- a/lib/java/src/protocol/TSet.java +++ b/lib/java/src/protocol/TSet.java @@ -11,14 +11,14 @@ public class TSet { public TSet() {} public TSet(TType t, int s) { - this(t, new UInt32(s)); + this(t, new Int32(s)); } - public TSet(TType t, UInt32 s) { + public TSet(TType t, Int32 s) { elemType = t; size = s; } public TType elemType = TType.STOP; - public UInt32 size = new UInt32(); + public Int32 size = new Int32(); } -- 2.17.1