Class: Thrift::HeaderProtocol
Overview
HeaderProtocol is a protocol that wraps HeaderTransport and delegates
to either BinaryProtocol or CompactProtocol based on auto-detection.
It provides access to header management (get_headers, set_header, etc.)
through the underlying HeaderTransport.
Example usage:
socket = Thrift::Socket.new('localhost', 9090)
protocol = Thrift::HeaderProtocol.new(socket)
client = MyService::Client.new(protocol)
protocol.trans.open
client.some_method()
protocol.trans.close
Instance Method Summary
collapse
-
#add_transform(transform_id) ⇒ Object
Adds a transform (e.g., ZLIB compression).
-
#clear_headers ⇒ Object
Clears all write headers.
-
#get_headers ⇒ Object
Returns headers read from the last message.
-
#initialize(transport, allowed_client_types = nil, default_protocol = HeaderSubprotocolID::COMPACT) ⇒ HeaderProtocol
constructor
Creates a new HeaderProtocol.
-
#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_list_begin ⇒ Object
-
#read_list_end ⇒ Object
-
#read_map_begin ⇒ Object
-
#read_map_end ⇒ Object
-
#read_message_begin ⇒ Object
Read methods - delegate to underlying protocol read_message_begin handles protocol switching after detection.
-
#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
-
#set_header(key, value) ⇒ Object
Sets a header to be sent with the next message.
-
#to_s ⇒ Object
-
#trans ⇒ Object
Returns the HeaderTransport.
-
#write_binary(buf) ⇒ 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_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 methods - delegate to underlying protocol.
-
#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
#native?, #read_type, #skip, #validate_container_size, #write_field, #write_type
Constructor Details
#initialize(transport, allowed_client_types = nil, default_protocol = HeaderSubprotocolID::COMPACT) ⇒ HeaderProtocol
Creates a new HeaderProtocol.
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/thrift/protocol/header_protocol.rb', line 44
def initialize(transport, allowed_client_types = nil, default_protocol = HeaderSubprotocolID::COMPACT)
if transport.is_a?(HeaderTransport)
@header_transport = transport
else
@header_transport = HeaderTransport.new(transport, allowed_client_types, default_protocol)
end
@default_protocol = default_protocol
@current_protocol_id = default_protocol
@protocol = create_protocol(@current_protocol_id)
end
|
Instance Method Details
Adds a transform (e.g., ZLIB compression)
80
81
82
|
# File 'lib/thrift/protocol/header_protocol.rb', line 80
def add_transform(transform_id)
@header_transport.add_transform(transform_id)
end
|
75
76
77
|
# File 'lib/thrift/protocol/header_protocol.rb', line 75
def
@header_transport.
end
|
Returns headers read from the last message
65
66
67
|
# File 'lib/thrift/protocol/header_protocol.rb', line 65
def
@header_transport.
end
|
#read_binary ⇒ Object
263
264
265
|
# File 'lib/thrift/protocol/header_protocol.rb', line 263
def read_binary
@protocol.read_binary
end
|
#read_bool ⇒ Object
235
236
237
|
# File 'lib/thrift/protocol/header_protocol.rb', line 235
def read_bool
@protocol.read_bool
end
|
#read_byte ⇒ Object
239
240
241
|
# File 'lib/thrift/protocol/header_protocol.rb', line 239
def read_byte
@protocol.read_byte
end
|
#read_double ⇒ Object
255
256
257
|
# File 'lib/thrift/protocol/header_protocol.rb', line 255
def read_double
@protocol.read_double
end
|
#read_field_begin ⇒ Object
203
204
205
|
# File 'lib/thrift/protocol/header_protocol.rb', line 203
def read_field_begin
@protocol.read_field_begin
end
|
#read_field_end ⇒ Object
207
208
209
|
# File 'lib/thrift/protocol/header_protocol.rb', line 207
def read_field_end
@protocol.read_field_end
end
|
#read_i16 ⇒ Object
243
244
245
|
# File 'lib/thrift/protocol/header_protocol.rb', line 243
def read_i16
@protocol.read_i16
end
|
#read_i32 ⇒ Object
247
248
249
|
# File 'lib/thrift/protocol/header_protocol.rb', line 247
def read_i32
@protocol.read_i32
end
|
#read_i64 ⇒ Object
251
252
253
|
# File 'lib/thrift/protocol/header_protocol.rb', line 251
def read_i64
@protocol.read_i64
end
|
#read_list_begin ⇒ Object
219
220
221
|
# File 'lib/thrift/protocol/header_protocol.rb', line 219
def read_list_begin
@protocol.read_list_begin
end
|
#read_list_end ⇒ Object
223
224
225
|
# File 'lib/thrift/protocol/header_protocol.rb', line 223
def read_list_end
@protocol.read_list_end
end
|
#read_map_begin ⇒ Object
211
212
213
|
# File 'lib/thrift/protocol/header_protocol.rb', line 211
def read_map_begin
@protocol.read_map_begin
end
|
#read_map_end ⇒ Object
215
216
217
|
# File 'lib/thrift/protocol/header_protocol.rb', line 215
def read_map_end
@protocol.read_map_end
end
|
#read_message_begin ⇒ Object
Read methods - delegate to underlying protocol
read_message_begin handles protocol switching after detection
#read_message_end ⇒ Object
191
192
193
|
# File 'lib/thrift/protocol/header_protocol.rb', line 191
def read_message_end
@protocol.read_message_end
end
|
#read_set_begin ⇒ Object
227
228
229
|
# File 'lib/thrift/protocol/header_protocol.rb', line 227
def read_set_begin
@protocol.read_set_begin
end
|
#read_set_end ⇒ Object
231
232
233
|
# File 'lib/thrift/protocol/header_protocol.rb', line 231
def read_set_end
@protocol.read_set_end
end
|
#read_string ⇒ Object
259
260
261
|
# File 'lib/thrift/protocol/header_protocol.rb', line 259
def read_string
@protocol.read_string
end
|
#read_struct_begin ⇒ Object
195
196
197
|
# File 'lib/thrift/protocol/header_protocol.rb', line 195
def read_struct_begin
@protocol.read_struct_begin
end
|
#read_struct_end ⇒ Object
199
200
201
|
# File 'lib/thrift/protocol/header_protocol.rb', line 199
def read_struct_end
@protocol.read_struct_end
end
|
#read_uuid ⇒ Object
267
268
269
|
# File 'lib/thrift/protocol/header_protocol.rb', line 267
def read_uuid
@protocol.read_uuid
end
|
Sets a header to be sent with the next message
70
71
72
|
# File 'lib/thrift/protocol/header_protocol.rb', line 70
def (key, value)
@header_transport.(key, value)
end
|
#to_s ⇒ Object
271
272
273
|
# File 'lib/thrift/protocol/header_protocol.rb', line 271
def to_s
"header(#{@protocol.to_s})"
end
|
#trans ⇒ Object
Returns the HeaderTransport
60
61
62
|
# File 'lib/thrift/protocol/header_protocol.rb', line 60
def trans
@header_transport
end
|
#write_binary(buf) ⇒ Object
166
167
168
|
# File 'lib/thrift/protocol/header_protocol.rb', line 166
def write_binary(buf)
@protocol.write_binary(buf)
end
|
#write_bool(bool) ⇒ Object
138
139
140
|
# File 'lib/thrift/protocol/header_protocol.rb', line 138
def write_bool(bool)
@protocol.write_bool(bool)
end
|
#write_byte(byte) ⇒ Object
142
143
144
|
# File 'lib/thrift/protocol/header_protocol.rb', line 142
def write_byte(byte)
@protocol.write_byte(byte)
end
|
#write_double(dub) ⇒ Object
158
159
160
|
# File 'lib/thrift/protocol/header_protocol.rb', line 158
def write_double(dub)
@protocol.write_double(dub)
end
|
#write_field_begin(name, type, id) ⇒ Object
102
103
104
|
# File 'lib/thrift/protocol/header_protocol.rb', line 102
def write_field_begin(name, type, id)
@protocol.write_field_begin(name, type, id)
end
|
#write_field_end ⇒ Object
106
107
108
|
# File 'lib/thrift/protocol/header_protocol.rb', line 106
def write_field_end
@protocol.write_field_end
end
|
#write_field_stop ⇒ Object
110
111
112
|
# File 'lib/thrift/protocol/header_protocol.rb', line 110
def write_field_stop
@protocol.write_field_stop
end
|
#write_i16(i16) ⇒ Object
146
147
148
|
# File 'lib/thrift/protocol/header_protocol.rb', line 146
def write_i16(i16)
@protocol.write_i16(i16)
end
|
#write_i32(i32) ⇒ Object
150
151
152
|
# File 'lib/thrift/protocol/header_protocol.rb', line 150
def write_i32(i32)
@protocol.write_i32(i32)
end
|
#write_i64(i64) ⇒ Object
154
155
156
|
# File 'lib/thrift/protocol/header_protocol.rb', line 154
def write_i64(i64)
@protocol.write_i64(i64)
end
|
#write_list_begin(etype, size) ⇒ Object
122
123
124
|
# File 'lib/thrift/protocol/header_protocol.rb', line 122
def write_list_begin(etype, size)
@protocol.write_list_begin(etype, size)
end
|
#write_list_end ⇒ Object
126
127
128
|
# File 'lib/thrift/protocol/header_protocol.rb', line 126
def write_list_end
@protocol.write_list_end
end
|
#write_map_begin(ktype, vtype, size) ⇒ Object
114
115
116
|
# File 'lib/thrift/protocol/header_protocol.rb', line 114
def write_map_begin(ktype, vtype, size)
@protocol.write_map_begin(ktype, vtype, size)
end
|
#write_map_end ⇒ Object
118
119
120
|
# File 'lib/thrift/protocol/header_protocol.rb', line 118
def write_map_end
@protocol.write_map_end
end
|
#write_message_begin(name, type, seqid) ⇒ Object
Write methods - delegate to underlying protocol
85
86
87
88
|
# File 'lib/thrift/protocol/header_protocol.rb', line 85
def write_message_begin(name, type, seqid)
@header_transport.sequence_id = seqid
@protocol.write_message_begin(name, type, seqid)
end
|
#write_message_end ⇒ Object
90
91
92
|
# File 'lib/thrift/protocol/header_protocol.rb', line 90
def write_message_end
@protocol.write_message_end
end
|
#write_set_begin(etype, size) ⇒ Object
130
131
132
|
# File 'lib/thrift/protocol/header_protocol.rb', line 130
def write_set_begin(etype, size)
@protocol.write_set_begin(etype, size)
end
|
#write_set_end ⇒ Object
134
135
136
|
# File 'lib/thrift/protocol/header_protocol.rb', line 134
def write_set_end
@protocol.write_set_end
end
|
#write_string(str) ⇒ Object
162
163
164
|
# File 'lib/thrift/protocol/header_protocol.rb', line 162
def write_string(str)
@protocol.write_string(str)
end
|
#write_struct_begin(name) ⇒ Object
94
95
96
|
# File 'lib/thrift/protocol/header_protocol.rb', line 94
def write_struct_begin(name)
@protocol.write_struct_begin(name)
end
|
#write_struct_end ⇒ Object
98
99
100
|
# File 'lib/thrift/protocol/header_protocol.rb', line 98
def write_struct_end
@protocol.write_struct_end
end
|
#write_uuid(uuid) ⇒ Object
170
171
172
|
# File 'lib/thrift/protocol/header_protocol.rb', line 170
def write_uuid(uuid)
@protocol.write_uuid(uuid)
end
|