thrift-serializer

Serialize thrift models into bytes

License

License

GroupId

GroupId

com.gu
ArtifactId

ArtifactId

thrift-serializer_2.13
Last Version

Last Version

4.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

thrift-serializer
Serialize thrift models into bytes
Project URL

Project URL

https://github.com/guardian/thrift-serializer
Project Organization

Project Organization

com.gu
Source Code Management

Source Code Management

https://github.com/guardian/thrift-serializer

Download thrift-serializer_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/com.gu/thrift-serializer_2.13/ -->
<dependency>
    <groupId>com.gu</groupId>
    <artifactId>thrift-serializer_2.13</artifactId>
    <version>4.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.gu/thrift-serializer_2.13/
implementation 'com.gu:thrift-serializer_2.13:4.0.3'
// https://jarcasting.com/artifacts/com.gu/thrift-serializer_2.13/
implementation ("com.gu:thrift-serializer_2.13:4.0.3")
'com.gu:thrift-serializer_2.13:jar:4.0.3'
<dependency org="com.gu" name="thrift-serializer_2.13" rev="4.0.3">
  <artifact name="thrift-serializer_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.gu', module='thrift-serializer_2.13', version='4.0.3')
)
libraryDependencies += "com.gu" % "thrift-serializer_2.13" % "4.0.3"
[com.gu/thrift-serializer_2.13 "4.0.3"]

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.1
com.twitter : scrooge-core_2.13 jar 19.9.0
org.apache.thrift : libthrift jar 0.12.0
com.github.luben : zstd-jni jar 1.3.5-2

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.13 jar 3.0.8

Project Modules

There are no modules declared in this project.

Thrift Serializer

  • 2.11: Maven Central
  • 2.12: Maven Central

A library for serializing a thrift model into bytes.

How to use

  • Add the library as a depency by adding
"com.gu" %% "thrift-serializer" % "2.1.1"

to your applications libraryDepencies.

  • You can then use ThriftSerializer in your application:
import com.gu.thrift.serializer.ThriftSerializer

object myObject extends ThriftSerializer {

  def myMethod(thriftObject: MyThriftObject): Unit = {
    val bytes = serializeToBytes(thriftObject)
    //Do something with bytes
  }
}
  • You can use the ThriftDeserializer like this:

MyDeserializer.deserialize(buffer).map(myEvent => {
  // process the event
}

def myMethod(thriftObject: MyThriftObject): Unit = {
  val bytes = serializeToBytes(thriftObject)
  //Do something with bytes
}

If there is no compression type recorded in the bytes you wish to deserialize or if you don't want these to be included when serializing a thrift object, you can set the last arguments of the function calls to true. They are false by default.

MyDeserializer.deserialize(buffer, true).map(myEvent => {
    // process the event
}
def myMethod(thriftObject: MyThriftObject, true): Unit = {
  val bytes = serializeToBytes(thriftObject)
  //Do something with bytes
}

How to publish

  • The library is published to Maven Central. To publish, register to Sonatype and get added to Guardian projects.

  • Run sbt release. You will be asked about what version you want the release to be during the release process, you do not have to update it manually.

Node JS

  • Install using npm
npm install --save thrift-serializer

in your application or lambda you can decode messages

var Message = require('your-thrift-model');
var serializer = require('thrift-serializer');

serializer.read(Message, bytes, function (err, msg) {
	console.log(msg);
});

or encode them

var Message = require('your-thrift-model');
var serializer = require('thrift-serializer');

var message = new Message({
	someData: ''
});

serializer.write(message, serializer.Compression.Gzip, function (err, bytes) {
	// do something with your bytes, e.g. convert the buffer into a base64 string
	console.log(bytes.toString('base64'));
});
com.gu

The Guardian

The source code of the world's leading liberal voice

Versions

Version
4.0.3
4.0.2