class

Thrift::Protocol::JsonProtocol

Inherits Thrift::Protocol::BaseProtocol < Reference < Object

JsonProtocol writes values to a transport in valid JSON Format

Constants

JSON_ARRAY_END = ']'
JSON_ARRAY_START = '['
JSON_BACKSLASH = '\\'
JSON_CHAR_TABLE = [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, 1, 1, '"', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

This table describes the handling for the first 0x30 characters 0 : escape using "\u00xx" notation 1 : just output index <other> : escape using "<other>" notation

JSON_NEWLINE = '\n'
JSON_OBJECT_END = '}'
JSON_OBJECT_START = '{'
JSON_STRING_DELIMITER = '"'
THRIFT_INFINITY = "Infinity"
THRIFT_NAN = "NaN"
THRIFT_NEGATIVE_INFINITY = "-Infinity"
THRIFT_VERSION1 = 1

Constructors

new(trans)
Source

Class methods

read_syntax_char(reader, ch)

Read 1 character from the trans and verify that it is the expected character ch. Throw a protocol exception if it is not.

Source

Instance methods

get_json_name_from_type(ttype)
Source
get_type_from_json_name(name)
Source
is_json_numeric(ch)

Return true if the character ch is in [-+0-9.Ee]; false otherwise

Source
pop_context
Source
push_context(context : Thrift::JSONContext)
Source
read_binary

Reads a Thrift Binary (Thrift String without encoding). In Crystal 1.5.2 and onward, all Strings will be returned with an Encoding of BINARY.

Returns a String.

Source
read_bool
Source
read_byte
Source
read_double
Source
read_field_begin
Source
read_field_end
Source
read_i16
Source
read_i32
Source
read_i64
Source
read_json_array_end
Source
read_json_array_start
Source
read_json_base64

Reads a block of base64 characters, decoding it, and returns via str

Source
read_json_double

Reads a JSON number or string and interprets it as a double.

Source
read_json_escape_char

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

Source
read_json_integer

Reads a sequence of characters and assembles them into a number, returning them via num

Source
read_json_numeric_chars

Reads a sequence of characters, stopping at the first one that is not a valid JSON numeric character.

Source
read_json_object_end
Source
read_json_object_start
Source
read_json_string(skipContext = false)

Decodes a JSON string, including unescaping, and returns the string via str

Source
read_json_syntax_char(ch)

Reads 1 byte and verifies that it matches ch.

Source
read_list_begin
Source
read_list_end
Source
read_map_begin
Source
read_map_end
Source
read_message_begin
Source
read_message_end
Source
read_set_begin
Source
read_set_end
Source
read_string

Reads a Thrift String. In Crystal 1.5.2 and onward, all Strings will be returned with an Encoding of UTF-8.

Returns a String.

Source
read_struct_begin
Source
read_struct_end
Source
read_uuid
Source
write_binary(buf : Bytes)

Writes a Thrift Binary (Thrift String with no encoding). In Crystal 1.5.2 and onward

buf - The Bytes to write

Returns nothing.

Source
write_bool(bool : Bool)
Source
write_byte(byte : Int8)
Source
write_double(dub : Float64)
Source
write_field_begin(name : String, type : Thrift::Types, id : Int16)
Source
write_field_end
Source
write_field_stop
Source
write_i16(i16 : Int16)
Source
write_i32(i32 : Int32)
Source
write_i64(i64 : Int64)
Source
write_json_array_end
Source
write_json_array_start
Source
write_json_base64(bytes)

Write out the contents of the string as JSON string, base64-encoding the string's contents, and escaping as appropriate

Source
write_json_char(ch)

Write the character ch as part of a JSON string, escaping as appropriate.

Source
write_json_double(num)

Convert the given double to a JSON string, which is either the number, "NaN" or "Infinity" or "-Infinity".

Source
write_json_escape_char(ch)

Write the character ch as a JSON escape sequence ("\u00xx")

Source
write_json_integer(num)

Convert the given integer type to a JSON number, or a string if the context requires it (eg: key in a map pair).

Source
write_json_object_end
Source
write_json_object_start
Source
write_json_string(str)

Write out the contents of the string str as a JSON string, escaping characters as appropriate.

Source
write_list_begin(etype, size)
Source
write_list_end
Source
write_map_begin(ktype, vtype, size)
Source
write_map_end
Source
write_message_begin(name : String, type : Thrift::MessageTypes, seqid : Int32)
Source
write_message_end
Source
write_set_begin(etype, size)
Source
write_set_end
Source
write_string(str : String)

Writes a Thrift String. In Crystal 1.5.2 and onward, 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
write_struct_begin(name)
Source
write_struct_end
Source
write_uuid(uuid : UUID)
Source