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, #write_field, #write_type
Constructor Details
#initialize(transport, allowed_client_types = nil, default_protocol = HeaderSubprotocolID::COMPACT) ⇒ HeaderProtocol
Creates a new HeaderProtocol.
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/thrift/protocol/header_protocol.rb', line 43
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)
79
80
81
|
# File 'lib/thrift/protocol/header_protocol.rb', line 79
def add_transform(transform_id)
@header_transport.add_transform(transform_id)
end
|
74
75
76
|
# File 'lib/thrift/protocol/header_protocol.rb', line 74
def
@header_transport.
end
|
Returns headers read from the last message
64
65
66
|
# File 'lib/thrift/protocol/header_protocol.rb', line 64
def
@header_transport.
end
|
#read_binary ⇒ Object
262
263
264
|
# File 'lib/thrift/protocol/header_protocol.rb', line 262
def read_binary
@protocol.read_binary
end
|
#read_bool ⇒ Object
234
235
236
|
# File 'lib/thrift/protocol/header_protocol.rb', line 234
def read_bool
@protocol.read_bool
end
|
#read_byte ⇒ Object
238
239
240
|
# File 'lib/thrift/protocol/header_protocol.rb', line 238
def read_byte
@protocol.read_byte
end
|
#read_double ⇒ Object
254
255
256
|
# File 'lib/thrift/protocol/header_protocol.rb', line 254
def read_double
@protocol.read_double
end
|
#read_field_begin ⇒ Object
202
203
204
|
# File 'lib/thrift/protocol/header_protocol.rb', line 202
def read_field_begin
@protocol.read_field_begin
end
|
#read_field_end ⇒ Object
206
207
208
|
# File 'lib/thrift/protocol/header_protocol.rb', line 206
def read_field_end
@protocol.read_field_end
end
|
#read_i16 ⇒ Object
242
243
244
|
# File 'lib/thrift/protocol/header_protocol.rb', line 242
def read_i16
@protocol.read_i16
end
|
#read_i32 ⇒ Object
246
247
248
|
# File 'lib/thrift/protocol/header_protocol.rb', line 246
def read_i32
@protocol.read_i32
end
|
#read_i64 ⇒ Object
250
251
252
|
# File 'lib/thrift/protocol/header_protocol.rb', line 250
def read_i64
@protocol.read_i64
end
|
#read_list_begin ⇒ Object
218
219
220
|
# File 'lib/thrift/protocol/header_protocol.rb', line 218
def read_list_begin
@protocol.read_list_begin
end
|
#read_list_end ⇒ Object
222
223
224
|
# File 'lib/thrift/protocol/header_protocol.rb', line 222
def read_list_end
@protocol.read_list_end
end
|
#read_map_begin ⇒ Object
210
211
212
|
# File 'lib/thrift/protocol/header_protocol.rb', line 210
def read_map_begin
@protocol.read_map_begin
end
|
#read_map_end ⇒ Object
214
215
216
|
# File 'lib/thrift/protocol/header_protocol.rb', line 214
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
190
191
192
|
# File 'lib/thrift/protocol/header_protocol.rb', line 190
def read_message_end
@protocol.read_message_end
end
|
#read_set_begin ⇒ Object
226
227
228
|
# File 'lib/thrift/protocol/header_protocol.rb', line 226
def read_set_begin
@protocol.read_set_begin
end
|
#read_set_end ⇒ Object
230
231
232
|
# File 'lib/thrift/protocol/header_protocol.rb', line 230
def read_set_end
@protocol.read_set_end
end
|
#read_string ⇒ Object
258
259
260
|
# File 'lib/thrift/protocol/header_protocol.rb', line 258
def read_string
@protocol.read_string
end
|
#read_struct_begin ⇒ Object
194
195
196
|
# File 'lib/thrift/protocol/header_protocol.rb', line 194
def read_struct_begin
@protocol.read_struct_begin
end
|
#read_struct_end ⇒ Object
198
199
200
|
# File 'lib/thrift/protocol/header_protocol.rb', line 198
def read_struct_end
@protocol.read_struct_end
end
|
#read_uuid ⇒ Object
266
267
268
|
# File 'lib/thrift/protocol/header_protocol.rb', line 266
def read_uuid
@protocol.read_uuid
end
|
Sets a header to be sent with the next message
69
70
71
|
# File 'lib/thrift/protocol/header_protocol.rb', line 69
def (key, value)
@header_transport.(key, value)
end
|
#to_s ⇒ Object
270
271
272
|
# File 'lib/thrift/protocol/header_protocol.rb', line 270
def to_s
"header(#{@protocol.to_s})"
end
|
#trans ⇒ Object
Returns the HeaderTransport
59
60
61
|
# File 'lib/thrift/protocol/header_protocol.rb', line 59
def trans
@header_transport
end
|
#write_binary(buf) ⇒ Object
165
166
167
|
# File 'lib/thrift/protocol/header_protocol.rb', line 165
def write_binary(buf)
@protocol.write_binary(buf)
end
|
#write_bool(bool) ⇒ Object
137
138
139
|
# File 'lib/thrift/protocol/header_protocol.rb', line 137
def write_bool(bool)
@protocol.write_bool(bool)
end
|
#write_byte(byte) ⇒ Object
141
142
143
|
# File 'lib/thrift/protocol/header_protocol.rb', line 141
def write_byte(byte)
@protocol.write_byte(byte)
end
|
#write_double(dub) ⇒ Object
157
158
159
|
# File 'lib/thrift/protocol/header_protocol.rb', line 157
def write_double(dub)
@protocol.write_double(dub)
end
|
#write_field_begin(name, type, id) ⇒ Object
101
102
103
|
# File 'lib/thrift/protocol/header_protocol.rb', line 101
def write_field_begin(name, type, id)
@protocol.write_field_begin(name, type, id)
end
|
#write_field_end ⇒ Object
105
106
107
|
# File 'lib/thrift/protocol/header_protocol.rb', line 105
def write_field_end
@protocol.write_field_end
end
|
#write_field_stop ⇒ Object
109
110
111
|
# File 'lib/thrift/protocol/header_protocol.rb', line 109
def write_field_stop
@protocol.write_field_stop
end
|
#write_i16(i16) ⇒ Object
145
146
147
|
# File 'lib/thrift/protocol/header_protocol.rb', line 145
def write_i16(i16)
@protocol.write_i16(i16)
end
|
#write_i32(i32) ⇒ Object
149
150
151
|
# File 'lib/thrift/protocol/header_protocol.rb', line 149
def write_i32(i32)
@protocol.write_i32(i32)
end
|
#write_i64(i64) ⇒ Object
153
154
155
|
# File 'lib/thrift/protocol/header_protocol.rb', line 153
def write_i64(i64)
@protocol.write_i64(i64)
end
|
#write_list_begin(etype, size) ⇒ Object
121
122
123
|
# File 'lib/thrift/protocol/header_protocol.rb', line 121
def write_list_begin(etype, size)
@protocol.write_list_begin(etype, size)
end
|
#write_list_end ⇒ Object
125
126
127
|
# File 'lib/thrift/protocol/header_protocol.rb', line 125
def write_list_end
@protocol.write_list_end
end
|
#write_map_begin(ktype, vtype, size) ⇒ Object
113
114
115
|
# File 'lib/thrift/protocol/header_protocol.rb', line 113
def write_map_begin(ktype, vtype, size)
@protocol.write_map_begin(ktype, vtype, size)
end
|
#write_map_end ⇒ Object
117
118
119
|
# File 'lib/thrift/protocol/header_protocol.rb', line 117
def write_map_end
@protocol.write_map_end
end
|
#write_message_begin(name, type, seqid) ⇒ Object
Write methods - delegate to underlying protocol
84
85
86
87
|
# File 'lib/thrift/protocol/header_protocol.rb', line 84
def write_message_begin(name, type, seqid)
@header_transport.sequence_id = seqid
@protocol.write_message_begin(name, type, seqid)
end
|
#write_message_end ⇒ Object
89
90
91
|
# File 'lib/thrift/protocol/header_protocol.rb', line 89
def write_message_end
@protocol.write_message_end
end
|
#write_set_begin(etype, size) ⇒ Object
129
130
131
|
# File 'lib/thrift/protocol/header_protocol.rb', line 129
def write_set_begin(etype, size)
@protocol.write_set_begin(etype, size)
end
|
#write_set_end ⇒ Object
133
134
135
|
# File 'lib/thrift/protocol/header_protocol.rb', line 133
def write_set_end
@protocol.write_set_end
end
|
#write_string(str) ⇒ Object
161
162
163
|
# File 'lib/thrift/protocol/header_protocol.rb', line 161
def write_string(str)
@protocol.write_string(str)
end
|
#write_struct_begin(name) ⇒ Object
93
94
95
|
# File 'lib/thrift/protocol/header_protocol.rb', line 93
def write_struct_begin(name)
@protocol.write_struct_begin(name)
end
|
#write_struct_end ⇒ Object
97
98
99
|
# File 'lib/thrift/protocol/header_protocol.rb', line 97
def write_struct_end
@protocol.write_struct_end
end
|
#write_uuid(uuid) ⇒ Object
169
170
171
|
# File 'lib/thrift/protocol/header_protocol.rb', line 169
def write_uuid(uuid)
@protocol.write_uuid(uuid)
end
|