Class | Thrift::BinaryProtocol |
In: |
lib/thrift/protocol/binary_protocol.rb
lib/thrift/protocol/binary_protocol.rb |
Parent: | BaseProtocol |
VERSION_MASK | = | 0xffff0000 |
VERSION_1 | = | 0x80010000 |
TYPE_MASK | = | 0x000000ff |
VERSION_MASK | = | 0xffff0000 |
VERSION_1 | = | 0x80010000 |
TYPE_MASK | = | 0x000000ff |
strict_read | [R] | |
strict_read | [R] | |
strict_write | [R] | |
strict_write | [R] |
# File lib/thrift/protocol/binary_protocol.rb, line 28 28: def initialize(trans, strict_read=true, strict_write=true) 29: super(trans) 30: @strict_read = strict_read 31: @strict_write = strict_write 32: 33: # Pre-allocated read buffer for fixed-size read methods. Needs to be at least 8 bytes long for 34: # read_i64() and read_double(). 35: @rbuf = Bytes.empty_byte_buffer(8) 36: end
# File lib/thrift/protocol/binary_protocol.rb, line 28 28: def initialize(trans, strict_read=true, strict_write=true) 29: super(trans) 30: @strict_read = strict_read 31: @strict_write = strict_write 32: 33: # Pre-allocated read buffer for fixed-size read methods. Needs to be at least 8 bytes long for 34: # read_i64() and read_double(). 35: @rbuf = Bytes.empty_byte_buffer(8) 36: end
# File lib/thrift/protocol/binary_protocol.rb, line 167 167: def read_bool 168: byte = read_byte 169: byte != 0 170: end
# File lib/thrift/protocol/binary_protocol.rb, line 167 167: def read_bool 168: byte = read_byte 169: byte != 0 170: end
# File lib/thrift/protocol/binary_protocol.rb, line 172 172: def read_byte 173: val = trans.read_byte 174: if (val > 0x7f) 175: val = 0 - ((val - 1) ^ 0xff) 176: end 177: val 178: end
# File lib/thrift/protocol/binary_protocol.rb, line 172 172: def read_byte 173: val = trans.read_byte 174: if (val > 0x7f) 175: val = 0 - ((val - 1) ^ 0xff) 176: end 177: val 178: end
# File lib/thrift/protocol/binary_protocol.rb, line 210 210: def read_double 211: trans.read_into_buffer(@rbuf, 8) 212: val = @rbuf.unpack('G').first 213: val 214: end
# File lib/thrift/protocol/binary_protocol.rb, line 210 210: def read_double 211: trans.read_into_buffer(@rbuf, 8) 212: val = @rbuf.unpack('G').first 213: val 214: end
# File lib/thrift/protocol/binary_protocol.rb, line 138 138: def read_field_begin 139: type = read_byte 140: if (type == Types::STOP) 141: [nil, type, 0] 142: else 143: id = read_i16 144: [nil, type, id] 145: end 146: end
# File lib/thrift/protocol/binary_protocol.rb, line 138 138: def read_field_begin 139: type = read_byte 140: if (type == Types::STOP) 141: [nil, type, 0] 142: else 143: id = read_i16 144: [nil, type, id] 145: end 146: end
# File lib/thrift/protocol/binary_protocol.rb, line 180 180: def read_i16 181: trans.read_into_buffer(@rbuf, 2) 182: val, = @rbuf.unpack('n') 183: if (val > 0x7fff) 184: val = 0 - ((val - 1) ^ 0xffff) 185: end 186: val 187: end
# File lib/thrift/protocol/binary_protocol.rb, line 180 180: def read_i16 181: trans.read_into_buffer(@rbuf, 2) 182: val, = @rbuf.unpack('n') 183: if (val > 0x7fff) 184: val = 0 - ((val - 1) ^ 0xffff) 185: end 186: val 187: end
# File lib/thrift/protocol/binary_protocol.rb, line 189 189: def read_i32 190: trans.read_into_buffer(@rbuf, 4) 191: val, = @rbuf.unpack('N') 192: if (val > 0x7fffffff) 193: val = 0 - ((val - 1) ^ 0xffffffff) 194: end 195: val 196: end
# File lib/thrift/protocol/binary_protocol.rb, line 189 189: def read_i32 190: trans.read_into_buffer(@rbuf, 4) 191: val, = @rbuf.unpack('N') 192: if (val > 0x7fffffff) 193: val = 0 - ((val - 1) ^ 0xffffffff) 194: end 195: val 196: end
# File lib/thrift/protocol/binary_protocol.rb, line 198 198: def read_i64 199: trans.read_into_buffer(@rbuf, 8) 200: hi, lo = @rbuf.unpack('N2') 201: if (hi > 0x7fffffff) 202: hi ^= 0xffffffff 203: lo ^= 0xffffffff 204: 0 - (hi << 32) - lo - 1 205: else 206: (hi << 32) + lo 207: end 208: end
# File lib/thrift/protocol/binary_protocol.rb, line 198 198: def read_i64 199: trans.read_into_buffer(@rbuf, 8) 200: hi, lo = @rbuf.unpack('N2') 201: if (hi > 0x7fffffff) 202: hi ^= 0xffffffff 203: lo ^= 0xffffffff 204: 0 - (hi << 32) - lo - 1 205: else 206: (hi << 32) + lo 207: end 208: end
# File lib/thrift/protocol/binary_protocol.rb, line 155 155: def read_list_begin 156: etype = read_byte 157: size = read_i32 158: [etype, size] 159: end
# File lib/thrift/protocol/binary_protocol.rb, line 155 155: def read_list_begin 156: etype = read_byte 157: size = read_i32 158: [etype, size] 159: end
# File lib/thrift/protocol/binary_protocol.rb, line 148 148: def read_map_begin 149: ktype = read_byte 150: vtype = read_byte 151: size = read_i32 152: [ktype, vtype, size] 153: end
# File lib/thrift/protocol/binary_protocol.rb, line 148 148: def read_map_begin 149: ktype = read_byte 150: vtype = read_byte 151: size = read_i32 152: [ktype, vtype, size] 153: end
# File lib/thrift/protocol/binary_protocol.rb, line 115 115: def read_message_begin 116: version = read_i32 117: if version < 0 118: if (version & VERSION_MASK != VERSION_1) 119: raise ProtocolException.new(ProtocolException::BAD_VERSION, 'Missing version identifier') 120: end 121: type = version & TYPE_MASK 122: name = read_string 123: seqid = read_i32 124: [name, type, seqid] 125: else 126: if strict_read 127: raise ProtocolException.new(ProtocolException::BAD_VERSION, 'No version identifier, old protocol client?') 128: end 129: name = trans.read_all(version) 130: type = read_byte 131: seqid = read_i32 132: [name, type, seqid] 133: end 134: end
# File lib/thrift/protocol/binary_protocol.rb, line 115 115: def read_message_begin 116: version = read_i32 117: if version < 0 118: if (version & VERSION_MASK != VERSION_1) 119: raise ProtocolException.new(ProtocolException::BAD_VERSION, 'Missing version identifier') 120: end 121: type = version & TYPE_MASK 122: name = read_string 123: seqid = read_i32 124: [name, type, seqid] 125: else 126: if strict_read 127: raise ProtocolException.new(ProtocolException::BAD_VERSION, 'No version identifier, old protocol client?') 128: end 129: name = trans.read_all(version) 130: type = read_byte 131: seqid = read_i32 132: [name, type, seqid] 133: end 134: end
# File lib/thrift/protocol/binary_protocol.rb, line 161 161: def read_set_begin 162: etype = read_byte 163: size = read_i32 164: [etype, size] 165: end
# File lib/thrift/protocol/binary_protocol.rb, line 161 161: def read_set_begin 162: etype = read_byte 163: size = read_i32 164: [etype, size] 165: end
# File lib/thrift/protocol/binary_protocol.rb, line 216 216: def read_string 217: size = read_i32 218: buffer = trans.read_all(size) 219: Bytes.convert_to_string(buffer) 220: end
# File lib/thrift/protocol/binary_protocol.rb, line 216 216: def read_string 217: size = read_i32 218: buffer = trans.read_all(size) 219: Bytes.convert_to_string(buffer) 220: end
# File lib/thrift/protocol/binary_protocol.rb, line 80 80: def write_bool(bool) 81: write_byte(bool ? 1 : 0) 82: end
# File lib/thrift/protocol/binary_protocol.rb, line 80 80: def write_bool(bool) 81: write_byte(bool ? 1 : 0) 82: end
# File lib/thrift/protocol/binary_protocol.rb, line 84 84: def write_byte(byte) 85: raise RangeError if byte < -2**31 || byte >= 2**32 86: trans.write([byte].pack('c')) 87: end
# File lib/thrift/protocol/binary_protocol.rb, line 84 84: def write_byte(byte) 85: raise RangeError if byte < -2**31 || byte >= 2**32 86: trans.write([byte].pack('c')) 87: end
# File lib/thrift/protocol/binary_protocol.rb, line 105 105: def write_double(dub) 106: trans.write([dub].pack('G')) 107: end
# File lib/thrift/protocol/binary_protocol.rb, line 105 105: def write_double(dub) 106: trans.write([dub].pack('G')) 107: end
# File lib/thrift/protocol/binary_protocol.rb, line 55 55: def write_field_begin(name, type, id) 56: write_byte(type) 57: write_i16(id) 58: end
# File lib/thrift/protocol/binary_protocol.rb, line 55 55: def write_field_begin(name, type, id) 56: write_byte(type) 57: write_i16(id) 58: end
# File lib/thrift/protocol/binary_protocol.rb, line 60 60: def write_field_stop 61: write_byte(Thrift::Types::STOP) 62: end
# File lib/thrift/protocol/binary_protocol.rb, line 60 60: def write_field_stop 61: write_byte(Thrift::Types::STOP) 62: end
# File lib/thrift/protocol/binary_protocol.rb, line 89 89: def write_i16(i16) 90: trans.write([i16].pack('n')) 91: end
# File lib/thrift/protocol/binary_protocol.rb, line 89 89: def write_i16(i16) 90: trans.write([i16].pack('n')) 91: end
# File lib/thrift/protocol/binary_protocol.rb, line 93 93: def write_i32(i32) 94: raise RangeError if i32 < -2**31 || i32 >= 2**31 95: trans.write([i32].pack('N')) 96: end
# File lib/thrift/protocol/binary_protocol.rb, line 93 93: def write_i32(i32) 94: raise RangeError if i32 < -2**31 || i32 >= 2**31 95: trans.write([i32].pack('N')) 96: end
# File lib/thrift/protocol/binary_protocol.rb, line 98 98: def write_i64(i64) 99: raise RangeError if i64 < -2**63 || i64 >= 2**64 100: hi = i64 >> 32 101: lo = i64 & 0xffffffff 102: trans.write([hi, lo].pack('N2')) 103: end
# File lib/thrift/protocol/binary_protocol.rb, line 98 98: def write_i64(i64) 99: raise RangeError if i64 < -2**63 || i64 >= 2**64 100: hi = i64 >> 32 101: lo = i64 & 0xffffffff 102: trans.write([hi, lo].pack('N2')) 103: end
# File lib/thrift/protocol/binary_protocol.rb, line 70 70: def write_list_begin(etype, size) 71: write_byte(etype) 72: write_i32(size) 73: end
# File lib/thrift/protocol/binary_protocol.rb, line 70 70: def write_list_begin(etype, size) 71: write_byte(etype) 72: write_i32(size) 73: end
# File lib/thrift/protocol/binary_protocol.rb, line 64 64: def write_map_begin(ktype, vtype, size) 65: write_byte(ktype) 66: write_byte(vtype) 67: write_i32(size) 68: end
# File lib/thrift/protocol/binary_protocol.rb, line 64 64: def write_map_begin(ktype, vtype, size) 65: write_byte(ktype) 66: write_byte(vtype) 67: write_i32(size) 68: end
# File lib/thrift/protocol/binary_protocol.rb, line 38 38: def write_message_begin(name, type, seqid) 39: # this is necessary because we added (needed) bounds checking to 40: # write_i32, and 0x80010000 is too big for that. 41: if strict_write 42: write_i16(VERSION_1 >> 16) 43: write_i16(type) 44: write_string(name) 45: write_i32(seqid) 46: else 47: write_string(name) 48: write_byte(type) 49: write_i32(seqid) 50: end 51: end
# File lib/thrift/protocol/binary_protocol.rb, line 38 38: def write_message_begin(name, type, seqid) 39: # this is necessary because we added (needed) bounds checking to 40: # write_i32, and 0x80010000 is too big for that. 41: if strict_write 42: write_i16(VERSION_1 >> 16) 43: write_i16(type) 44: write_string(name) 45: write_i32(seqid) 46: else 47: write_string(name) 48: write_byte(type) 49: write_i32(seqid) 50: end 51: end
# File lib/thrift/protocol/binary_protocol.rb, line 75 75: def write_set_begin(etype, size) 76: write_byte(etype) 77: write_i32(size) 78: end
# File lib/thrift/protocol/binary_protocol.rb, line 75 75: def write_set_begin(etype, size) 76: write_byte(etype) 77: write_i32(size) 78: end
# File lib/thrift/protocol/binary_protocol.rb, line 109 109: def write_string(str) 110: str = Bytes.convert_to_utf8_byte_buffer(str) 111: write_i32(str.length) 112: trans.write(str) 113: end
# File lib/thrift/protocol/binary_protocol.rb, line 109 109: def write_string(str) 110: str = Bytes.convert_to_utf8_byte_buffer(str) 111: write_i32(str.length) 112: trans.write(str) 113: end