tagion_document_get_text

Get document as string

extern (C)
int
tagion_document_get_text
(
const uint8_t* buf
,
const size_t buf_len
,
const int text_format
,
char** str
,
size_t* str_len
)

Parameters

buf uint8_t*

doc buffer

buf_len size_t

doc len

text_format int

See DocumentTextFormat for supported formats

str char**

returned pointer

str_len size_t*

returned str len

Return Value

Type: int

Examples

import tagion.hibon.HiBONJSON;
import tagion.hibon.HiBONtoText;
import std.format;

auto h = new HiBON;
h["hai"] = "bon";
const doc = Document(h);

// hex
char* str_value;
size_t str_len;
int rt = tagion_document_get_text(&doc.data[0], doc.data.length, DocumentTextFormat.HEX, &str_value, &str_len); 
assert(rt == ErrorCode.none);
auto str = str_value[0..str_len];
assert(str == format("%(%02x%)", doc.serialize));

// json
rt = tagion_document_get_text(&doc.data[0], doc.data.length, DocumentTextFormat.JSON, &str_value, &str_len); 
assert(rt == ErrorCode.none);
str = str_value[0..str_len];
assert(str == doc.toJSON.toString);


// jsonpretty
rt = tagion_document_get_text(&doc.data[0], doc.data.length, DocumentTextFormat.PRETTYJSON, &str_value, &str_len); 
assert(rt == ErrorCode.none);
str = str_value[0..str_len];
assert(str == doc.toPretty);

// base64
rt = tagion_document_get_text(&doc.data[0], doc.data.length, DocumentTextFormat.BASE64, &str_value, &str_len); 
assert(rt == ErrorCode.none);
str = str_value[0..str_len];
assert(str == doc.encodeBase64);

// none existing format
rt = tagion_document_get_text(&doc.data[0], doc.data.length, 100, &str_value, &str_len); 
assert(rt == ErrorCode.error);