1 module deimos.cbor.encoding;
2 
3 /*
4  * Copyright (c) 2014-2019 Pavel Kalvoda <me@pavelkalvoda.com>
5  *
6  * libcbor is free software; you can redistribute it and/or modify
7  * it under the terms of the MIT license. See LICENSE for details.
8  */
9 
10 extern (C):
11 
12 /*
13  * ============================================================================
14  * Primitives encoding
15  * ============================================================================
16  */
17 
18 size_t cbor_encode_uint8(ubyte, ubyte*, size_t);
19 
20 size_t cbor_encode_uint16(ushort, ubyte*, size_t);
21 
22 size_t cbor_encode_uint32(uint, ubyte*, size_t);
23 
24 size_t cbor_encode_uint64(ulong, ubyte*, size_t);
25 
26 size_t cbor_encode_uint(ulong, ubyte*, size_t);
27 
28 size_t cbor_encode_negint8(ubyte, ubyte*, size_t);
29 
30 size_t cbor_encode_negint16(ushort, ubyte*, size_t);
31 
32 size_t cbor_encode_negint32(uint, ubyte*, size_t);
33 
34 size_t cbor_encode_negint64(ulong, ubyte*, size_t);
35 
36 size_t cbor_encode_negint(ulong, ubyte*, size_t);
37 
38 size_t cbor_encode_bytestring_start(size_t, ubyte*, size_t);
39 
40 size_t cbor_encode_indef_bytestring_start(ubyte*, size_t);
41 
42 size_t cbor_encode_string_start(size_t, ubyte*, size_t);
43 
44 size_t cbor_encode_indef_string_start(ubyte*, size_t);
45 
46 size_t cbor_encode_array_start(size_t, ubyte*, size_t);
47 
48 size_t cbor_encode_indef_array_start(ubyte*, size_t);
49 
50 size_t cbor_encode_map_start(size_t, ubyte*, size_t);
51 
52 size_t cbor_encode_indef_map_start(ubyte*, size_t);
53 
54 size_t cbor_encode_tag(ulong, ubyte*, size_t);
55 
56 size_t cbor_encode_bool(bool, ubyte*, size_t);
57 
58 size_t cbor_encode_null(ubyte*, size_t);
59 
60 size_t cbor_encode_undef(ubyte*, size_t);
61 
62 /** Encodes a half-precision float
63  *
64  * Since there is no native representation or semantics for half floats
65  * in the language, we use single-precision floats, as every value that
66  * can be expressed as a half-float can also be expressed as a float.
67  *
68  * This however means that not all floats passed to this function can be
69  * unambiguously encoded. The behavior is as follows:
70  *  - Infinity, NaN are preserved
71  *  - Zero is preserved
72  *  - Denormalized numbers keep their sign bit and 10 most significant bit of
73  * the significand
74  *  - All other numbers
75  *   - If the logical value of the exponent is < -24, the output is zero
76  *   - If the logical value of the exponent is between -23 and -14, the output
77  *     is cut off to represent the 'magnitude' of the input, by which we
78  *     mean (-1)^{signbit} x 1.0e{exponent}. The value in the significand is
79  * lost.
80  *   - In all other cases, the sign bit, the exponent, and 10 most significant
81  * bits of the significand are kept
82  *
83  * @param value
84  * @param buffer Target buffer
85  * @param buffer_size Available space in the buffer
86  * @return number of bytes written
87  */
88 size_t cbor_encode_half(float, ubyte*, size_t);
89 
90 size_t cbor_encode_single(float, ubyte*, size_t);
91 
92 size_t cbor_encode_double(double, ubyte*, size_t);
93 
94 size_t cbor_encode_break(ubyte*, size_t);
95 
96 size_t cbor_encode_ctrl(ubyte, ubyte*, size_t);