You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Tim Hughes <th...@thegoldfish.org> on 2010/01/08 02:24:39 UTC
Using a type before it has been defined
I am wondering if the following concept is possible in some way, other
than the way i am doing it obviously. It is a bit recursive and is
giving an issue when compiling. The error is:
Type "Domains" has not been defined
and the thrift code is:
struct Node {
1: i32 id,
2: string name,
3: string hb_time,
4: i32 running_state,
5: Domains domains,
}
struct Domain {
1: i32 id,
2: string name,
3: string hb_time,
4: i32 state,
5: Node node,
}
typedef list<Domain> Domains
typedef list<Node> Nodes
typedef i32 IdNum
service Virt {
Node getNode(1:i32 id),
IdNum saveNode(1:Node node),
Domain getDomain(1:i32 id),
Domains getDomainByNode(1:Node node),
Node getNodeOfDomain(1:i32 id),
Nodes getAllNodes(),
}
Tim Hughes
mailto:thughes@thegoldfish.org
Re: Using a type before it has been defined
Posted by Tim Hughes <tj...@gmail.com>.
Thanks everyone, I have ended up going with the list of integers
method, not as neat but will work fairly easily
Tim Hughes
mailto:thughes@thegoldfish.org
On Fri, Jan 15, 2010 at 1:55 AM, Mark Slee <ms...@facebook.com> wrote:
> That won't work properly either, forward declarations are not allowed in Thrift.
>
> The reason for this is in the thread David referenced -- Thrift elements are not nullable because in C++ we store actual objects rather than references/pointers.
>
> The simplest thing to do here is probably to simplify the Node object to just reference domains by id. You probably don't need/want to always incur the full overhead of storing a full list of rich Domain objects in every Node.
>
> struct Domain {
> 5: Node node;
> }
>
> typedef list<i32> Domains; // Store a list of integer pointers to the Domains by id
> struct Node {
> 5: Domains domains;
> }
>
> -----Original Message-----
> From: Rory McGuire [mailto:rmcguire@neonova.co.za]
> Sent: Wednesday, January 13, 2010 12:43 AM
> To: thrift-user@incubator.apache.org
> Subject: Re: Using a type before it has been defined
>
> You could try this.
>
> struct Node {}
>
> struct Domain {
> 1: i32 id,
> 2: string name,
> 3: string hb_time,
> 4: i32 state,
> 5: Node node,
> }
> typedef list<Domain> Domains
>
> struct Node {
> 1: i32 id,
> 2: string name,
> 3: string hb_time,
> 4: i32 running_state,
> 5: Domains domains,
> }
>
> typedef list<Node> Nodes
> typedef i32 IdNum
>
> service Virt {
> Node getNode(1:i32 id),
> IdNum saveNode(1:Node node),
> Domain getDomain(1:i32 id),
> Domains getDomainByNode(1:Node node),
> Node getNodeOfDomain(1:i32 id),
> Nodes getAllNodes(),
> }
>
>
>
> On 08 Jan 2010, at 8:28 AM, David Reiss wrote:
>
>> Short answer: no. See this thread for details: http://markmail.org/thread/4pwhw5d254zrphv5
>>
>> Tim Hughes wrote:
>>> I am wondering if the following concept is possible in some way,
>>> other
>>> than the way i am doing it obviously. It is a bit recursive and is
>>> giving an issue when compiling. The error is:
>>>
>>> Type "Domains" has not been defined
>>>
>>>
>>> and the thrift code is:
>>>
>>> struct Node {
>>> 1: i32 id,
>>> 2: string name,
>>> 3: string hb_time,
>>> 4: i32 running_state,
>>> 5: Domains domains,
>>> }
>>>
>>>
>>> struct Domain {
>>> 1: i32 id,
>>> 2: string name,
>>> 3: string hb_time,
>>> 4: i32 state,
>>> 5: Node node,
>>> }
>>>
>>> typedef list<Domain> Domains
>>> typedef list<Node> Nodes
>>> typedef i32 IdNum
>>>
>>> service Virt {
>>> Node getNode(1:i32 id),
>>> IdNum saveNode(1:Node node),
>>> Domain getDomain(1:i32 id),
>>> Domains getDomainByNode(1:Node node),
>>> Node getNodeOfDomain(1:i32 id),
>>> Nodes getAllNodes(),
>>> }
>>>
>>>
>>>
>>>
>>> Tim Hughes
>>> mailto:thughes@thegoldfish.org
>
>
RE: Using a type before it has been defined
Posted by Mark Slee <ms...@facebook.com>.
That won't work properly either, forward declarations are not allowed in Thrift.
The reason for this is in the thread David referenced -- Thrift elements are not nullable because in C++ we store actual objects rather than references/pointers.
The simplest thing to do here is probably to simplify the Node object to just reference domains by id. You probably don't need/want to always incur the full overhead of storing a full list of rich Domain objects in every Node.
struct Domain {
5: Node node;
}
typedef list<i32> Domains; // Store a list of integer pointers to the Domains by id
struct Node {
5: Domains domains;
}
-----Original Message-----
From: Rory McGuire [mailto:rmcguire@neonova.co.za]
Sent: Wednesday, January 13, 2010 12:43 AM
To: thrift-user@incubator.apache.org
Subject: Re: Using a type before it has been defined
You could try this.
struct Node {}
struct Domain {
1: i32 id,
2: string name,
3: string hb_time,
4: i32 state,
5: Node node,
}
typedef list<Domain> Domains
struct Node {
1: i32 id,
2: string name,
3: string hb_time,
4: i32 running_state,
5: Domains domains,
}
typedef list<Node> Nodes
typedef i32 IdNum
service Virt {
Node getNode(1:i32 id),
IdNum saveNode(1:Node node),
Domain getDomain(1:i32 id),
Domains getDomainByNode(1:Node node),
Node getNodeOfDomain(1:i32 id),
Nodes getAllNodes(),
}
On 08 Jan 2010, at 8:28 AM, David Reiss wrote:
> Short answer: no. See this thread for details: http://markmail.org/thread/4pwhw5d254zrphv5
>
> Tim Hughes wrote:
>> I am wondering if the following concept is possible in some way,
>> other
>> than the way i am doing it obviously. It is a bit recursive and is
>> giving an issue when compiling. The error is:
>>
>> Type "Domains" has not been defined
>>
>>
>> and the thrift code is:
>>
>> struct Node {
>> 1: i32 id,
>> 2: string name,
>> 3: string hb_time,
>> 4: i32 running_state,
>> 5: Domains domains,
>> }
>>
>>
>> struct Domain {
>> 1: i32 id,
>> 2: string name,
>> 3: string hb_time,
>> 4: i32 state,
>> 5: Node node,
>> }
>>
>> typedef list<Domain> Domains
>> typedef list<Node> Nodes
>> typedef i32 IdNum
>>
>> service Virt {
>> Node getNode(1:i32 id),
>> IdNum saveNode(1:Node node),
>> Domain getDomain(1:i32 id),
>> Domains getDomainByNode(1:Node node),
>> Node getNodeOfDomain(1:i32 id),
>> Nodes getAllNodes(),
>> }
>>
>>
>>
>>
>> Tim Hughes
>> mailto:thughes@thegoldfish.org
Re: Using a type before it has been defined
Posted by Rory McGuire <rm...@neonova.co.za>.
You could try this.
struct Node {}
struct Domain {
1: i32 id,
2: string name,
3: string hb_time,
4: i32 state,
5: Node node,
}
typedef list<Domain> Domains
struct Node {
1: i32 id,
2: string name,
3: string hb_time,
4: i32 running_state,
5: Domains domains,
}
typedef list<Node> Nodes
typedef i32 IdNum
service Virt {
Node getNode(1:i32 id),
IdNum saveNode(1:Node node),
Domain getDomain(1:i32 id),
Domains getDomainByNode(1:Node node),
Node getNodeOfDomain(1:i32 id),
Nodes getAllNodes(),
}
On 08 Jan 2010, at 8:28 AM, David Reiss wrote:
> Short answer: no. See this thread for details: http://markmail.org/thread/4pwhw5d254zrphv5
>
> Tim Hughes wrote:
>> I am wondering if the following concept is possible in some way,
>> other
>> than the way i am doing it obviously. It is a bit recursive and is
>> giving an issue when compiling. The error is:
>>
>> Type "Domains" has not been defined
>>
>>
>> and the thrift code is:
>>
>> struct Node {
>> 1: i32 id,
>> 2: string name,
>> 3: string hb_time,
>> 4: i32 running_state,
>> 5: Domains domains,
>> }
>>
>>
>> struct Domain {
>> 1: i32 id,
>> 2: string name,
>> 3: string hb_time,
>> 4: i32 state,
>> 5: Node node,
>> }
>>
>> typedef list<Domain> Domains
>> typedef list<Node> Nodes
>> typedef i32 IdNum
>>
>> service Virt {
>> Node getNode(1:i32 id),
>> IdNum saveNode(1:Node node),
>> Domain getDomain(1:i32 id),
>> Domains getDomainByNode(1:Node node),
>> Node getNodeOfDomain(1:i32 id),
>> Nodes getAllNodes(),
>> }
>>
>>
>>
>>
>> Tim Hughes
>> mailto:thughes@thegoldfish.org
Re: Using a type before it has been defined
Posted by David Reiss <dr...@facebook.com>.
Short answer: no. See this thread for details: http://markmail.org/thread/4pwhw5d254zrphv5
Tim Hughes wrote:
> I am wondering if the following concept is possible in some way, other
> than the way i am doing it obviously. It is a bit recursive and is
> giving an issue when compiling. The error is:
>
> Type "Domains" has not been defined
>
>
> and the thrift code is:
>
> struct Node {
> 1: i32 id,
> 2: string name,
> 3: string hb_time,
> 4: i32 running_state,
> 5: Domains domains,
> }
>
>
> struct Domain {
> 1: i32 id,
> 2: string name,
> 3: string hb_time,
> 4: i32 state,
> 5: Node node,
> }
>
> typedef list<Domain> Domains
> typedef list<Node> Nodes
> typedef i32 IdNum
>
> service Virt {
> Node getNode(1:i32 id),
> IdNum saveNode(1:Node node),
> Domain getDomain(1:i32 id),
> Domains getDomainByNode(1:Node node),
> Node getNodeOfDomain(1:i32 id),
> Nodes getAllNodes(),
> }
>
>
>
>
> Tim Hughes
> mailto:thughes@thegoldfish.org