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
diff --git a/lib/cpp/protocol/TBinaryProtocol.cc b/lib/cpp/protocol/TBinaryProtocol.cc
index 1f31c8d..666a6a4 100644
--- a/lib/cpp/protocol/TBinaryProtocol.cc
+++ b/lib/cpp/protocol/TBinaryProtocol.cc
@@ -16,7 +16,7 @@
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::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::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::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::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 @@
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::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::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::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::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 e05bd9f..ea0bd25 100644
--- a/lib/cpp/protocol/TBinaryProtocol.h
+++ b/lib/cpp/protocol/TBinaryProtocol.h
@@ -35,19 +35,19 @@
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 @@
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 fe2d6ef..0007406 100644
--- a/lib/cpp/protocol/TProtocol.h
+++ b/lib/cpp/protocol/TProtocol.h
@@ -73,19 +73,19 @@
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 @@
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 @@
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 @@
{
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 @@
{
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 3aaa06b..b2e77d9 100644
--- a/lib/java/src/protocol/TBinaryProtocol.java
+++ b/lib/java/src/protocol/TBinaryProtocol.java
@@ -23,7 +23,7 @@
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 @@
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 @@
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 @@
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 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 @@
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 @@
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 @@
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 @@
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 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 83f1fc3..d758c68 100644
--- a/lib/java/src/protocol/TField.java
+++ b/lib/java/src/protocol/TField.java
@@ -11,10 +11,10 @@
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 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 6eac06b..ff76ffd 100644
--- a/lib/java/src/protocol/TList.java
+++ b/lib/java/src/protocol/TList.java
@@ -11,14 +11,14 @@
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 84eb468..f251fa6 100644
--- a/lib/java/src/protocol/TMap.java
+++ b/lib/java/src/protocol/TMap.java
@@ -11,10 +11,10 @@
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 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 e0dcf76..fa6e24d 100644
--- a/lib/java/src/protocol/TSet.java
+++ b/lib/java/src/protocol/TSet.java
@@ -11,14 +11,14 @@
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();
}