class Thrift::BinaryProtocol
Constants
- TYPE_MASK
- VERSION_1
- VERSION_MASK
Attributes
strict_read[R]
strict_write[R]
Public Class Methods
new(trans, strict_read=true, strict_write=true)
click to toggle source
Calls superclass method
Thrift::BaseProtocol::new
# File lib/thrift/protocol/binary_protocol.rb 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
Public Instance Methods
read_binary()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 225 def read_binary 226 size = read_i32 227 trans.read_all(size) 228 end
read_bool()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 171 def read_bool 172 byte = read_byte 173 byte != 0 174 end
read_byte()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 176 def read_byte 177 val = trans.read_byte 178 if (val > 0x7f) 179 val = 0 - ((val - 1) ^ 0xff) 180 end 181 val 182 end
read_double()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 214 def read_double 215 trans.read_into_buffer(@rbuf, 8) 216 val = @rbuf.unpack('G').first 217 val 218 end
read_field_begin()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 142 def read_field_begin 143 type = read_byte 144 if (type == Types::STOP) 145 [nil, type, 0] 146 else 147 id = read_i16 148 [nil, type, id] 149 end 150 end
read_i16()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 184 def read_i16 185 trans.read_into_buffer(@rbuf, 2) 186 val, = @rbuf.unpack('n') 187 if (val > 0x7fff) 188 val = 0 - ((val - 1) ^ 0xffff) 189 end 190 val 191 end
read_i32()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 193 def read_i32 194 trans.read_into_buffer(@rbuf, 4) 195 val, = @rbuf.unpack('N') 196 if (val > 0x7fffffff) 197 val = 0 - ((val - 1) ^ 0xffffffff) 198 end 199 val 200 end
read_i64()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 202 def read_i64 203 trans.read_into_buffer(@rbuf, 8) 204 hi, lo = @rbuf.unpack('N2') 205 if (hi > 0x7fffffff) 206 hi ^= 0xffffffff 207 lo ^= 0xffffffff 208 0 - (hi << 32) - lo - 1 209 else 210 (hi << 32) + lo 211 end 212 end
read_list_begin()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 159 def read_list_begin 160 etype = read_byte 161 size = read_i32 162 [etype, size] 163 end
read_map_begin()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 152 def read_map_begin 153 ktype = read_byte 154 vtype = read_byte 155 size = read_i32 156 [ktype, vtype, size] 157 end
read_message_begin()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 119 def read_message_begin 120 version = read_i32 121 if version < 0 122 if (version & VERSION_MASK != VERSION_1) 123 raise ProtocolException.new(ProtocolException::BAD_VERSION, 'Missing version identifier') 124 end 125 type = version & TYPE_MASK 126 name = read_string 127 seqid = read_i32 128 [name, type, seqid] 129 else 130 if strict_read 131 raise ProtocolException.new(ProtocolException::BAD_VERSION, 'No version identifier, old protocol client?') 132 end 133 name = trans.read_all(version) 134 type = read_byte 135 seqid = read_i32 136 [name, type, seqid] 137 end 138 end
read_set_begin()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 165 def read_set_begin 166 etype = read_byte 167 size = read_i32 168 [etype, size] 169 end
read_string()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 220 def read_string 221 buffer = read_binary 222 Bytes.convert_to_string(buffer) 223 end
read_struct_begin()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 140 def read_struct_begin; nil; end
to_s()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 230 def to_s 231 "binary(#{super.to_s})" 232 end
write_binary(buf)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 114 def write_binary(buf) 115 write_i32(buf.bytesize) 116 trans.write(buf) 117 end
write_bool(bool)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 80 def write_bool(bool) 81 write_byte(bool ? 1 : 0) 82 end
write_byte(byte)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 84 def write_byte(byte) 85 raise RangeError if byte < -2**31 || byte >= 2**32 86 trans.write([byte].pack('c')) 87 end
write_double(dub)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 105 def write_double(dub) 106 trans.write([dub].pack('G')) 107 end
write_field_begin(name, type, id)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 55 def write_field_begin(name, type, id) 56 write_byte(type) 57 write_i16(id) 58 end
write_field_stop()
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 60 def write_field_stop 61 write_byte(Thrift::Types::STOP) 62 end
write_i16(i16)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 89 def write_i16(i16) 90 trans.write([i16].pack('n')) 91 end
write_i32(i32)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 93 def write_i32(i32) 94 raise RangeError if i32 < -2**31 || i32 >= 2**31 95 trans.write([i32].pack('N')) 96 end
write_i64(i64)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 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
write_list_begin(etype, size)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 70 def write_list_begin(etype, size) 71 write_byte(etype) 72 write_i32(size) 73 end
write_map_begin(ktype, vtype, size)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 64 def write_map_begin(ktype, vtype, size) 65 write_byte(ktype) 66 write_byte(vtype) 67 write_i32(size) 68 end
write_message_begin(name, type, seqid)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 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
write_set_begin(etype, size)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 75 def write_set_begin(etype, size) 76 write_byte(etype) 77 write_i32(size) 78 end
write_string(str)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 109 def write_string(str) 110 buf = Bytes.convert_to_utf8_byte_buffer(str) 111 write_binary(buf) 112 end
write_struct_begin(name)
click to toggle source
# File lib/thrift/protocol/binary_protocol.rb 53 def write_struct_begin(name); nil; end