Value converters - SolalPirelli/ThriftSharp GitHub Wiki

Thrift doesn't have many primitive types, which means some types of data have to be transmitted in less-than-ideal ways. However, it doesn't have to stay that way after transmission.

Enter value converters. They allow you to implement a converter from a Thrift type to another type.

These converters can be applied to struct fields, method return types, method parameters and method exceptions using the Converter named parameter like so:

// inside a class
[ThriftField( 1, true, "date", Converter = typeof( ThriftUnixDateConverter )]
public DateTime Date { get; set; }

Available converters

Converter name From type To type Description
ThriftUnixDateConverter i32 DateTime 32-bit Unix timestamp
ThriftUnixDate64Converter i64 DateTime 64-bit Unix timestamp
ThriftJavaDateConverter i64 DateTime 64-bit Java timestamp
ThriftUnixDateOffsetConverter i32 DateTimeOffset 32-bit Unix timestamp
ThriftUnixLongDateOffsetConverter i64 DateTimeOffset 64-bit Unix timestamp
ThriftJavaDateOffsetConverter i64 DateTimeOffset 64-bit Java timestamp

N.B.: An Unix timestamp is the number of seconds from 01.01.1970 00:00:00 UTC. A Java timestamp is the same with milliseconds.

Implementing your own converter

Implement the IThriftValueConverter<TFrom, TTo> interface. It contains two methods: TTo Convert( TFrom value ) and TFrom ConvertBack( TTo value ).

⚠️ **GitHub.com Fallback** ⚠️