Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Protocol buffers Apache thrift,结构包含自身_Protocol Buffers_Thrift_Thrift Protocol - Fatal编程技术网

Protocol buffers Apache thrift,结构包含自身

Protocol buffers Apache thrift,结构包含自身,protocol-buffers,thrift,thrift-protocol,Protocol Buffers,Thrift,Thrift Protocol,我正在研究数据序列化的节俭方法。但文件说 循环结构-结构只能包含在其前面声明的结构。结构也不能包含自身 我们的要求之一是 结构A 子项列表 项目(项目为结构A) 所以阅读要求我不能在任何层次上拥有结构本身?我可以把它放在循环模型中,就像上面一样。Struct不是Struct的直接成员,但它有一些其他成员,并且它包含Struct 他们的文件描述得不太好 节俭有可能吗?protobuf支持它吗?根据,节约是不可能的。但是,有一种解决方法,可以使用整数索引到主列表中。本质上,这是一种穷人的

我正在研究数据序列化的节俭方法。但文件说

循环结构-结构只能包含在其前面声明的结构。结构也不能包含自身

我们的要求之一是

  • 结构A
    • 子项列表
      • 项目(项目为结构A)
所以阅读要求我不能在任何层次上拥有结构本身?我可以把它放在循环模型中,就像上面一样。Struct不是Struct的直接成员,但它有一些其他成员,并且它包含Struct

他们的文件描述得不太好

节俭有可能吗?protobuf支持它吗?

根据,节约是不可能的。但是,有一种解决方法,可以使用整数索引到主列表中。本质上,这是一种穷人的指南针

struct A 
{ 
1: list<i32> subitems; 
}

struct AllAs 
{ 
1: list<A> items; 
} 

是,从Thrift 0.9.2开始支持此方案

对于任何早期版本的thrift,以下(故意)导致编译器错误消息:

struct Foo {
  1 : Foo foo     // error - Foo not fully defined yet
  2 : Bar bar     // error - Bar not defined yet
}

struct Bar {
  1 : Foo left     // ok, Foo has been defined earlier
  2 : Foo right    // ok, Foo has been defined earlier
}
但仍有一些警告。开发者负责不产生无休止的循环或菱形引用,如

var foo = new Foo();
foo.foo = foo;    // will crash on serialization with stack overflow

var bar = new Bar();
bar.left = foo;
bar.right = foo;   // points to same object only BEFORE deserialization
var foo = new Foo();
foo.foo = foo;    // will crash on serialization with stack overflow

var bar = new Bar();
bar.left = foo;
bar.right = foo;   // points to same object only BEFORE deserialization