class Thrift::BinaryProtocol
Constants
- BYTE_MAX
- BYTE_MIN
- I16_MAX
- I16_MIN
- I32_MAX
- I32_MIN
- I64_MAX
- I64_MIN
- TYPE_MASK
- VERSION_1
- VERSION_MASK
Attributes
Public Class Methods
Source
# File lib/thrift/protocol/binary_protocol.rb 37 def initialize(trans, strict_read = true, strict_write = true, max_string_size: DEFAULT_MAX_STRING_SIZE) 38 BaseProtocol.validate_max_string_size(max_string_size) 39 super(trans) 40 @reset_message_size = trans.message_boundaries? 41 @strict_read = strict_read 42 @strict_write = strict_write 43 @max_string_size = max_string_size 44 45 # Pre-allocated read buffer for fixed-size read methods. Needs to be at least 8 bytes long for 46 # read_i64() and read_double(). 47 @rbuf = Bytes.empty_byte_buffer(8) 48 end
Calls superclass method
Thrift::BaseProtocol::new
Public Instance Methods
Source
# File lib/thrift/protocol/binary_protocol.rb 258 def read_binary 259 size = read_i32 260 if size >= 0 261 check_string_size(size) 262 trans.read_all(size) 263 else 264 raise ProtocolException.new(ProtocolException::NEGATIVE_SIZE, "Negative size") 265 end 266 end
Source
# File lib/thrift/protocol/binary_protocol.rb 205 def read_bool 206 byte = read_byte 207 byte != 0 208 end
Source
# File lib/thrift/protocol/binary_protocol.rb 210 def read_byte 211 val = trans.read_byte 212 if (val > 0x7f) 213 val = 0 - ((val - 1) ^ 0xff) 214 end 215 val 216 end
Source
# File lib/thrift/protocol/binary_protocol.rb 248 def read_double 249 trans.read_into_buffer(@rbuf, 8) 250 @rbuf.unpack1("G") 251 end
Source
# File lib/thrift/protocol/binary_protocol.rb 173 def read_field_begin 174 type = read_byte 175 if (type == Types::STOP) 176 [nil, type, 0] 177 else 178 id = read_i16 179 [nil, type, id] 180 end 181 end
Source
# File lib/thrift/protocol/binary_protocol.rb 218 def read_i16 219 trans.read_into_buffer(@rbuf, 2) 220 val = @rbuf.unpack1("n") 221 if (val > 0x7fff) 222 val = 0 - ((val - 1) ^ 0xffff) 223 end 224 val 225 end
Source
# File lib/thrift/protocol/binary_protocol.rb 227 def read_i32 228 trans.read_into_buffer(@rbuf, 4) 229 val = @rbuf.unpack1("N") 230 if (val > 0x7fffffff) 231 val = 0 - ((val - 1) ^ 0xffffffff) 232 end 233 val 234 end
Source
# File lib/thrift/protocol/binary_protocol.rb 236 def read_i64 237 trans.read_into_buffer(@rbuf, 8) 238 hi, lo = @rbuf.unpack("N2") 239 if (hi > 0x7fffffff) 240 hi ^= 0xffffffff 241 lo ^= 0xffffffff 242 0 - (hi << 32) - lo - 1 243 else 244 (hi << 32) + lo 245 end 246 end
Source
# File lib/thrift/protocol/binary_protocol.rb 191 def read_list_begin 192 etype = read_byte 193 size = read_i32 194 raise ProtocolException.new(ProtocolException::NEGATIVE_SIZE, "Negative size") unless size >= 0 195 [etype, size] 196 end
Source
# File lib/thrift/protocol/binary_protocol.rb 183 def read_map_begin 184 ktype = read_byte 185 vtype = read_byte 186 size = read_i32 187 raise ProtocolException.new(ProtocolException::NEGATIVE_SIZE, "Negative size") unless size >= 0 188 [ktype, vtype, size] 189 end
Source
# File lib/thrift/protocol/binary_protocol.rb 147 def read_message_begin 148 trans.reset_message_size if @reset_message_size 149 150 version = read_i32 151 if version < 0 152 if (version & VERSION_MASK != VERSION_1) 153 raise ProtocolException.new(ProtocolException::BAD_VERSION, "Missing version identifier") 154 end 155 type = version & TYPE_MASK 156 name = read_string 157 seqid = read_i32 158 [name, type, seqid] 159 else 160 if strict_read 161 raise ProtocolException.new(ProtocolException::BAD_VERSION, "No version identifier, old protocol client?") 162 end 163 check_string_size(version) 164 name = trans.read_all(version) 165 type = read_byte 166 seqid = read_i32 167 [name, type, seqid] 168 end 169 end
Source
# File lib/thrift/protocol/binary_protocol.rb 198 def read_set_begin 199 etype = read_byte 200 size = read_i32 201 raise ProtocolException.new(ProtocolException::NEGATIVE_SIZE, "Negative size") unless size >= 0 202 [etype, size] 203 end
Source
# File lib/thrift/protocol/binary_protocol.rb 253 def read_string 254 buffer = read_binary 255 Bytes.convert_to_string(buffer) 256 end
Source
# File lib/thrift/protocol/binary_protocol.rb 171 def read_struct_begin; nil; end
Source
# File lib/thrift/protocol/binary_protocol.rb 272 def read_uuid 273 UUID.uuid_from_bytes(trans.read_all(16)) 274 end
Source
# File lib/thrift/protocol/binary_protocol.rb 268 def skip_string 269 read_binary 270 end
Source
# File lib/thrift/protocol/binary_protocol.rb 276 def to_s 277 "binary(#{super})" 278 end
Source
# File lib/thrift/protocol/binary_protocol.rb 136 def write_binary(buf) 137 raise "nil argument not allowed!" if buf.nil? 138 write_i32_size(buf.bytesize) 139 trans.write(buf) 140 end
Source
# File lib/thrift/protocol/binary_protocol.rb 91 def write_bool(bool) 92 write_byte(bool ? 1 : 0) 93 end
Source
# File lib/thrift/protocol/binary_protocol.rb 95 def write_byte(byte) 96 raise "nil argument not allowed!" if byte.nil? 97 raise ::TypeError, "integer argument expected" unless byte.is_a?(Integer) 98 raise RangeError if byte < BYTE_MIN || byte > BYTE_MAX 99 trans.write([byte].pack("c")) 100 end
Source
# File lib/thrift/protocol/binary_protocol.rb 125 def write_double(dub) 126 raise "nil argument not allowed!" if dub.nil? 127 trans.write([dub].pack("G")) 128 end
Source
# File lib/thrift/protocol/binary_protocol.rb 66 def write_field_begin(name, type, id) 67 write_byte(type) 68 write_i16(id) 69 end
Source
# File lib/thrift/protocol/binary_protocol.rb 71 def write_field_stop 72 write_byte(Thrift::Types::STOP) 73 end
Source
# File lib/thrift/protocol/binary_protocol.rb 102 def write_i16(i16) 103 raise "nil argument not allowed!" if i16.nil? 104 raise ::TypeError, "integer argument expected" unless i16.is_a?(Integer) 105 raise RangeError if i16 < I16_MIN || i16 > I16_MAX 106 trans.write([i16].pack("n")) 107 end
Source
# File lib/thrift/protocol/binary_protocol.rb 109 def write_i32(i32) 110 raise "nil argument not allowed!" if i32.nil? 111 raise ::TypeError, "integer argument expected" unless i32.is_a?(Integer) 112 raise RangeError if i32 < I32_MIN || i32 > I32_MAX 113 trans.write([i32].pack("N")) 114 end
Source
# File lib/thrift/protocol/binary_protocol.rb 116 def write_i64(i64) 117 raise "nil argument not allowed!" if i64.nil? 118 raise ::TypeError, "integer argument expected" unless i64.is_a?(Integer) 119 raise RangeError if i64 < I64_MIN || i64 > I64_MAX 120 hi = i64 >> 32 121 lo = i64 & 0xffffffff 122 trans.write([hi, lo].pack("N2")) 123 end
Source
# File lib/thrift/protocol/binary_protocol.rb 81 def write_list_begin(etype, size) 82 write_byte(etype) 83 write_i32_size(size) 84 end
Source
# File lib/thrift/protocol/binary_protocol.rb 75 def write_map_begin(ktype, vtype, size) 76 write_byte(ktype) 77 write_byte(vtype) 78 write_i32_size(size) 79 end
Source
# File lib/thrift/protocol/binary_protocol.rb 50 def write_message_begin(name, type, seqid) 51 if strict_write 52 raise ::TypeError, "integer argument expected" unless type.is_a?(Integer) 53 raise RangeError if type < BYTE_MIN || type > BYTE_MAX 54 trans.write([VERSION_1 | type].pack("N")) 55 write_string(name) 56 write_i32(seqid) 57 else 58 write_string(name) 59 write_byte(type) 60 write_i32(seqid) 61 end 62 end
Source
# File lib/thrift/protocol/binary_protocol.rb 86 def write_set_begin(etype, size) 87 write_byte(etype) 88 write_i32_size(size) 89 end
Source
# File lib/thrift/protocol/binary_protocol.rb 130 def write_string(str) 131 raise "nil argument not allowed!" if str.nil? 132 buf = Bytes.convert_to_utf8_byte_buffer(str) 133 write_binary(buf) 134 end
Source
# File lib/thrift/protocol/binary_protocol.rb 64 def write_struct_begin(name); nil; end
Source
# File lib/thrift/protocol/binary_protocol.rb 142 def write_uuid(uuid) 143 UUID.validate_uuid!(uuid) 144 trans.write(UUID.uuid_bytes(uuid)) 145 end
Private Instance Methods
Source
# File lib/thrift/protocol/binary_protocol.rb 282 def write_i32_size(size) 283 raise "nil argument not allowed!" if size.nil? 284 raise ::TypeError, "integer argument expected" unless size.is_a?(Integer) 285 raise RangeError if size < 0 || size > I32_MAX 286 trans.write([size].pack("N")) 287 end