1 module deimos.cbor.ints; 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 * Integer (uints and negints) manipulation 17 * ============================================================================ 18 */ 19 20 /** Extracts the integer value 21 * 22 * @param item[borrow] positive or negative integer 23 * @return the value 24 */ 25 ubyte cbor_get_uint8(const cbor_item_t* item); 26 27 /** Extracts the integer value 28 * 29 * @param item[borrow] positive or negative integer 30 * @return the value 31 */ 32 ushort cbor_get_uint16(const cbor_item_t* item); 33 34 /** Extracts the integer value 35 * 36 * @param item[borrow] positive or negative integer 37 * @return the value 38 */ 39 uint cbor_get_uint32(const cbor_item_t* item); 40 41 /** Extracts the integer value 42 * 43 * @param item[borrow] positive or negative integer 44 * @return the value 45 */ 46 ulong cbor_get_uint64(const cbor_item_t* item); 47 48 /** Extracts the integer value 49 * 50 * @param item[borrow] positive or negative integer 51 * @return the value, extended to `uint64_t` 52 */ 53 ulong cbor_get_int(const cbor_item_t* item); 54 55 /** Assigns the integer value 56 * 57 * @param item[borrow] positive or negative integer item 58 * @param value the value to assign. For negative integer, the logical value is 59 * `-value - 1` 60 */ 61 void cbor_set_uint8(cbor_item_t* item, ubyte value); 62 63 /** Assigns the integer value 64 * 65 * @param item[borrow] positive or negative integer item 66 * @param value the value to assign. For negative integer, the logical value is 67 * `-value - 1` 68 */ 69 void cbor_set_uint16(cbor_item_t* item, ushort value); 70 71 /** Assigns the integer value 72 * 73 * @param item[borrow] positive or negative integer item 74 * @param value the value to assign. For negative integer, the logical value is 75 * `-value - 1` 76 */ 77 void cbor_set_uint32(cbor_item_t* item, uint value); 78 79 /** Assigns the integer value 80 * 81 * @param item[borrow] positive or negative integer item 82 * @param value the value to assign. For negative integer, the logical value is 83 * `-value - 1` 84 */ 85 void cbor_set_uint64(cbor_item_t* item, ulong value); 86 87 /** Queries the integer width 88 * 89 * @param item[borrow] positive or negative integer item 90 * @return the width 91 */ 92 cbor_int_width cbor_int_get_width(const cbor_item_t* item); 93 94 /** Marks the integer item as a positive integer 95 * 96 * The data value is not changed 97 * 98 * @param item[borrow] positive or negative integer item 99 */ 100 void cbor_mark_uint(cbor_item_t* item); 101 102 /** Marks the integer item as a negative integer 103 * 104 * The data value is not changed 105 * 106 * @param item[borrow] positive or negative integer item 107 */ 108 void cbor_mark_negint(cbor_item_t* item); 109 110 /** Allocates new integer with 1B width 111 * 112 * The width cannot be changed once allocated 113 * 114 * @return **new** positive integer or `NULL` on memory allocation failure. The 115 * value is not initialized 116 */ 117 cbor_item_t* cbor_new_int8(); 118 119 /** Allocates new integer with 2B width 120 * 121 * The width cannot be changed once allocated 122 * 123 * @return **new** positive integer or `NULL` on memory allocation failure. The 124 * value is not initialized 125 */ 126 cbor_item_t* cbor_new_int16(); 127 128 /** Allocates new integer with 4B width 129 * 130 * The width cannot be changed once allocated 131 * 132 * @return **new** positive integer or `NULL` on memory allocation failure. The 133 * value is not initialized 134 */ 135 cbor_item_t* cbor_new_int32(); 136 137 /** Allocates new integer with 8B width 138 * 139 * The width cannot be changed once allocated 140 * 141 * @return **new** positive integer or `NULL` on memory allocation failure. The 142 * value is not initialized 143 */ 144 cbor_item_t* cbor_new_int64(); 145 146 /** Constructs a new positive integer 147 * 148 * @param value the value to use 149 * @return **new** positive integer or `NULL` on memory allocation failure 150 */ 151 cbor_item_t* cbor_build_uint8(ubyte value); 152 153 /** Constructs a new positive integer 154 * 155 * @param value the value to use 156 * @return **new** positive integer or `NULL` on memory allocation failure 157 */ 158 cbor_item_t* cbor_build_uint16(ushort value); 159 160 /** Constructs a new positive integer 161 * 162 * @param value the value to use 163 * @return **new** positive integer or `NULL` on memory allocation failure 164 */ 165 cbor_item_t* cbor_build_uint32(uint value); 166 167 /** Constructs a new positive integer 168 * 169 * @param value the value to use 170 * @return **new** positive integer or `NULL` on memory allocation failure 171 */ 172 cbor_item_t* cbor_build_uint64(ulong value); 173 174 /** Constructs a new negative integer 175 * 176 * @param value the value to use 177 * @return **new** negative integer or `NULL` on memory allocation failure 178 */ 179 cbor_item_t* cbor_build_negint8(ubyte value); 180 181 /** Constructs a new negative integer 182 * 183 * @param value the value to use 184 * @return **new** negative integer or `NULL` on memory allocation failure 185 */ 186 cbor_item_t* cbor_build_negint16(ushort value); 187 188 /** Constructs a new negative integer 189 * 190 * @param value the value to use 191 * @return **new** negative integer or `NULL` on memory allocation failure 192 */ 193 cbor_item_t* cbor_build_negint32(uint value); 194 195 /** Constructs a new negative integer 196 * 197 * @param value the value to use 198 * @return **new** negative integer or `NULL` on memory allocation failure 199 */ 200 cbor_item_t* cbor_build_negint64(ulong value);