Skip to content
A Thrift parser/generator
Scala Java HTML Thrift Objective-C Shell Other
Latest commit c918ede May 12, 2016 @isnotinvain isnotinvain committed with jenkins scrooge-*: Add `_codec` method to all ThriftStruct instances
Problem:
Given an instance of ThriftStruct in a generic context, for example
def helper[T <: ThriftStruct, U](struct: T): U = ...
There is no good way to get the ThriftStructCodec3
(serializer / deserializer) for "struct".
Some codebases currently solve this problem via reflection, which
is fragile, not type safe, and makes some assumptions about
the existance of certain companion objects.

Solution:
Add a trait (HasThriftStructCodec3) that all ThriftStructs
extend from with a method for getting the
ThriftStructCodec3 from an instance of ThriftStruct.

Result:

The following is now possible:

def helper[T <: ThriftStruct with HasThriftStructCodec3[T], U]
  (struct: T): U = {
  val codec: ThriftStructCodec3[T] = struct._codec
}

or, with some lack of type safety:

def helper[T <: ThriftStruct, U]: U = {
  (struct: T): U = {
  val codec: ThriftStructCodec3[T] =
    struct.asInstanceOf[HasThriftStructCodec3[T]]._codec
}

RB_ID=830944
Failed to load latest commit information.
.github Add PULL_REQUEST_TEMPLATEs Mar 10, 2016
bin finagle/finatra/scrooge/twitter-server: bin/travisci updates and fixes Apr 21, 2016
demos/scrooge-maven-demo Twitter OSS: Prepare libraries for next release Apr 27, 2016
doc/src/sphinx scrooge: Create servers using Thrift.server and clients using Thrift.… May 9, 2016
project scrooge: Fix sbt builds May 9, 2016
scrooge-benchmark source: fix more unused imports for scala 2.11.8 Mar 29, 2016
scrooge-core scrooge-*: Add `_codec` method to all ThriftStruct instances May 16, 2016
scrooge-generator-tests scrooge-*: Add `_codec` method to all ThriftStruct instances May 16, 2016
scrooge-generator scrooge-*: Add `_codec` method to all ThriftStruct instances May 16, 2016
scrooge-linter scrooge: cleanup various build warnings Dec 21, 2015
scrooge-maven-plugin Twitter OSS: Prepare libraries for next release Apr 27, 2016
scrooge-sbt-plugin scrooge-generator: experimental-java RIP Mar 10, 2016
scrooge-serializer scrooge: cleanup various build warnings Dec 21, 2015
.gitignore [split] scrooge: Cache mustache resources to improve generation perfo… Oct 7, 2014
.travis.yml Switch to Java 8 and Scala 2.11 May 9, 2016
CHANGES Switch to Java 8 and Scala 2.11 May 9, 2016
CONFIG.ini [split] improve SocialGraphUtil exception logging Sep 11, 2014
CONTRIBUTING.md Add PULL_REQUEST_TEMPLATEs Mar 10, 2016
GROUPS [split] improve SocialGraphUtil exception logging Sep 11, 2014
LICENSE [split] improve SocialGraphUtil exception logging Sep 11, 2014
OWNERS util, finagle, scrooge: Add ryano to More Owners Files Feb 4, 2016
README.md scrooge-docs: Modernize the scrooge README Mar 21, 2016
pushsite.bash [split] improve SocialGraphUtil exception logging Sep 11, 2014
sbt Switch to Java 8 and Scala 2.11 May 9, 2016

README.md

Scrooge

Build status Coverage status Project status Gitter Maven Central

Scrooge is a thrift code generator written in Scala, which currently generates code for Scala and Java.

It's meant to be a replacement for the apache thrift code generator, and generates conforming, compatible binary codecs by building on top of libthrift. It integrates with the finagle project, exporting stats and finagle APIs, and makes it easy to build high throughput, low latency, robust thrift servers and clients.

Part of the motivation behind scrooge's scala implementation is that since Scala is API-compatible with Java, you can use the apache thrift code generator to generate Java files and use them from within Scala, but the generated code uses Java collections and mutable "bean" classes, causing some annoying boilerplate conversions to be hand-written. Scrooge bypasses the problem by generating Scala code directly. It also uses Scala syntax so the generated code is much more compact.

There is a comprehensive set of unit tests, which generate code, compile it, and execute it to verify expectations, as well as gold files to make it easy to review the effects of changes to the generator.

Status

This project is used in production at Twitter (and many other organizations), and is actively developed and maintained.

Building the develop branch locally

You will need the develop branch of util.

Finagle depends on scrooge-core, so the order in which you build dependencies should be:

  • in util: ./sbt publishLocal
  • in scrooge: ./sbt publishLocal
  • in finagle: ./sbt publishLocal

You will need the develop branch of finagle to run tests in scrooge-generator-tests, but you do not need it to build scrooge otherwise.

Full Documentation

https://twitter.github.io/scrooge/

Something went wrong with that request. Please try again.