Class Thrift::BinaryProtocol
In: lib/thrift/protocol/binary_protocol.rb
lib/thrift/protocol/binary_protocol.rb
Parent: BaseProtocol

Methods

Constants

VERSION_MASK = 0xffff0000
VERSION_1 = 0x80010000
TYPE_MASK = 0x000000ff
VERSION_MASK = 0xffff0000
VERSION_1 = 0x80010000
TYPE_MASK = 0x000000ff

Attributes

strict_read  [R] 
strict_read  [R] 
strict_write  [R] 
strict_write  [R] 

Public Class methods

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 28
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 = "\0" * 8
36:       @rbuf.force_encoding("BINARY") if @rbuf.respond_to?(:force_encoding)
37:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 28
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 = "\0" * 8
36:       @rbuf.force_encoding("BINARY") if @rbuf.respond_to?(:force_encoding)
37:     end

Public Instance methods

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 167
167:     def read_bool
168:       byte = read_byte
169:       byte != 0
170:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 167
167:     def read_bool
168:       byte = read_byte
169:       byte != 0
170:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 172
172:     def read_byte
173:       val = trans.read_byte
174:       if (val > 0x7f)
175:         val = 0 - ((val - 1) ^ 0xff)
176:       end
177:       val
178:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 172
172:     def read_byte
173:       val = trans.read_byte
174:       if (val > 0x7f)
175:         val = 0 - ((val - 1) ^ 0xff)
176:       end
177:       val
178:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 210
210:     def read_double
211:       trans.read_into_buffer(@rbuf, 8)
212:       val = @rbuf.unpack('G').first
213:       val
214:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 210
210:     def read_double
211:       trans.read_into_buffer(@rbuf, 8)
212:       val = @rbuf.unpack('G').first
213:       val
214:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 138
138:     def read_field_begin
139:       type = read_byte
140:       if (type == Types::STOP)
141:         [nil, type, 0]
142:       else
143:         id = read_i16
144:         [nil, type, id]
145:       end
146:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 138
138:     def read_field_begin
139:       type = read_byte
140:       if (type == Types::STOP)
141:         [nil, type, 0]
142:       else
143:         id = read_i16
144:         [nil, type, id]
145:       end
146:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 180
180:     def read_i16
181:       trans.read_into_buffer(@rbuf, 2)
182:       val, = @rbuf.unpack('n')
183:       if (val > 0x7fff)
184:         val = 0 - ((val - 1) ^ 0xffff)
185:       end
186:       val
187:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 180
180:     def read_i16
181:       trans.read_into_buffer(@rbuf, 2)
182:       val, = @rbuf.unpack('n')
183:       if (val > 0x7fff)
184:         val = 0 - ((val - 1) ^ 0xffff)
185:       end
186:       val
187:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 189
189:     def read_i32
190:       trans.read_into_buffer(@rbuf, 4)
191:       val, = @rbuf.unpack('N')
192:       if (val > 0x7fffffff)
193:         val = 0 - ((val - 1) ^ 0xffffffff)
194:       end
195:       val
196:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 189
189:     def read_i32
190:       trans.read_into_buffer(@rbuf, 4)
191:       val, = @rbuf.unpack('N')
192:       if (val > 0x7fffffff)
193:         val = 0 - ((val - 1) ^ 0xffffffff)
194:       end
195:       val
196:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 198
198:     def read_i64
199:       trans.read_into_buffer(@rbuf, 8)
200:       hi, lo = @rbuf.unpack('N2')
201:       if (hi > 0x7fffffff)
202:         hi ^= 0xffffffff
203:         lo ^= 0xffffffff
204:         0 - (hi << 32) - lo - 1
205:       else
206:         (hi << 32) + lo
207:       end
208:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 198
198:     def read_i64
199:       trans.read_into_buffer(@rbuf, 8)
200:       hi, lo = @rbuf.unpack('N2')
201:       if (hi > 0x7fffffff)
202:         hi ^= 0xffffffff
203:         lo ^= 0xffffffff
204:         0 - (hi << 32) - lo - 1
205:       else
206:         (hi << 32) + lo
207:       end
208:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 155
155:     def read_list_begin
156:       etype = read_byte
157:       size = read_i32
158:       [etype, size]
159:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 155
155:     def read_list_begin
156:       etype = read_byte
157:       size = read_i32
158:       [etype, size]
159:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 148
148:     def read_map_begin
149:       ktype = read_byte
150:       vtype = read_byte
151:       size = read_i32
152:       [ktype, vtype, size]
153:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 148
148:     def read_map_begin
149:       ktype = read_byte
150:       vtype = read_byte
151:       size = read_i32
152:       [ktype, vtype, size]
153:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 115
115:     def read_message_begin
116:       version = read_i32
117:       if version < 0
118:         if (version & VERSION_MASK != VERSION_1)
119:           raise ProtocolException.new(ProtocolException::BAD_VERSION, 'Missing version identifier')
120:         end
121:         type = version & TYPE_MASK
122:         name = read_string
123:         seqid = read_i32
124:         [name, type, seqid]
125:       else
126:         if strict_read
127:           raise ProtocolException.new(ProtocolException::BAD_VERSION, 'No version identifier, old protocol client?')
128:         end
129:         name = trans.read_all(version)
130:         type = read_byte
131:         seqid = read_i32
132:         [name, type, seqid]
133:       end
134:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 115
115:     def read_message_begin
116:       version = read_i32
117:       if version < 0
118:         if (version & VERSION_MASK != VERSION_1)
119:           raise ProtocolException.new(ProtocolException::BAD_VERSION, 'Missing version identifier')
120:         end
121:         type = version & TYPE_MASK
122:         name = read_string
123:         seqid = read_i32
124:         [name, type, seqid]
125:       else
126:         if strict_read
127:           raise ProtocolException.new(ProtocolException::BAD_VERSION, 'No version identifier, old protocol client?')
128:         end
129:         name = trans.read_all(version)
130:         type = read_byte
131:         seqid = read_i32
132:         [name, type, seqid]
133:       end
134:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 161
161:     def read_set_begin
162:       etype = read_byte
163:       size = read_i32
164:       [etype, size]
165:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 161
161:     def read_set_begin
162:       etype = read_byte
163:       size = read_i32
164:       [etype, size]
165:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 216
216:     def read_string
217:       sz = read_i32
218:       dat = trans.read_all(sz)
219:       dat
220:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 216
216:     def read_string
217:       sz = read_i32
218:       dat = trans.read_all(sz)
219:       dat
220:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 136
136:     def read_struct_begin; nil; end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 136
136:     def read_struct_begin; nil; end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 81
81:     def write_bool(bool)
82:       write_byte(bool ? 1 : 0)
83:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 81
81:     def write_bool(bool)
82:       write_byte(bool ? 1 : 0)
83:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 85
85:     def write_byte(byte)
86:       raise RangeError if byte < -2**31 || byte >= 2**32
87:       trans.write([byte].pack('c'))
88:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 85
85:     def write_byte(byte)
86:       raise RangeError if byte < -2**31 || byte >= 2**32
87:       trans.write([byte].pack('c'))
88:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 106
106:     def write_double(dub)
107:       trans.write([dub].pack('G'))
108:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 106
106:     def write_double(dub)
107:       trans.write([dub].pack('G'))
108:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 56
56:     def write_field_begin(name, type, id)
57:       write_byte(type)
58:       write_i16(id)
59:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 56
56:     def write_field_begin(name, type, id)
57:       write_byte(type)
58:       write_i16(id)
59:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 61
61:     def write_field_stop
62:       write_byte(Thrift::Types::STOP)
63:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 61
61:     def write_field_stop
62:       write_byte(Thrift::Types::STOP)
63:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 90
90:     def write_i16(i16)
91:       trans.write([i16].pack('n'))
92:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 90
90:     def write_i16(i16)
91:       trans.write([i16].pack('n'))
92:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 94
94:     def write_i32(i32)
95:       raise RangeError if i32 < -2**31 || i32 >= 2**31
96:       trans.write([i32].pack('N'))
97:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 94
94:     def write_i32(i32)
95:       raise RangeError if i32 < -2**31 || i32 >= 2**31
96:       trans.write([i32].pack('N'))
97:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 99
 99:     def write_i64(i64)
100:       raise RangeError if i64 < -2**63 || i64 >= 2**64
101:       hi = i64 >> 32
102:       lo = i64 & 0xffffffff
103:       trans.write([hi, lo].pack('N2'))
104:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 99
 99:     def write_i64(i64)
100:       raise RangeError if i64 < -2**63 || i64 >= 2**64
101:       hi = i64 >> 32
102:       lo = i64 & 0xffffffff
103:       trans.write([hi, lo].pack('N2'))
104:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 71
71:     def write_list_begin(etype, size)
72:       write_byte(etype)
73:       write_i32(size)
74:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 71
71:     def write_list_begin(etype, size)
72:       write_byte(etype)
73:       write_i32(size)
74:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 65
65:     def write_map_begin(ktype, vtype, size)
66:       write_byte(ktype)
67:       write_byte(vtype)
68:       write_i32(size)
69:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 65
65:     def write_map_begin(ktype, vtype, size)
66:       write_byte(ktype)
67:       write_byte(vtype)
68:       write_i32(size)
69:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 39
39:     def write_message_begin(name, type, seqid)
40:       # this is necessary because we added (needed) bounds checking to 
41:       # write_i32, and 0x80010000 is too big for that.
42:       if strict_write
43:         write_i16(VERSION_1 >> 16)
44:         write_i16(type)
45:         write_string(name)
46:         write_i32(seqid)
47:       else
48:         write_string(name)
49:         write_byte(type)
50:         write_i32(seqid)
51:       end
52:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 39
39:     def write_message_begin(name, type, seqid)
40:       # this is necessary because we added (needed) bounds checking to 
41:       # write_i32, and 0x80010000 is too big for that.
42:       if strict_write
43:         write_i16(VERSION_1 >> 16)
44:         write_i16(type)
45:         write_string(name)
46:         write_i32(seqid)
47:       else
48:         write_string(name)
49:         write_byte(type)
50:         write_i32(seqid)
51:       end
52:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 76
76:     def write_set_begin(etype, size)
77:       write_byte(etype)
78:       write_i32(size)
79:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 76
76:     def write_set_begin(etype, size)
77:       write_byte(etype)
78:       write_i32(size)
79:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 110
110:     def write_string(str)
111:       write_i32(str.length)
112:       trans.write(str)
113:     end

[Source]

     # File lib/thrift/protocol/binary_protocol.rb, line 110
110:     def write_string(str)
111:       write_i32(str.length)
112:       trans.write(str)
113:     end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 54
54:     def write_struct_begin(name); nil; end

[Source]

    # File lib/thrift/protocol/binary_protocol.rb, line 54
54:     def write_struct_begin(name); nil; end

[Validate]