]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/lib/rb/lib/thrift/protocol/base_protocol.rb
2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
20 # this require is to make generated struct definitions happy
24 class ProtocolException
< Exception
36 def initialize(type
=UNKNOWN
, message
=nil)
51 puts
"wrong method is being called!"
55 def write_message_begin(name
, type
, seqid
)
56 raise NotImplementedError
59 def write_message_end
; nil; end
61 def write_struct_begin(name
)
62 raise NotImplementedError
65 def write_struct_end
; nil; end
67 def write_field_begin(name
, type
, id
)
68 raise NotImplementedError
71 def write_field_end
; nil; end
74 raise NotImplementedError
77 def write_map_begin(ktype
, vtype
, size
)
78 raise NotImplementedError
81 def write_map_end
; nil; end
83 def write_list_begin(etype
, size
)
84 raise NotImplementedError
87 def write_list_end
; nil; end
89 def write_set_begin(etype
, size
)
90 raise NotImplementedError
93 def write_set_end
; nil; end
96 raise NotImplementedError
100 raise NotImplementedError
104 raise NotImplementedError
108 raise NotImplementedError
112 raise NotImplementedError
115 def write_double(dub
)
116 raise NotImplementedError
119 # Writes a Thrift String. In Ruby 1.9+, the String passed will be transcoded to UTF-8.
121 # str - The String to write.
123 # Raises EncodingError if the transcoding to UTF-8 fails.
126 def write_string(str
)
127 raise NotImplementedError
130 # Writes a Thrift Binary (Thrift String with no encoding). In Ruby 1.9+, the String passed
131 # will forced into BINARY encoding.
133 # buf - The String to write.
136 def write_binary(buf
)
137 raise NotImplementedError
140 def read_message_begin
141 raise NotImplementedError
144 def read_message_end
; nil; end
146 def read_struct_begin
147 raise NotImplementedError
150 def read_struct_end
; nil; end
153 raise NotImplementedError
156 def read_field_end
; nil; end
159 raise NotImplementedError
162 def read_map_end
; nil; end
165 raise NotImplementedError
168 def read_list_end
; nil; end
171 raise NotImplementedError
174 def read_set_end
; nil; end
177 raise NotImplementedError
181 raise NotImplementedError
185 raise NotImplementedError
189 raise NotImplementedError
193 raise NotImplementedError
197 raise NotImplementedError
200 # Reads a Thrift String. In Ruby 1.9+, all Strings will be returned with an Encoding of UTF-8.
204 raise NotImplementedError
207 # Reads a Thrift Binary (Thrift String without encoding). In Ruby 1.9+, all Strings will be returned
208 # with an Encoding of BINARY.
212 raise NotImplementedError
215 # Writes a field based on the field information, field ID and value.
217 # field_info - A Hash containing the definition of the field:
218 # :name - The name of the field.
219 # :type - The type of the field, which must be a Thrift::Types constant.
220 # :binary - A Boolean flag that indicates if Thrift::Types::STRING is a binary string (string without encoding).
221 # fid - The ID of the field.
222 # value - The field's value to write; object type varies based on :type.
225 def write_field(*args
)
227 # handles the documented method signature - write_field(field_info, fid, value)
232 # handles the deprecated method signature - write_field(name, type, fid, value)
233 field_info
= {:name => args
[0], :type => args
[1]}
237 raise ArgumentError
, "wrong number of arguments (#{args.size} for 3)"
240 write_field_begin(field_info
[:name], field_info
[:type], fid
)
241 write_type(field_info
, value
)
245 # Writes a field value based on the field information.
247 # field_info - A Hash containing the definition of the field:
248 # :type - The Thrift::Types constant that determines how the value is written.
249 # :binary - A Boolean flag that indicates if Thrift::Types::STRING is a binary string (string without encoding).
250 # value - The field's value to write; object type varies based on field_info[:type].
253 def write_type(field_info
, value
)
254 # if field_info is a Fixnum, assume it is a Thrift::Types constant
255 # convert it into a field_info Hash for backwards compatibility
256 if field_info
.is_a
? Fixnum
257 field_info
= {:type => field_info
}
260 case field_info
[:type]
274 if field_info
[:binary]
282 raise NotImplementedError
286 # Reads a field value based on the field information.
288 # field_info - A Hash containing the pertinent data to write:
289 # :type - The Thrift::Types constant that determines how the value is written.
290 # :binary - A flag that indicates if Thrift::Types::STRING is a binary string (string without encoding).
292 # Returns the value read; object type varies based on field_info[:type].
293 def read_type(field_info
)
294 # if field_info is a Fixnum, assume it is a Thrift::Types constant
295 # convert it into a field_info Hash for backwards compatibility
296 if field_info
.is_a
? Fixnum
297 field_info
= {:type => field_info
}
300 case field_info
[:type]
314 if field_info
[:binary]
320 raise NotImplementedError
343 name
, type
, id
= read_field_begin
344 break if type
== Types
::STOP
350 ktype
, vtype
, size
= read_map_begin
357 etype
, size
= read_set_begin
363 etype
, size
= read_list_begin
369 raise ProtocolException
.new(ProtocolException
::INVALID_DATA, 'Invalid data')
378 class BaseProtocolFactory
379 def get_protocol(trans
)
380 raise NotImplementedError