Class: Thrift::JsonProtocol
- Inherits:
-
BaseProtocol
- Object
- BaseProtocol
- Thrift::JsonProtocol
- Defined in:
- lib/thrift/protocol/json_protocol.rb
Constant Summary collapse
- @@kJSONObjectStart =
'{'- @@kJSONObjectEnd =
'}'- @@kJSONArrayStart =
'['- @@kJSONArrayEnd =
']'- @@kJSONNewline =
'\n'- @@kJSONBackslash =
'\\'- @@kJSONStringDelimiter =
'"'- @@kThriftVersion1 =
1- @@kThriftNan =
"NaN"- @@kThriftInfinity =
"Infinity"- @@kThriftNegativeInfinity =
"-Infinity"
Instance Attribute Summary
Attributes inherited from BaseProtocol
Class Method Summary collapse
-
.read_syntax_char(reader, ch) ⇒ Object
Read 1 character from the trans and verify that it is the expected character ch.
Instance Method Summary collapse
- #get_type_id_for_type_name(name) ⇒ Object
- #get_type_name_for_type_id(id) ⇒ Object
-
#initialize(trans) ⇒ JsonProtocol
constructor
A new instance of JsonProtocol.
-
#is_json_numeric(ch) ⇒ Object
Return true if the character ch is in [-+0-9.Ee]; false otherwise.
- #pop_context ⇒ Object
- #push_context(context) ⇒ Object
- #read_binary ⇒ Object
- #read_bool ⇒ Object
- #read_byte ⇒ Object
- #read_double ⇒ Object
- #read_field_begin ⇒ Object
- #read_field_end ⇒ Object
- #read_i16 ⇒ Object
- #read_i32 ⇒ Object
- #read_i64 ⇒ Object
- #read_json_array_end ⇒ Object
- #read_json_array_start ⇒ Object
-
#read_json_base64 ⇒ Object
Reads a block of base64 characters, decoding it, and returns via str.
-
#read_json_double ⇒ Object
Reads a JSON number or string and interprets it as a double.
-
#read_json_escape_char ⇒ Object
Decodes the four hex parts of a JSON escaped string character and returns the character via out.
-
#read_json_integer ⇒ Object
Reads a sequence of characters and assembles them into a number, returning them via num.
-
#read_json_numeric_chars ⇒ Object
Reads a sequence of characters, stopping at the first one that is not a valid JSON numeric character.
- #read_json_object_end ⇒ Object
- #read_json_object_start ⇒ Object
-
#read_json_string(skipContext = false) ⇒ Object
Decodes a JSON string, including unescaping, and returns the string via str.
-
#read_json_syntax_char(ch) ⇒ Object
Reads 1 byte and verifies that it matches ch.
- #read_list_begin ⇒ Object
- #read_list_end ⇒ Object
- #read_map_begin ⇒ Object
- #read_map_end ⇒ Object
- #read_message_begin ⇒ Object
- #read_message_end ⇒ Object
- #read_set_begin ⇒ Object
- #read_set_end ⇒ Object
- #read_string ⇒ Object
- #read_struct_begin ⇒ Object
- #read_struct_end ⇒ Object
- #read_uuid ⇒ Object
- #to_s ⇒ Object
- #write_binary(str) ⇒ Object
- #write_bool(bool) ⇒ Object
- #write_byte(byte) ⇒ Object
- #write_double(dub) ⇒ Object
- #write_field_begin(name, type, id) ⇒ Object
- #write_field_end ⇒ Object
- #write_field_stop ⇒ Object
- #write_i16(i16) ⇒ Object
- #write_i32(i32) ⇒ Object
- #write_i64(i64) ⇒ Object
- #write_json_array_end ⇒ Object
- #write_json_array_start ⇒ Object
-
#write_json_base64(str) ⇒ Object
Write out the contents of the string as JSON string, base64-encoding the string's contents, and escaping as appropriate.
-
#write_json_char(ch) ⇒ Object
Write the character ch as part of a JSON string, escaping as appropriate.
-
#write_json_double(num) ⇒ Object
Convert the given double to a JSON string, which is either the number, "NaN" or "Infinity" or "-Infinity".
-
#write_json_escape_char(ch) ⇒ Object
Write the character ch as a JSON escape sequence ("\u00xx").
-
#write_json_integer(num) ⇒ Object
Convert the given integer type to a JSON number, or a string if the context requires it (eg: key in a map pair).
- #write_json_object_end ⇒ Object
- #write_json_object_start ⇒ Object
-
#write_json_string(str) ⇒ Object
Write out the contents of the string str as a JSON string, escaping characters as appropriate.
- #write_list_begin(etype, size) ⇒ Object
- #write_list_end ⇒ Object
- #write_map_begin(ktype, vtype, size) ⇒ Object
- #write_map_end ⇒ Object
- #write_message_begin(name, type, seqid) ⇒ Object
- #write_message_end ⇒ Object
- #write_set_begin(etype, size) ⇒ Object
- #write_set_end ⇒ Object
- #write_string(str) ⇒ Object
- #write_struct_begin(name) ⇒ Object
- #write_struct_end ⇒ Object
- #write_uuid(uuid) ⇒ Object
Methods inherited from BaseProtocol
#native?, #read_type, #skip, #validate_container_size, #write_field, #write_type
Constructor Details
#initialize(trans) ⇒ JsonProtocol
Returns a new instance of JsonProtocol.
152 153 154 155 156 157 |
# File 'lib/thrift/protocol/json_protocol.rb', line 152 def initialize(trans) super(trans) @context = JSONContext.new @contexts = Array.new @reader = LookaheadReader.new(trans) end |
Class Method Details
.read_syntax_char(reader, ch) ⇒ Object
Read 1 character from the trans and verify that it is the expected character ch. Throw a protocol exception if it is not.
228 229 230 231 232 233 |
# File 'lib/thrift/protocol/json_protocol.rb', line 228 def self.read_syntax_char(reader, ch) ch2 = reader.read if (ch2 != ch) raise ProtocolException.new(ProtocolException::INVALID_DATA, "Expected \'#{ch}\' got \'#{ch2}\'.") end end |
Instance Method Details
#get_type_id_for_type_name(name) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/thrift/protocol/json_protocol.rb', line 190 def get_type_id_for_type_name(name) if (name == "tf") result = Types::BOOL elsif (name == "i8") result = Types::BYTE elsif (name == "i16") result = Types::I16 elsif (name == "i32") result = Types::I32 elsif (name == "i64") result = Types::I64 elsif (name == "dbl") result = Types::DOUBLE elsif (name == "str") result = Types::STRING elsif (name == "rec") result = Types::STRUCT elsif (name == "map") result = Types::MAP elsif (name == "set") result = Types::SET elsif (name == "lst") result = Types::LIST elsif (name == "uid") result = Types::UUID else result = Types::STOP end if (result == Types::STOP) raise NotImplementedError end return result end |
#get_type_name_for_type_id(id) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/thrift/protocol/json_protocol.rb', line 159 def get_type_name_for_type_id(id) case id when Types::BOOL "tf" when Types::BYTE "i8" when Types::I16 "i16" when Types::I32 "i32" when Types::I64 "i64" when Types::DOUBLE "dbl" when Types::STRING "str" when Types::STRUCT "rec" when Types::MAP "map" when Types::SET "set" when Types::LIST "lst" when Types::UUID "uid" else raise NotImplementedError end end |
#is_json_numeric(ch) ⇒ Object
Return true if the character ch is in [-+0-9.Ee]; false otherwise
236 237 238 239 240 241 242 243 |
# File 'lib/thrift/protocol/json_protocol.rb', line 236 def is_json_numeric(ch) case ch when '+', '-', '.', '0' .. '9', 'E', "e" return true else return false end end |
#pop_context ⇒ Object
250 251 252 |
# File 'lib/thrift/protocol/json_protocol.rb', line 250 def pop_context @context = @contexts.pop end |
#push_context(context) ⇒ Object
245 246 247 248 |
# File 'lib/thrift/protocol/json_protocol.rb', line 245 def push_context(context) @contexts.push(@context) @context = context end |
#read_binary ⇒ Object
778 779 780 |
# File 'lib/thrift/protocol/json_protocol.rb', line 778 def read_binary read_json_base64 end |
#read_bool ⇒ Object
749 750 751 752 |
# File 'lib/thrift/protocol/json_protocol.rb', line 749 def read_bool byte = read_byte byte != 0 end |
#read_byte ⇒ Object
754 755 756 |
# File 'lib/thrift/protocol/json_protocol.rb', line 754 def read_byte read_json_integer end |
#read_double ⇒ Object
770 771 772 |
# File 'lib/thrift/protocol/json_protocol.rb', line 770 def read_double read_json_double end |
#read_field_begin ⇒ Object
693 694 695 696 697 698 699 700 701 702 703 704 |
# File 'lib/thrift/protocol/json_protocol.rb', line 693 def read_field_begin # Check if we hit the end of the list ch = @reader.peek if (ch == @@kJSONObjectEnd) field_type = Types::STOP else field_id = read_json_integer read_json_object_start field_type = get_type_id_for_type_name(read_json_string) end [nil, field_type, field_id] end |
#read_field_end ⇒ Object
706 707 708 |
# File 'lib/thrift/protocol/json_protocol.rb', line 706 def read_field_end read_json_object_end end |
#read_i16 ⇒ Object
758 759 760 |
# File 'lib/thrift/protocol/json_protocol.rb', line 758 def read_i16 read_json_integer end |
#read_i32 ⇒ Object
762 763 764 |
# File 'lib/thrift/protocol/json_protocol.rb', line 762 def read_i32 read_json_integer end |
#read_i64 ⇒ Object
766 767 768 |
# File 'lib/thrift/protocol/json_protocol.rb', line 766 def read_i64 read_json_integer end |
#read_json_array_end ⇒ Object
660 661 662 663 664 |
# File 'lib/thrift/protocol/json_protocol.rb', line 660 def read_json_array_end read_json_syntax_char(@@kJSONArrayEnd) pop_context nil end |
#read_json_array_start ⇒ Object
653 654 655 656 657 658 |
# File 'lib/thrift/protocol/json_protocol.rb', line 653 def read_json_array_start @context.read(@reader) read_json_syntax_char(@@kJSONArrayStart) push_context(JSONListContext.new) nil end |
#read_json_base64 ⇒ Object
Reads a block of base64 characters, decoding it, and returns via str
552 553 554 555 556 557 558 559 560 561 562 |
# File 'lib/thrift/protocol/json_protocol.rb', line 552 def read_json_base64 str = read_json_string m = str.length % 4 if m != 0 # Add missing padding (4 - m).times do str += '=' end end str.unpack1('m0') end |
#read_json_double ⇒ Object
Reads a JSON number or string and interprets it as a double.
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/thrift/protocol/json_protocol.rb', line 602 def read_json_double @context.read(@reader) num = 0 if (@reader.peek == @@kJSONStringDelimiter) str = read_json_string(true) # Check for NaN, Infinity and -Infinity if (str == @@kThriftNan) num = (+1.0/0.0)/(+1.0/0.0) elsif (str == @@kThriftInfinity) num = +1.0/0.0 elsif (str == @@kThriftNegativeInfinity) num = -1.0/0.0 else if (!@context.escapeNum) # Raise exception -- we should not be in a string in this case raise ProtocolException.new(ProtocolException::INVALID_DATA, "Numeric data unexpectedly quoted") end begin num = Float(str) rescue raise ProtocolException.new(ProtocolException::INVALID_DATA, "Expected numeric value; got \"#{str}\"") end end else if (@context.escapeNum) # This will throw - we should have had a quote if escapeNum == true read_json_syntax_char(@@kJSONStringDelimiter) end str = read_json_numeric_chars begin num = Float(str) rescue raise ProtocolException.new(ProtocolException::INVALID_DATA, "Expected numeric value; got \"#{str}\"") end end return num end |
#read_json_escape_char ⇒ Object
Decodes the four hex parts of a JSON escaped string character and returns the character via out.
Note - this only supports Unicode characters in the BMP (U+0000 to U+FFFF); characters above the BMP are encoded as two escape sequences (surrogate pairs), which is not yet implemented
503 504 505 506 507 508 509 |
# File 'lib/thrift/protocol/json_protocol.rb', line 503 def read_json_escape_char str = +@reader.read str << @reader.read str << @reader.read str << @reader.read str.hex.chr(Encoding::UTF_8) end |
#read_json_integer ⇒ Object
Reads a sequence of characters and assembles them into a number, returning them via num
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
# File 'lib/thrift/protocol/json_protocol.rb', line 581 def read_json_integer @context.read(@reader) if (@context.escapeNum) read_json_syntax_char(@@kJSONStringDelimiter) end str = read_json_numeric_chars begin num = Integer(str); rescue raise ProtocolException.new(ProtocolException::INVALID_DATA, "Expected numeric value; got \"#{str}\"") end if (@context.escapeNum) read_json_syntax_char(@@kJSONStringDelimiter) end return num end |
#read_json_numeric_chars ⇒ Object
Reads a sequence of characters, stopping at the first one that is not a valid JSON numeric character.
566 567 568 569 570 571 572 573 574 575 576 577 |
# File 'lib/thrift/protocol/json_protocol.rb', line 566 def read_json_numeric_chars str = String.new(encoding: Encoding::UTF_8) while (true) ch = @reader.peek if (!is_json_numeric(ch)) break; end ch = @reader.read str << ch end return str end |
#read_json_object_end ⇒ Object
647 648 649 650 651 |
# File 'lib/thrift/protocol/json_protocol.rb', line 647 def read_json_object_end read_json_syntax_char(@@kJSONObjectEnd) pop_context nil end |
#read_json_object_start ⇒ Object
640 641 642 643 644 645 |
# File 'lib/thrift/protocol/json_protocol.rb', line 640 def read_json_object_start @context.read(@reader) read_json_syntax_char(@@kJSONObjectStart) push_context(JSONPairContext.new) nil end |
#read_json_string(skipContext = false) ⇒ Object
Decodes a JSON string, including unescaping, and returns the string via str
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/thrift/protocol/json_protocol.rb', line 512 def read_json_string(skipContext = false) # This string's characters must match up with the elements in escape_char_vals. # I don't have '/' on this list even though it appears on www.json.org -- # it is not in the RFC -> it is. See RFC 4627 escape_chars = "\"\\/bfnrt" # The elements of this array must match up with the sequence of characters in # escape_chars escape_char_vals = [ "\"", "\\", "\/", "\b", "\f", "\n", "\r", "\t", ] if !skipContext @context.read(@reader) end read_json_syntax_char(@@kJSONStringDelimiter) str = +'' while (true) ch = @reader.read if (ch == @@kJSONStringDelimiter) break end if (ch == @@kJSONBackslash) ch = @reader.read if (ch == 'u') ch = read_json_escape_char else pos = escape_chars.index(ch); if (pos.nil?) # not found raise ProtocolException.new(ProtocolException::INVALID_DATA, "Expected control char, got \'#{ch}\'.") end ch = escape_char_vals[pos] end end str << ch end return str end |
#read_json_syntax_char(ch) ⇒ Object
Reads 1 byte and verifies that it matches ch.
493 494 495 |
# File 'lib/thrift/protocol/json_protocol.rb', line 493 def read_json_syntax_char(ch) JsonProtocol::read_syntax_char(@reader, ch) end |
#read_list_begin ⇒ Object
725 726 727 728 729 730 731 |
# File 'lib/thrift/protocol/json_protocol.rb', line 725 def read_list_begin read_json_array_start type = get_type_id_for_type_name(read_json_string) size = read_json_integer validate_container_size(size) [type, size] end |
#read_list_end ⇒ Object
733 734 735 |
# File 'lib/thrift/protocol/json_protocol.rb', line 733 def read_list_end read_json_array_end end |
#read_map_begin ⇒ Object
710 711 712 713 714 715 716 717 718 |
# File 'lib/thrift/protocol/json_protocol.rb', line 710 def read_map_begin read_json_array_start key_type = get_type_id_for_type_name(read_json_string) val_type = get_type_id_for_type_name(read_json_string) size = read_json_integer validate_container_size(size) read_json_object_start [key_type, val_type, size] end |
#read_map_end ⇒ Object
720 721 722 723 |
# File 'lib/thrift/protocol/json_protocol.rb', line 720 def read_map_end read_json_object_end read_json_array_end end |
#read_message_begin ⇒ Object
666 667 668 669 670 671 672 673 674 675 676 |
# File 'lib/thrift/protocol/json_protocol.rb', line 666 def read_json_array_start version = read_json_integer if (version != @@kThriftVersion1) raise ProtocolException.new(ProtocolException::BAD_VERSION, 'Message contained bad version.') end name = read_json_string = read_json_integer seqid = read_json_integer [name, , seqid] end |
#read_message_end ⇒ Object
678 679 680 681 |
# File 'lib/thrift/protocol/json_protocol.rb', line 678 def read_json_array_end nil end |
#read_set_begin ⇒ Object
737 738 739 740 741 742 743 |
# File 'lib/thrift/protocol/json_protocol.rb', line 737 def read_set_begin read_json_array_start type = get_type_id_for_type_name(read_json_string) size = read_json_integer validate_container_size(size) [type, size] end |
#read_set_end ⇒ Object
745 746 747 |
# File 'lib/thrift/protocol/json_protocol.rb', line 745 def read_set_end read_json_array_end end |
#read_string ⇒ Object
774 775 776 |
# File 'lib/thrift/protocol/json_protocol.rb', line 774 def read_string read_json_string end |
#read_struct_begin ⇒ Object
683 684 685 686 |
# File 'lib/thrift/protocol/json_protocol.rb', line 683 def read_struct_begin read_json_object_start nil end |
#read_struct_end ⇒ Object
688 689 690 691 |
# File 'lib/thrift/protocol/json_protocol.rb', line 688 def read_struct_end read_json_object_end nil end |
#read_uuid ⇒ Object
782 783 784 785 786 787 |
# File 'lib/thrift/protocol/json_protocol.rb', line 782 def read_uuid uuid = read_json_string raise EOFError.new if uuid.length < 36 UUID.validate_uuid!(uuid) uuid.tap(&:downcase!) end |
#to_s ⇒ Object
789 790 791 |
# File 'lib/thrift/protocol/json_protocol.rb', line 789 def to_s "json(#{super.to_s})" end |
#write_binary(str) ⇒ Object
479 480 481 |
# File 'lib/thrift/protocol/json_protocol.rb', line 479 def write_binary(str) write_json_base64(str) end |
#write_bool(bool) ⇒ Object
451 452 453 |
# File 'lib/thrift/protocol/json_protocol.rb', line 451 def write_bool(bool) write_json_integer(bool ? 1 : 0) end |
#write_byte(byte) ⇒ Object
455 456 457 |
# File 'lib/thrift/protocol/json_protocol.rb', line 455 def write_byte(byte) write_json_integer(byte) end |
#write_double(dub) ⇒ Object
471 472 473 |
# File 'lib/thrift/protocol/json_protocol.rb', line 471 def write_double(dub) write_json_double(dub) end |
#write_field_begin(name, type, id) ⇒ Object
406 407 408 409 410 |
# File 'lib/thrift/protocol/json_protocol.rb', line 406 def write_field_begin(name, type, id) write_json_integer(id) write_json_object_start write_json_string(get_type_name_for_type_id(type)) end |
#write_field_end ⇒ Object
412 413 414 |
# File 'lib/thrift/protocol/json_protocol.rb', line 412 def write_field_end write_json_object_end end |
#write_field_stop ⇒ Object
416 |
# File 'lib/thrift/protocol/json_protocol.rb', line 416 def write_field_stop; nil; end |
#write_i16(i16) ⇒ Object
459 460 461 |
# File 'lib/thrift/protocol/json_protocol.rb', line 459 def write_i16(i16) write_json_integer(i16) end |
#write_i32(i32) ⇒ Object
463 464 465 |
# File 'lib/thrift/protocol/json_protocol.rb', line 463 def write_i32(i32) write_json_integer(i32) end |
#write_i64(i64) ⇒ Object
467 468 469 |
# File 'lib/thrift/protocol/json_protocol.rb', line 467 def write_i64(i64) write_json_integer(i64) end |
#write_json_array_end ⇒ Object
381 382 383 384 |
# File 'lib/thrift/protocol/json_protocol.rb', line 381 def write_json_array_end pop_context trans.write(@@kJSONArrayEnd) end |
#write_json_array_start ⇒ Object
375 376 377 378 379 |
# File 'lib/thrift/protocol/json_protocol.rb', line 375 def write_json_array_start @context.write(trans) trans.write(@@kJSONArrayStart) push_context(JSONListContext.new); end |
#write_json_base64(str) ⇒ Object
Write out the contents of the string as JSON string, base64-encoding the string's contents, and escaping as appropriate
314 315 316 317 318 319 |
# File 'lib/thrift/protocol/json_protocol.rb', line 314 def write_json_base64(str) @context.write(trans) trans.write(@@kJSONStringDelimiter) trans.write([str].pack('m0')) trans.write(@@kJSONStringDelimiter) end |
#write_json_char(ch) ⇒ Object
Write the character ch as part of a JSON string, escaping as appropriate.
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/thrift/protocol/json_protocol.rb', line 265 def write_json_char(ch) # This table describes the handling for the first 0x30 characters # 0 : escape using "\u00xx" notation # 1 : just output index # <other> : escape using "\<other>" notation kJSONCharTable = [ # 0 1 2 3 4 5 6 7 8 9 A B C D E F 0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0, # 0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 1 1, 1, '"', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, # 2 ] ch_value = ch[0] if (ch_value.kind_of? String) ch_value = ch.bytes.first end if (ch_value >= 0x30) if (ch == @@kJSONBackslash) # Only special character >= 0x30 is '\' trans.write(@@kJSONBackslash) trans.write(@@kJSONBackslash) else trans.write(ch) end else outCh = kJSONCharTable[ch_value]; # Check if regular character, backslash escaped, or JSON escaped if outCh.kind_of? String trans.write(@@kJSONBackslash) trans.write(outCh) elsif outCh == 1 trans.write(ch) else write_json_escape_char(ch) end end end |
#write_json_double(num) ⇒ Object
Convert the given double to a JSON string, which is either the number, "NaN" or "Infinity" or "-Infinity".
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/thrift/protocol/json_protocol.rb', line 337 def write_json_double(num) @context.write(trans) # Normalize output of thrift::to_string for NaNs and Infinities special = false; if (num.nan?) special = true; val = @@kThriftNan; elsif (num.infinite?) special = true; val = @@kThriftInfinity; if (num < 0.0) val = @@kThriftNegativeInfinity; end else val = num.to_s end escapeNum = special || @context.escapeNum if (escapeNum) trans.write(@@kJSONStringDelimiter) end trans.write(val) if (escapeNum) trans.write(@@kJSONStringDelimiter) end end |
#write_json_escape_char(ch) ⇒ Object
Write the character ch as a JSON escape sequence ("\u00xx")
255 256 257 258 259 260 261 262 |
# File 'lib/thrift/protocol/json_protocol.rb', line 255 def write_json_escape_char(ch) trans.write('\\u') ch_value = ch[0] if (ch_value.kind_of? String) ch_value = ch.bytes.first end trans.write(ch_value.to_s(16).rjust(4, '0')) end |
#write_json_integer(num) ⇒ Object
Convert the given integer type to a JSON number, or a string if the context requires it (eg: key in a map pair).
323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/thrift/protocol/json_protocol.rb', line 323 def write_json_integer(num) @context.write(trans) escapeNum = @context.escapeNum if (escapeNum) trans.write(@@kJSONStringDelimiter) end trans.write(num.to_s); if (escapeNum) trans.write(@@kJSONStringDelimiter) end end |
#write_json_object_end ⇒ Object
370 371 372 373 |
# File 'lib/thrift/protocol/json_protocol.rb', line 370 def write_json_object_end pop_context trans.write(@@kJSONObjectEnd) end |
#write_json_object_start ⇒ Object
364 365 366 367 368 |
# File 'lib/thrift/protocol/json_protocol.rb', line 364 def write_json_object_start @context.write(trans) trans.write(@@kJSONObjectStart) push_context(JSONPairContext.new); end |
#write_json_string(str) ⇒ Object
Write out the contents of the string str as a JSON string, escaping characters as appropriate.
303 304 305 306 307 308 309 310 |
# File 'lib/thrift/protocol/json_protocol.rb', line 303 def write_json_string(str) @context.write(trans) trans.write(@@kJSONStringDelimiter) str.split('').each do |ch| write_json_char(ch) end trans.write(@@kJSONStringDelimiter) end |
#write_list_begin(etype, size) ⇒ Object
431 432 433 434 435 |
# File 'lib/thrift/protocol/json_protocol.rb', line 431 def write_list_begin(etype, size) write_json_array_start write_json_string(get_type_name_for_type_id(etype)) write_json_integer(size) end |
#write_list_end ⇒ Object
437 438 439 |
# File 'lib/thrift/protocol/json_protocol.rb', line 437 def write_list_end write_json_array_end end |
#write_map_begin(ktype, vtype, size) ⇒ Object
418 419 420 421 422 423 424 |
# File 'lib/thrift/protocol/json_protocol.rb', line 418 def write_map_begin(ktype, vtype, size) write_json_array_start write_json_string(get_type_name_for_type_id(ktype)) write_json_string(get_type_name_for_type_id(vtype)) write_json_integer(size) write_json_object_start end |
#write_map_end ⇒ Object
426 427 428 429 |
# File 'lib/thrift/protocol/json_protocol.rb', line 426 def write_map_end write_json_object_end write_json_array_end end |
#write_message_begin(name, type, seqid) ⇒ Object
386 387 388 389 390 391 392 |
# File 'lib/thrift/protocol/json_protocol.rb', line 386 def (name, type, seqid) write_json_array_start write_json_integer(@@kThriftVersion1) write_json_string(name) write_json_integer(type) write_json_integer(seqid) end |
#write_message_end ⇒ Object
394 395 396 |
# File 'lib/thrift/protocol/json_protocol.rb', line 394 def write_json_array_end end |
#write_set_begin(etype, size) ⇒ Object
441 442 443 444 445 |
# File 'lib/thrift/protocol/json_protocol.rb', line 441 def write_set_begin(etype, size) write_json_array_start write_json_string(get_type_name_for_type_id(etype)) write_json_integer(size) end |
#write_set_end ⇒ Object
447 448 449 |
# File 'lib/thrift/protocol/json_protocol.rb', line 447 def write_set_end write_json_array_end end |
#write_string(str) ⇒ Object
475 476 477 |
# File 'lib/thrift/protocol/json_protocol.rb', line 475 def write_string(str) write_json_string(str) end |
#write_struct_begin(name) ⇒ Object
398 399 400 |
# File 'lib/thrift/protocol/json_protocol.rb', line 398 def write_struct_begin(name) write_json_object_start end |
#write_struct_end ⇒ Object
402 403 404 |
# File 'lib/thrift/protocol/json_protocol.rb', line 402 def write_struct_end write_json_object_end end |
#write_uuid(uuid) ⇒ Object
483 484 485 486 |
# File 'lib/thrift/protocol/json_protocol.rb', line 483 def write_uuid(uuid) UUID.validate_uuid!(uuid) write_json_string(uuid.downcase) end |