The biggest problem in the languages that I'm familiar with is
C++.  Unlike Protocol Buffers, we store members directly in our
structures (rather than by pointers), so our members are not
nullable.  Therefore, it is impossible to have something like

struct Folder {
  optional 1: Folder parent;
}

since that would require infinite memory.  The list case is possible
in theory, but I think it would require a lot of work.

There are other "gotchas" that would come up.  For example, I think
the code in the Python generator that creates the type specification
passed to the protocol accelerator module is not recursion-safe.

One workaround you can use is to create something like an inode table
in your struct.

struct Folder {
  1: string name;
  2: list<i32> subfolders;
}

struct FileSystem {
  1: list<Folder> folders;
}

The subfolder integers are indexes into the "folders" list in the
"FileSystem" struct.

--David

Bryan Duxbury wrote:
> Up to this point we have avoided it, and it's not on the roadmap.  
> There have been a few discussions in the past about why we haven't  
> done this to date.
> 
> If someone wanted to tackle this feature, the first thing that would  
> need to be done is to make the compiler ok with references to structs  
> that don't appear before them lexically. From there it probably  
> wouldn't be too much of challenge. Maybe David or someone else with a  
> deeper sense can chime in?
> 
> -Bryan
> 
> On Aug 4, 2009, at 9:50 AM, Samir Mulder wrote:
> 
>> Hi,
>>
>> I've been using Thrift for over a year now and love it. It has  
>> really increased my productivity in rolling out distributes services.
>>
>> But the project I'm working on now needs a feature I haven't needed  
>> before and Thrift does not seem to support it. And that is  
>> recursion in a datatype. The example is that of a folder with  
>> subfolders:
>>
>> struct Folder
>> {
>>   1: some data....
>>   2: list<Folder> subfolders
>> }
>>
>> The compiler does not allow this since the type 'Folder' is not yet  
>> defined when it reaches the 'subfolders' item.
>>
>> For this particular project allowing recursion is critical. Google  
>> Protocol Buffers supports it but I don't really want to switch to  
>> that this late in the game.
>>
>> Any ideas on how to work around this? Is something like this  
>> planned for a future release?
>>
>> Thanks.
>>
>> Samir
> 

Reply via email to