package

github.com/kylepellham/thrift_cr

main / published Jul 12, 2024 / repository

thrift library for crystal

thrift_cr

thrift_cr is library to be used in conjunction with apache thrift in order to use apache thrift generated crystal code

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      thrift:
        github: kylepellham/thrift_cr
  2. Run shards install

Usage

require "thrift"

All library definitions exist in the namespace Thrift. Through Thrift you can initialize a server with a transport:

  • Thrift::Transport::ServerSocketTransport

and a protocol factory:

  • Thrift::Protocol::BinaryProtocolFactory
  • Thrift::Protocol::JsonProtocolFactory

you can mix any factory with any server transport. When you use this library you are expected to use the thrift generation this is how you get a server processor for a service. When you get processor you can create one of the following servers:

  • Thrift::Server::SimpleServer

this is an example of creating and running a server:

server_transport = Thrift::Transport::Socket.new("localhost", 9090)
trans_factory = Thrift::Transport::SocketTransportFactory.new
prot_factory = Thrift::Protocol::BinaryProtocolFactory.new

# this would be generated from a thrift idl file
handler = MyHandler.new
processor = MyService::Processor(MyHandler).new(handler)

server = Thrift::Server::SimpleServer.new(processor, server_transport, trans_factory, prot_factory)

Contributing

  1. Fork it (https://github.com/kylepellham/thrift_cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

API

  • Array(T)

    An Array is an ordered, integer-indexed collection of objects of type T.

  • Bool

    Bool has only two possible values: true and false.

  • Char

    reopen char and add #to_slice method to simply json writing

  • Enum

    Enum is the base type of all enums.

  • Float64
  • Hash(K, V)

    A Hash represents a collection of key-value mappings, similar to a dictionary.

  • Int16
  • Int32
  • Int64
  • Int8
  • Nil

    The Nil type has only one possible value: nil.

  • Set(T)

    Set implements a collection of values with no duplicates.

  • Slice(T)

    Bytes is aliased as Slice(UInt8) so we throw on any slice that isn't bytes

  • String

    A String represents an immutable sequence of UTF-8 characters.

  • Thrift
  • UUID

    Represents a UUID (Universally Unique IDentifier).