thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jens Geyer" <jensge...@hotmail.com>
Subject Re: Thrift custom types
Date Sat, 07 Nov 2015 12:56:40 GMT
Hi,

For some languages Thrift generates partial classes, e.g. for C#. Those can 
be easily extended, but not all languages (Embarcadero, I'm looking at you) 
and not all language bindings support this, unfortunately.

Have fun,
JensG


-----Urspr√ľngliche Nachricht----- 
From: BCG
Sent: Saturday, November 7, 2015 3:01 AM
To: user@thrift.apache.org
Subject: Re: Thrift custom types



On 11/6/2015 at 6:01 PM, "J" <mvnjpy@gmail.com> wrote:

>
>Say I want to add methods to the generated Java object such as
>"get10XData1()" that just returns 10x data1. Is there some way to
>do that
>or do I have to hack the thrift compiler and libraries?
>
>Similarly, say I want to have a custom type with custom
>serialization/deserialization. Is there any way to do that without
>editing
>thrift?

If you're using Java, easier than hacking the compiler and libraries would 
be to use Facebook's Swift:

https://github.com/facebook/swift

That allows you define your structs as annotated Java classes, and you can 
add whatever utility methods you like.  Also you can define "builders" that 
could be useful to customize serialization and deserialization.

If you want to be able to annotate interfaces and abstract classes instead 
of just concrete classes, you might try my fork of that tool (I sent a pull 
request to upstream for that feature but they don't seem interested):

https://github.com/bgould/swift

If you don't want to use a tool like that and instead hack on the compiler - 
for the utility methods you could probably have the Java generator recognize 
an annotation that causes the generated struct to extend from some abstract 
base class, or if you are on Java 8 it could be an interface with default 
methods.  To do custom serialization would be trickier but not impossible I 
think.

Thanks

Ben


Mime
View raw message