Mark Slee | 7eb0d63 | 2007-03-01 00:00:27 +0000 | [diff] [blame] | 1 | // Copyright (c) 2006- Facebook |
| 2 | // Distributed under the Thrift Software License |
| 3 | // |
| 4 | // See accompanying file LICENSE or visit the Thrift site at: |
| 5 | // http://developers.facebook.com/thrift/ |
| 6 | |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 7 | package com.facebook.thrift.protocol; |
| 8 | |
| 9 | import com.facebook.thrift.TException; |
| 10 | import com.facebook.thrift.transport.TTransport; |
Mark Slee | 6eb5892 | 2007-11-07 00:48:47 +0000 | [diff] [blame] | 11 | import java.io.UnsupportedEncodingException; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * Binary protocol implementation for thrift. |
| 15 | * |
| 16 | * @author Mark Slee <mcslee@facebook.com> |
| 17 | */ |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 18 | public class TBinaryProtocol extends TProtocol { |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 19 | |
Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 20 | protected static final int VERSION_MASK = 0xffff0000; |
| 21 | protected static final int VERSION_1 = 0x80010000; |
| 22 | |
| 23 | protected boolean strictRead_ = false; |
| 24 | protected boolean strictWrite_ = true; |
| 25 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 26 | /** |
| 27 | * Factory |
| 28 | */ |
| 29 | public static class Factory implements TProtocolFactory { |
Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 30 | protected boolean strictRead_ = false; |
| 31 | protected boolean strictWrite_ = true; |
Mark Slee | 6eb5892 | 2007-11-07 00:48:47 +0000 | [diff] [blame] | 32 | |
Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 33 | public Factory() { |
| 34 | this(false, false); |
| 35 | } |
| 36 | |
| 37 | public Factory(boolean strictRead, boolean strictWrite) { |
| 38 | strictRead_ = strictRead; |
| 39 | strictWrite_ = strictWrite; |
| 40 | } |
| 41 | |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 42 | public TProtocol getProtocol(TTransport trans) { |
Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 43 | return new TBinaryProtocol(trans, strictRead_, strictWrite_); |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 44 | } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 47 | /** |
| 48 | * Constructor |
| 49 | */ |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 50 | public TBinaryProtocol(TTransport trans) { |
Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 51 | this(trans, false, false); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 54 | public TBinaryProtocol(TTransport trans, boolean strictRead, boolean strictWrite) { |
| 55 | super(trans); |
| 56 | strictRead_ = strictRead; |
| 57 | strictWrite_ = strictWrite; |
| 58 | } |
| 59 | |
| 60 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 61 | public void writeMessageBegin(TMessage message) throws TException { |
Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 62 | if (strictWrite_) { |
| 63 | int version = VERSION_1 | message.type; |
| 64 | writeI32(version); |
| 65 | writeString(message.name); |
| 66 | writeI32(message.seqid); |
| 67 | } else { |
| 68 | writeString(message.name); |
| 69 | writeByte(message.type); |
| 70 | writeI32(message.seqid); |
| 71 | } |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 74 | public void writeMessageEnd() {} |
| 75 | |
| 76 | public void writeStructBegin(TStruct struct) {} |
| 77 | |
| 78 | public void writeStructEnd() {} |
| 79 | |
| 80 | public void writeFieldBegin(TField field) throws TException { |
| 81 | writeByte(field.type); |
| 82 | writeI16(field.id); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 85 | public void writeFieldEnd() {} |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 86 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 87 | public void writeFieldStop() throws TException { |
| 88 | writeByte(TType.STOP); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 91 | public void writeMapBegin(TMap map) throws TException { |
| 92 | writeByte(map.keyType); |
| 93 | writeByte(map.valueType); |
| 94 | writeI32(map.size); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 97 | public void writeMapEnd() {} |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 98 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 99 | public void writeListBegin(TList list) throws TException { |
| 100 | writeByte(list.elemType); |
| 101 | writeI32(list.size); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 104 | public void writeListEnd() {} |
| 105 | |
| 106 | public void writeSetBegin(TSet set) throws TException { |
| 107 | writeByte(set.elemType); |
| 108 | writeI32(set.size); |
| 109 | } |
| 110 | |
| 111 | public void writeSetEnd() {} |
| 112 | |
| 113 | public void writeBool(boolean b) throws TException { |
| 114 | writeByte(b ? (byte)1 : (byte)0); |
| 115 | } |
| 116 | |
| 117 | private byte [] bout = new byte[1]; |
| 118 | public void writeByte(byte b) throws TException { |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 119 | bout[0] = b; |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 120 | trans_.write(bout, 0, 1); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 123 | private byte[] i16out = new byte[2]; |
| 124 | public void writeI16(short i16) throws TException { |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 125 | i16out[0] = (byte)(0xff & (i16 >> 8)); |
| 126 | i16out[1] = (byte)(0xff & (i16)); |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 127 | trans_.write(i16out, 0, 2); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 130 | private byte[] i32out = new byte[4]; |
| 131 | public void writeI32(int i32) throws TException { |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 132 | i32out[0] = (byte)(0xff & (i32 >> 24)); |
| 133 | i32out[1] = (byte)(0xff & (i32 >> 16)); |
| 134 | i32out[2] = (byte)(0xff & (i32 >> 8)); |
| 135 | i32out[3] = (byte)(0xff & (i32)); |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 136 | trans_.write(i32out, 0, 4); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 139 | private byte[] i64out = new byte[8]; |
| 140 | public void writeI64(long i64) throws TException { |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 141 | i64out[0] = (byte)(0xff & (i64 >> 56)); |
| 142 | i64out[1] = (byte)(0xff & (i64 >> 48)); |
| 143 | i64out[2] = (byte)(0xff & (i64 >> 40)); |
| 144 | i64out[3] = (byte)(0xff & (i64 >> 32)); |
| 145 | i64out[4] = (byte)(0xff & (i64 >> 24)); |
| 146 | i64out[5] = (byte)(0xff & (i64 >> 16)); |
| 147 | i64out[6] = (byte)(0xff & (i64 >> 8)); |
| 148 | i64out[7] = (byte)(0xff & (i64)); |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 149 | trans_.write(i64out, 0, 8); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 152 | public void writeDouble(double dub) throws TException { |
| 153 | writeI64(Double.doubleToLongBits(dub)); |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 156 | public void writeString(String str) throws TException { |
Mark Slee | 6eb5892 | 2007-11-07 00:48:47 +0000 | [diff] [blame] | 157 | try { |
| 158 | byte[] dat = str.getBytes("UTF-8"); |
| 159 | writeI32(dat.length); |
| 160 | trans_.write(dat, 0, dat.length); |
| 161 | } catch (UnsupportedEncodingException uex) { |
| 162 | throw new TException("JVM DOES NOT SUPPORT UTF-8"); |
| 163 | } |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Mark Slee | 8d725a2 | 2007-04-13 01:57:12 +0000 | [diff] [blame] | 166 | public void writeBinary(byte[] bin) throws TException { |
| 167 | writeI32(bin.length); |
| 168 | trans_.write(bin, 0, bin.length); |
| 169 | } |
| 170 | |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 171 | /** |
| 172 | * Reading methods. |
| 173 | */ |
| 174 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 175 | public TMessage readMessageBegin() throws TException { |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 176 | TMessage message = new TMessage(); |
Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 177 | |
| 178 | int size = readI32(); |
| 179 | if (size < 0) { |
| 180 | int version = size & VERSION_MASK; |
| 181 | if (version != VERSION_1) { |
| 182 | throw new TProtocolException(TProtocolException.BAD_VERSION, "Bad version in readMessageBegin"); |
| 183 | } |
| 184 | message.type = (byte)(version & 0x000000ff); |
| 185 | message.name = readString(); |
| 186 | message.seqid = readI32(); |
| 187 | } else { |
| 188 | if (strictRead_) { |
| 189 | throw new TProtocolException(TProtocolException.BAD_VERSION, "Missing version in readMessageBegin, old client?"); |
| 190 | } |
| 191 | message.name = readStringBody(size); |
| 192 | message.type = readByte(); |
| 193 | message.seqid = readI32(); |
| 194 | } |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 195 | return message; |
| 196 | } |
| 197 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 198 | public void readMessageEnd() {} |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 199 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 200 | public TStruct readStructBegin() { |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 201 | return new TStruct(); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 204 | public void readStructEnd() {} |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 205 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 206 | public TField readFieldBegin() throws TException { |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 207 | TField field = new TField(); |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 208 | field.type = readByte(); |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 209 | if (field.type != TType.STOP) { |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 210 | field.id = readI16(); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 211 | } |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 212 | return field; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 213 | } |
Mark Slee | 6eb5892 | 2007-11-07 00:48:47 +0000 | [diff] [blame] | 214 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 215 | public void readFieldEnd() {} |
Mark Slee | 6eb5892 | 2007-11-07 00:48:47 +0000 | [diff] [blame] | 216 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 217 | public TMap readMapBegin() throws TException { |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 218 | TMap map = new TMap(); |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 219 | map.keyType = readByte(); |
| 220 | map.valueType = readByte(); |
| 221 | map.size = readI32(); |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 222 | return map; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 225 | public void readMapEnd() {} |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 226 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 227 | public TList readListBegin() throws TException { |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 228 | TList list = new TList(); |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 229 | list.elemType = readByte(); |
| 230 | list.size = readI32(); |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 231 | return list; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 234 | public void readListEnd() {} |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 235 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 236 | public TSet readSetBegin() throws TException { |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 237 | TSet set = new TSet(); |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 238 | set.elemType = readByte(); |
| 239 | set.size = readI32(); |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 240 | return set; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 243 | public void readSetEnd() {} |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 244 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 245 | public boolean readBool() throws TException { |
| 246 | return (readByte() == 1); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 249 | private byte[] bin = new byte[1]; |
| 250 | public byte readByte() throws TException { |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 251 | trans_.readAll(bin, 0, 1); |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 252 | return bin[0]; |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 255 | private byte[] i16rd = new byte[2]; |
| 256 | public short readI16() throws TException { |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 257 | trans_.readAll(i16rd, 0, 2); |
Mark Slee | 78f58e2 | 2006-09-02 04:17:07 +0000 | [diff] [blame] | 258 | return |
| 259 | (short) |
| 260 | (((i16rd[0] & 0xff) << 8) | |
| 261 | ((i16rd[1] & 0xff))); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 264 | private byte[] i32rd = new byte[4]; |
| 265 | public int readI32() throws TException { |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 266 | trans_.readAll(i32rd, 0, 4); |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 267 | return |
| 268 | ((i32rd[0] & 0xff) << 24) | |
| 269 | ((i32rd[1] & 0xff) << 16) | |
| 270 | ((i32rd[2] & 0xff) << 8) | |
| 271 | ((i32rd[3] & 0xff)); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 272 | } |
Mark Slee | 6eb5892 | 2007-11-07 00:48:47 +0000 | [diff] [blame] | 273 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 274 | private byte[] i64rd = new byte[8]; |
| 275 | public long readI64() throws TException { |
Aditya Agarwal | 5a42958 | 2007-02-06 02:51:15 +0000 | [diff] [blame] | 276 | trans_.readAll(i64rd, 0, 8); |
Mark Slee | 530fd66 | 2006-08-09 00:05:18 +0000 | [diff] [blame] | 277 | return |
| 278 | ((long)(i64rd[0] & 0xff) << 56) | |
| 279 | ((long)(i64rd[1] & 0xff) << 48) | |
| 280 | ((long)(i64rd[2] & 0xff) << 40) | |
| 281 | ((long)(i64rd[3] & 0xff) << 32) | |
| 282 | ((long)(i64rd[4] & 0xff) << 24) | |
| 283 | ((long)(i64rd[5] & 0xff) << 16) | |
| 284 | ((long)(i64rd[6] & 0xff) << 8) | |
| 285 | ((long)(i64rd[7] & 0xff)); |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 288 | public double readDouble() throws TException { |
| 289 | return Double.longBitsToDouble(readI64()); |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Mark Slee | 456b7a8 | 2006-10-25 20:53:37 +0000 | [diff] [blame] | 292 | public String readString() throws TException { |
| 293 | int size = readI32(); |
Mark Slee | 808454e | 2007-06-20 21:51:57 +0000 | [diff] [blame] | 294 | return readStringBody(size); |
| 295 | } |
| 296 | |
| 297 | public String readStringBody(int size) throws TException { |
Mark Slee | 6eb5892 | 2007-11-07 00:48:47 +0000 | [diff] [blame] | 298 | try { |
| 299 | byte[] buf = new byte[size]; |
| 300 | trans_.readAll(buf, 0, size); |
| 301 | return new String(buf, "UTF-8"); |
| 302 | } catch (UnsupportedEncodingException uex) { |
| 303 | throw new TException("JVM DOES NOT SUPPORT UTF-8"); |
| 304 | } |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 305 | } |
Mark Slee | 8d725a2 | 2007-04-13 01:57:12 +0000 | [diff] [blame] | 306 | |
| 307 | public byte[] readBinary() throws TException { |
| 308 | int size = readI32(); |
| 309 | byte[] buf = new byte[size]; |
| 310 | trans_.readAll(buf, 0, size); |
| 311 | return buf; |
| 312 | } |
| 313 | |
Mark Slee | 83c52a8 | 2006-06-07 06:51:18 +0000 | [diff] [blame] | 314 | } |