class Thrift::BaseProtocol
Constants
- DEFAULT_MAX_STRING_SIZE
-
The longest string or binary field
BinaryProtocolandCompactProtocolread by default: the frame size limit the framed transports apply. A string’s length is the read size handed to the transport, and an unframed transport has no frame to bound it. Pass max_string_size: nil to read strings of any length. - MAX_CONTAINER_SIZE
Attributes
Public Class Methods
Source
# File lib/thrift/protocol/base_protocol.rb 55 def initialize(trans) 56 @trans = trans 57 end
Source
# File lib/thrift/protocol/base_protocol.rb 72 def self.validate_max_string_size(max_string_size) 73 return if max_string_size.nil? || (max_string_size.is_a?(Integer) && max_string_size > 0) 74 75 raise ArgumentError, "max_string_size must be nil or a positive Integer" 76 end
Public Instance Methods
Source
# File lib/thrift/protocol/base_protocol.rb 65 def check_string_size(size) 66 max = @max_string_size 67 return if max.nil? || size <= max 68 69 raise ProtocolException.new(ProtocolException::SIZE_LIMIT, "String size #{size} larger than the maximum #{max}") 70 end
Raises a SIZE_LIMIT ProtocolException when a declared string length is over the protocol’s max_string_size.
Source
Source
# File lib/thrift/protocol/base_protocol.rb 208 def read_bool 209 raise NotImplementedError 210 end
Source
# File lib/thrift/protocol/base_protocol.rb 212 def read_byte 213 raise NotImplementedError 214 end
Source
# File lib/thrift/protocol/base_protocol.rb 228 def read_double 229 raise NotImplementedError 230 end
Source
# File lib/thrift/protocol/base_protocol.rb 184 def read_field_begin 185 raise NotImplementedError 186 end
Source
# File lib/thrift/protocol/base_protocol.rb 188 def read_field_end; nil; end
Source
# File lib/thrift/protocol/base_protocol.rb 216 def read_i16 217 raise NotImplementedError 218 end
Source
# File lib/thrift/protocol/base_protocol.rb 220 def read_i32 221 raise NotImplementedError 222 end
Source
# File lib/thrift/protocol/base_protocol.rb 224 def read_i64 225 raise NotImplementedError 226 end
Source
# File lib/thrift/protocol/base_protocol.rb 196 def read_list_begin 197 raise NotImplementedError 198 end
Source
# File lib/thrift/protocol/base_protocol.rb 190 def read_map_begin 191 raise NotImplementedError 192 end
Source
# File lib/thrift/protocol/base_protocol.rb 172 def read_message_begin 173 raise NotImplementedError 174 end
Source
# File lib/thrift/protocol/base_protocol.rb 176 def read_message_end; nil; end
Source
# File lib/thrift/protocol/base_protocol.rb 202 def read_set_begin 203 raise NotImplementedError 204 end
Source
# File lib/thrift/protocol/base_protocol.rb 235 def read_string 236 raise NotImplementedError 237 end
Reads a Thrift String. All Strings will be returned with an Encoding of UTF-8.
Returns a String.
Source
# File lib/thrift/protocol/base_protocol.rb 178 def read_struct_begin 179 raise NotImplementedError 180 end
Source
# File lib/thrift/protocol/base_protocol.rb 182 def read_struct_end; nil; end
Source
# File lib/thrift/protocol/base_protocol.rb 337 def read_type(field_info) 338 # if field_info is a Integer, assume it is a Thrift::Types constant 339 # convert it into a field_info Hash for backwards compatibility 340 if field_info.is_a? Integer 341 field_info = {type: field_info} 342 end 343 344 case field_info[:type] 345 when Types::BOOL 346 read_bool 347 when Types::BYTE 348 read_byte 349 when Types::DOUBLE 350 read_double 351 when Types::I16 352 read_i16 353 when Types::I32 354 read_i32 355 when Types::I64 356 read_i64 357 when Types::STRING 358 if field_info[:binary] 359 read_binary 360 else 361 read_string 362 end 363 when Types::UUID 364 read_uuid 365 else 366 raise NotImplementedError 367 end 368 end
Reads a field value based on the field information.
field_info - A Hash containing the pertinent data to write:
:type - The Thrift::Types constant that determines how the value is written. :binary - A flag that indicates if Thrift::Types::STRING is a binary string (string without encoding).
Returns the value read; object type varies based on field_info.
Source
# File lib/thrift/protocol/base_protocol.rb 250 def read_uuid 251 raise NotImplementedError 252 end
Reads a UUID as 16 bytes and returns it as a string.
Returns a String (e.g. “550e8400-e29b-41d4-a716-446655440000”).
Source
# File lib/thrift/protocol/base_protocol.rb 370 def skip(type, max_depth = 64) 371 raise ProtocolException.new(ProtocolException::DEPTH_LIMIT, "Maximum skip depth exceeded") if max_depth <= 0 372 case type 373 when Types::BOOL 374 read_bool 375 when Types::BYTE 376 read_byte 377 when Types::I16 378 read_i16 379 when Types::I32 380 read_i32 381 when Types::I64 382 read_i64 383 when Types::DOUBLE 384 read_double 385 when Types::STRING 386 skip_string 387 when Types::UUID 388 read_uuid 389 when Types::STRUCT 390 read_struct_begin 391 while true 392 _, type, _ = read_field_begin 393 break if type == Types::STOP 394 skip(type, max_depth - 1) 395 read_field_end 396 end 397 read_struct_end 398 when Types::MAP 399 ktype, vtype, size = read_map_begin 400 validate_container_size(size) 401 size.times do 402 skip(ktype, max_depth - 1) 403 skip(vtype, max_depth - 1) 404 end 405 read_map_end 406 when Types::SET 407 etype, size = read_set_begin 408 validate_container_size(size) 409 size.times do 410 skip(etype, max_depth - 1) 411 end 412 read_set_end 413 when Types::LIST 414 etype, size = read_list_begin 415 validate_container_size(size) 416 size.times do 417 skip(etype, max_depth - 1) 418 end 419 read_list_end 420 else 421 raise ProtocolException.new(ProtocolException::INVALID_DATA, "Invalid data") 422 end 423 end
Source
# File lib/thrift/protocol/base_protocol.rb 254 def skip_string 255 read_string 256 end
Source
# File lib/thrift/protocol/base_protocol.rb 425 def validate_container_size(size) 426 raise ProtocolException.new(ProtocolException::NEGATIVE_SIZE, "Negative size") unless size >= 0 427 raise ProtocolException.new(ProtocolException::SIZE_LIMIT, "Container size limit exceeded") if size > MAX_CONTAINER_SIZE 428 end
Source
Source
# File lib/thrift/protocol/base_protocol.rb 118 def write_bool(bool) 119 raise NotImplementedError 120 end
Source
# File lib/thrift/protocol/base_protocol.rb 122 def write_byte(byte) 123 raise NotImplementedError 124 end
Source
# File lib/thrift/protocol/base_protocol.rb 138 def write_double(dub) 139 raise NotImplementedError 140 end
Source
# File lib/thrift/protocol/base_protocol.rb 269 def write_field(field_info, fid, value, remaining_depth = nil) 270 unless field_info.is_a?(Hash) 271 field_info = {name: field_info, type: fid} 272 fid = value 273 value = remaining_depth 274 remaining_depth = nil 275 end 276 277 write_field_begin(field_info[:name], field_info[:type], fid) 278 write_type(field_info, value, remaining_depth) 279 write_field_end 280 end
Writes a field based on the field information, field ID and value.
field_info - A Hash containing the definition of the field:
:name - The name of the field. :type - The type of the field, which must be a Thrift::Types constant. :binary - A Boolean flag that indicates if Thrift::Types::STRING is a binary string (string without encoding).
fid - The ID of the field. value - The field’s value to write; object type varies based on :type. remaining_depth - The optional recursion budget of the enclosing struct.
Returns nothing.
Source
# File lib/thrift/protocol/base_protocol.rb 90 def write_field_begin(name, type, id) 91 raise NotImplementedError 92 end
Source
# File lib/thrift/protocol/base_protocol.rb 94 def write_field_end; nil; end
Source
# File lib/thrift/protocol/base_protocol.rb 96 def write_field_stop 97 raise NotImplementedError 98 end
Source
# File lib/thrift/protocol/base_protocol.rb 126 def write_i16(i16) 127 raise NotImplementedError 128 end
Source
# File lib/thrift/protocol/base_protocol.rb 130 def write_i32(i32) 131 raise NotImplementedError 132 end
Source
# File lib/thrift/protocol/base_protocol.rb 134 def write_i64(i64) 135 raise NotImplementedError 136 end
Source
# File lib/thrift/protocol/base_protocol.rb 106 def write_list_begin(etype, size) 107 raise NotImplementedError 108 end
Source
# File lib/thrift/protocol/base_protocol.rb 110 def write_list_end; nil; end
Source
# File lib/thrift/protocol/base_protocol.rb 100 def write_map_begin(ktype, vtype, size) 101 raise NotImplementedError 102 end
Source
# File lib/thrift/protocol/base_protocol.rb 78 def write_message_begin(name, type, seqid) 79 raise NotImplementedError 80 end
Source
# File lib/thrift/protocol/base_protocol.rb 82 def write_message_end; nil; end
Source
# File lib/thrift/protocol/base_protocol.rb 112 def write_set_begin(etype, size) 113 raise NotImplementedError 114 end
Source
# File lib/thrift/protocol/base_protocol.rb 149 def write_string(str) 150 raise NotImplementedError 151 end
Writes a Thrift String. The String passed will be transcoded to UTF-8.
str - The String to write.
Raises EncodingError if the transcoding to UTF-8 fails.
Returns nothing.
Source
# File lib/thrift/protocol/base_protocol.rb 84 def write_struct_begin(name) 85 raise NotImplementedError 86 end
Source
# File lib/thrift/protocol/base_protocol.rb 88 def write_struct_end; nil; end
Source
# File lib/thrift/protocol/base_protocol.rb 291 def write_type(field_info, value, remaining_depth = nil) 292 # if field_info is a Integer, assume it is a Thrift::Types constant 293 # convert it into a field_info Hash for backwards compatibility 294 if field_info.is_a? Integer 295 field_info = {type: field_info} 296 end 297 298 case field_info[:type] 299 when Types::BOOL 300 write_bool(value) 301 when Types::BYTE 302 write_byte(value) 303 when Types::DOUBLE 304 write_double(value) 305 when Types::I16 306 write_i16(value) 307 when Types::I32 308 write_i32(value) 309 when Types::I64 310 write_i64(value) 311 when Types::STRING 312 if field_info[:binary] 313 write_binary(value) 314 else 315 write_string(value) 316 end 317 when Types::UUID 318 write_uuid(value) 319 when Types::STRUCT 320 if remaining_depth 321 value.write(self, remaining_depth - 1) 322 else 323 value.write(self) 324 end 325 else 326 raise NotImplementedError 327 end 328 end
Writes a field value based on the field information.
field_info - A Hash containing the definition of the field:
:type - The Thrift::Types constant that determines how the value is written. :binary - A Boolean flag that indicates if Thrift::Types::STRING is a binary string (string without encoding).
value - The field’s value to write; object type varies based on field_info. remaining_depth - The optional recursion budget of the enclosing struct.
Returns nothing.