tagion_document_get_document

Get an sub doc from a document

extern (C)
int
tagion_document_get_document
(,
uint8_t** buf
,
size_t* buf_len
)

Parameters

element Document.Element*

element to get

buf uint8_t**

returned buffer

buf_len size_t*

length of buffer

Return Value

Type: int

ErrorCode

Examples

auto sub_hibon = new HiBON;
sub_hibon["i32"] = "hello";
auto sub_doc = Document(sub_hibon);
string key_doc = "doc";
auto h = new HiBON;
h[key_doc] = sub_doc;
const doc = Document(h);

Document.Element elm_doc;
int rt = tagion_document_element_by_key(&doc.data[0], doc.data.length, &key_doc[0], key_doc.length, &elm_doc);
assert(rt == ErrorCode.none, "Get document element string returned error");

uint8_t* buf;
size_t buf_len;

rt = tagion_document_get_document(&elm_doc, &buf, &buf_len);
assert(rt == ErrorCode.none, "Get subdoc returned error");

auto read_data = cast(immutable) buf[0..buf_len];
assert(sub_doc == Document(read_data), "read doc was not the same");