1 module deimos.cbor.serialization; 2 3 import deimos.cbor.data; 4 5 /* 6 * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com> 7 * 8 * libcbor is free software; you can redistribute it and/or modify 9 * it under the terms of the MIT license. See LICENSE for details. 10 */ 11 12 extern (C): 13 14 /* 15 * ============================================================================ 16 * High level encoding 17 * ============================================================================ 18 */ 19 20 /** Serialize the given item 21 * 22 * @param item[borrow] A data item 23 * @param buffer Buffer to serialize to 24 * @param buffer_size Size of the \p buffer 25 * @return Length of the result. 0 on failure. 26 */ 27 size_t cbor_serialize(const cbor_item_t* item, cbor_mutable_data buffer, size_t buffer_size); 28 29 /** Serialize the given item, allocating buffers as needed 30 * 31 * \rst 32 * .. warning:: It is your responsibility to free the buffer using an 33 * appropriate ``free`` implementation. \endrst 34 * 35 * @param item[borrow] A data item 36 * @param buffer[out] Buffer containing the result 37 * @param buffer_size[out] Size of the \p buffer 38 * @return Length of the result. 0 on failure, in which case \p buffer is 39 * ``NULL``. 40 */ 41 size_t cbor_serialize_alloc(const cbor_item_t* item, 42 cbor_mutable_data* buffer, size_t* buffer_size); 43 44 /** Serialize an uint 45 * 46 * @param item[borrow] A uint 47 * @param buffer Buffer to serialize to 48 * @param buffer_size Size of the \p buffer 49 * @return Length of the result. 0 on failure. 50 */ 51 size_t cbor_serialize_uint(const cbor_item_t*, cbor_mutable_data, size_t); 52 53 /** Serialize a negint 54 * 55 * @param item[borrow] A neging 56 * @param buffer Buffer to serialize to 57 * @param buffer_size Size of the \p buffer 58 * @return Length of the result. 0 on failure. 59 */ 60 size_t cbor_serialize_negint(const cbor_item_t*, cbor_mutable_data, size_t); 61 62 /** Serialize a bytestring 63 * 64 * @param item[borrow] A bytestring 65 * @param buffer Buffer to serialize to 66 * @param buffer_size Size of the \p buffer 67 * @return Length of the result. 0 on failure. 68 */ 69 size_t cbor_serialize_bytestring(const cbor_item_t*, cbor_mutable_data, size_t); 70 71 /** Serialize a string 72 * 73 * @param item[borrow] A string 74 * @param buffer Buffer to serialize to 75 * @param buffer_size Size of the \p buffer 76 * @return Length of the result. 0 on failure. 77 */ 78 size_t cbor_serialize_string(const cbor_item_t*, cbor_mutable_data, size_t); 79 80 /** Serialize an array 81 * 82 * @param item[borrow] An array 83 * @param buffer Buffer to serialize to 84 * @param buffer_size Size of the \p buffer 85 * @return Length of the result. 0 on failure. 86 */ 87 size_t cbor_serialize_array(const cbor_item_t*, cbor_mutable_data, size_t); 88 89 /** Serialize a map 90 * 91 * @param item[borrow] A map 92 * @param buffer Buffer to serialize to 93 * @param buffer_size Size of the \p buffer 94 * @return Length of the result. 0 on failure. 95 */ 96 size_t cbor_serialize_map(const cbor_item_t*, cbor_mutable_data, size_t); 97 98 /** Serialize a tag 99 * 100 * @param item[borrow] A tag 101 * @param buffer Buffer to serialize to 102 * @param buffer_size Size of the \p buffer 103 * @return Length of the result. 0 on failure. 104 */ 105 size_t cbor_serialize_tag(const cbor_item_t*, cbor_mutable_data, size_t); 106 107 /** Serialize a 108 * 109 * @param item[borrow] A float or ctrl 110 * @param buffer Buffer to serialize to 111 * @param buffer_size Size of the \p buffer 112 * @return Length of the result. 0 on failure. 113 */ 114 size_t cbor_serialize_float_ctrl(const cbor_item_t*, cbor_mutable_data, size_t);