Module: Thrift

Defined in:
lib/thrift/bytes.rb,
lib/thrift/types.rb,
lib/thrift/union.rb,
lib/thrift/client.rb,
lib/thrift/struct.rb,
lib/thrift/metrics.rb,
lib/thrift/processor.rb,
lib/thrift/definition.rb,
lib/thrift/exceptions.rb,
lib/thrift/middleware.rb,
lib/thrift/struct_union.rb,
lib/thrift/transport/socket.rb,
lib/thrift/types/value/value.rb,
lib/thrift/server/base_server.rb,
lib/thrift/types/known/any/any.rb,
lib/thrift/server/simple_server.rb,
lib/thrift/multiplexed_processor.rb,
lib/thrift/serializer/serializer.rb,
lib/thrift/transport/unix_socket.rb,
lib/thrift/protocol/base_protocol.rb,
lib/thrift/protocol/json_protocol.rb,
lib/thrift/server/threaded_server.rb,
lib/thrift/serializer/deserializer.rb,
lib/thrift/server/rack_application.rb,
lib/thrift/server/thin_http_server.rb,
lib/thrift/transport/server_socket.rb,
lib/thrift/types/value/value_types.rb,
lib/thrift/protocol/binary_protocol.rb,
lib/thrift/transport/base_transport.rb,
lib/thrift/protocol/compact_protocol.rb,
lib/thrift/server/nonblocking_server.rb,
lib/thrift/server/thread_pool_server.rb,
lib/thrift/types/known/any/any_types.rb,
lib/thrift/server/mongrel_http_server.rb,
lib/thrift/transport/framed_transport.rb,
lib/thrift/protocol/protocol_decorator.rb,
lib/thrift/types/value/value_constants.rb,
lib/thrift/transport/buffered_transport.rb,
lib/thrift/transport/unix_server_socket.rb,
lib/thrift/protocol/multiplexed_protocol.rb,
lib/thrift/transport/io_stream_transport.rb,
lib/thrift/types/known/any/any_constants.rb,
lib/thrift/types/known/duration/duration.rb,
lib/thrift/types/annotation/naming/naming.rb,
lib/thrift/transport/base_server_transport.rb,
lib/thrift/transport/http_client_transport.rb,
lib/thrift/types/known/timestamp/timestamp.rb,
lib/thrift/transport/memory_buffer_transport.rb,
lib/thrift/types/known/duration/duration_types.rb,
lib/thrift/protocol/binary_protocol_accelerated.rb,
lib/thrift/types/annotation/naming/naming_types.rb,
lib/thrift/types/known/timestamp/timestamp_types.rb,
lib/thrift/types/known/duration/duration_constants.rb,
lib/thrift/types/annotation/naming/naming_constants.rb,
lib/thrift/types/known/timestamp/timestamp_constants.rb,
lib/thrift/types/annotation/deprecation/deprecation_types.rb,
lib/thrift/types/annotation/deprecation/deprecation_constants.rb

Overview

The only change required for a transport to support BinaryProtocolAccelerated is to implement 2 methods:

* borrow(size), which takes an optional argument and returns atleast _size_ bytes from the transport, 
                or the default buffer size if no argument is given
* consume!(size), which removes size bytes from the front of the buffer

See MemoryBuffer and BufferedTransport for examples.

Defined Under Namespace

Modules: Bytes, Client, MessageTypes, Metrics, Middleware, Processor, ProtocolDecorator, Struct, Struct_Union, TransportUtils, Types Classes: ApplicationException, BaseClient, BaseProtocol, BaseProtocolFactory, BaseServer, BaseServerTransport, BaseTransport, BaseTransportFactory, BinaryProtocol, BinaryProtocolAcceleratedFactory, BinaryProtocolFactory, BufferedTransport, BufferedTransportFactory, CompactProtocol, CompactProtocolFactory, DefaultCanonicalNameExtractor, Deserializer, Exception, FramedTransport, FramedTransportFactory, HTTPClientTransport, IOStreamTransport, JSONContext, JSONListContext, JSONPairContext, JsonProtocol, JsonProtocolFactory, LookaheadReader, MemoryBufferTransport, MongrelHTTPServer, MultiplexedProcessor, MultiplexedProtocol, NonblockingServer, ProtocolException, RackApplication, Serializer, ServerSocket, ServiceDefinition, SimpleJsonProtocol, SimpleJsonProtocolFactory, SimpleServer, Socket, StoredMessageProtocol, StructDefinition, ThinHTTPServer, ThreadPoolServer, ThreadedServer, TransportException, TypeError, UNIXServerSocket, UNIXSocket, Union

Constant Summary collapse

STRUCT_DEFINITIONS =
{}
SERVICE_DEFINITIONS =
{}
CANONICAL_NAME_EXTRACTORS =
[DefaultCanonicalNameExtractor]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.type_checkingObject

Returns the value of attribute type_checking.



40
41
42
# File 'lib/thrift/types.rb', line 40

def type_checking
  @type_checking
end

Class Method Details

.build_client(input) ⇒ Object



113
114
115
116
117
# File 'lib/thrift/client.rb', line 113

def build_client(input)
  return BaseClient.new(input) if input.is_a? BaseProtocol

  input
end

.check_type(value, field, name, skip_nil = true) ⇒ Object

Raises:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/thrift/types.rb', line 46

def self.check_type(value, field, name, skip_nil=true)
  return if value.nil? and skip_nil
  klasses = case field[:type]
            when Types::VOID
              NilClass
            when Types::BOOL
              [TrueClass, FalseClass]
            when Types::BYTE, Types::I16, Types::I32, Types::I64
              Integer
            when Types::DOUBLE
              Float
            when Types::STRING
              String
            when Types::STRUCT
              [Struct, Union]
            when Types::MAP
              Hash
            when Types::SET
              Set
            when Types::LIST
              Array
            end
  valid = klasses && [*klasses].any? { |klass| klass === value }
  raise TypeError, "Expected #{type_name(field[:type])}, received #{value.class} for field #{name}" unless valid
  # check elements now
  case field[:type]
  when Types::MAP
    value.each_pair do |k,v|
      check_type(k, field[:key], "#{name}.key", false)
      check_type(v, field[:value], "#{name}.value", false)
    end
  when Types::SET, Types::LIST
    value.each do |el|
      check_type(el, field[:element], "#{name}.element", false)
    end
  when Types::STRUCT
    raise TypeError, "Expected #{field[:class]}, received #{value.class} for field #{name}" unless field[:class] == value.class
  end
end

.register_canonical_name_extractor(klass) ⇒ Object



85
86
87
# File 'lib/thrift/definition.rb', line 85

def register_canonical_name_extractor(klass)
  CANONICAL_NAME_EXTRACTORS << klass
end

.register_service_type(klass) ⇒ Object



80
81
82
83
# File 'lib/thrift/definition.rb', line 80

def register_service_type(klass)
  definition = ServiceDefinition.new(klass)
  SERVICE_DEFINITIONS[definition.service_type] = definition
end

.register_struct_type(klass) ⇒ Object



75
76
77
78
# File 'lib/thrift/definition.rb', line 75

def register_struct_type(klass)
  definition = StructDefinition.new(klass)
  STRUCT_DEFINITIONS[definition.struct_type] = definition
end

.type_name(type) ⇒ Object



86
87
88
89
90
91
# File 'lib/thrift/types.rb', line 86

def self.type_name(type)
  Types.constants.each do |const|
    return "Types::#{const}" if Types.const_get(const) == type
  end
  nil
end