class Thrift::Types::Known::Any::Any
Constants
- FIELDS
- NAME
- NAMESPACE
- THRIFT_FIELD_INDEX_TYPE
- THRIFT_FIELD_INDEX_VALUE
Public Class Methods
from_object(obj, codec_key = '')
click to toggle source
# File lib/thrift/types/known/any.rb 132 def from_object(obj, codec_key = '') 133 struct_def = Thrift::STRUCT_DEFINITIONS.values.find do |v| 134 obj.is_a? v.klass 135 end 136 137 raise TypeNotHandled unless struct_def 138 raise CodecNotHandled unless CODECS[codec_key] 139 140 key = codec_key.eql?('') ? '' : "-#{codec_key}" 141 142 Any.new( 143 type: "thrift#{key}/#{struct_def.struct_type}", 144 value: CODECS[codec_key].encode(obj) 145 ) 146 end
Public Instance Methods
struct_fields()
click to toggle source
# File lib/thrift/types/known/any_types.rb 29 def struct_fields; FIELDS; end
to_object()
click to toggle source
# File lib/thrift/types/known/any.rb 149 def to_object 150 codec_key, struct_type = parse_type 151 152 raise TypeNotHandled unless Thrift::STRUCT_DEFINITIONS[struct_type] 153 raise CodecNotHandled unless CODECS[codec_key] 154 155 res = Thrift::STRUCT_DEFINITIONS[struct_type].klass.new 156 CODECS[codec_key].decode(value, res) 157 158 res 159 end
validate()
click to toggle source
# File lib/thrift/types/known/any_types.rb 31 def validate 32 raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field type is unset!') unless @type 33 raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Required field value is unset!') unless @value 34 end
Private Instance Methods
parse_type()
click to toggle source
# File lib/thrift/types/known/any.rb 163 def parse_type 164 ts = type.split('/') 165 166 if ts.length != 2 || (ts[0] =~ /^thrift-?/) != 0 167 raise TypeNotHandled.new 168 end 169 170 codec = ts[0][6..-1] 171 codec = codec[1..-1] if codec[0].eql?('-') 172 173 [codec, ts[1]] 174 end