| Server IP : 82.208.35.60 / Your IP : 216.73.216.238 Web Server : Apache/2.4.55 (FreeBSD) OpenSSL/1.1.1q-freebsd PHP/7.3.31 System : FreeBSD server7.d2m.cz 12.4-RELEASE-p9 FreeBSD 12.4-RELEASE-p9 GENERIC amd64 User : studiokobylisy_cz ( 1008) PHP Version : 7.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /usr/local/include/cbor/ |
Upload File : |
/*
* Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com>
*
* libcbor is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/
#ifndef LIBCBOR_INTS_H
#define LIBCBOR_INTS_H
#include "cbor/cbor_export.h"
#include "cbor/common.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* ============================================================================
* Integer (uints and negints) manipulation
* ============================================================================
*/
/** Extracts the integer value
*
* @param item[borrow] positive or negative integer
* @return the value
*/
CBOR_EXPORT uint8_t cbor_get_uint8(const cbor_item_t *item);
/** Extracts the integer value
*
* @param item[borrow] positive or negative integer
* @return the value
*/
CBOR_EXPORT uint16_t cbor_get_uint16(const cbor_item_t *item);
/** Extracts the integer value
*
* @param item[borrow] positive or negative integer
* @return the value
*/
CBOR_EXPORT uint32_t cbor_get_uint32(const cbor_item_t *item);
/** Extracts the integer value
*
* @param item[borrow] positive or negative integer
* @return the value
*/
CBOR_EXPORT uint64_t cbor_get_uint64(const cbor_item_t *item);
/** Extracts the integer value
*
* @param item[borrow] positive or negative integer
* @return the value, extended to `uint64_t`
*/
CBOR_EXPORT uint64_t cbor_get_int(const cbor_item_t *item);
/** Assigns the integer value
*
* @param item[borrow] positive or negative integer item
* @param value the value to assign. For negative integer, the logical value is
* `-value - 1`
*/
CBOR_EXPORT void cbor_set_uint8(cbor_item_t *item, uint8_t value);
/** Assigns the integer value
*
* @param item[borrow] positive or negative integer item
* @param value the value to assign. For negative integer, the logical value is
* `-value - 1`
*/
CBOR_EXPORT void cbor_set_uint16(cbor_item_t *item, uint16_t value);
/** Assigns the integer value
*
* @param item[borrow] positive or negative integer item
* @param value the value to assign. For negative integer, the logical value is
* `-value - 1`
*/
CBOR_EXPORT void cbor_set_uint32(cbor_item_t *item, uint32_t value);
/** Assigns the integer value
*
* @param item[borrow] positive or negative integer item
* @param value the value to assign. For negative integer, the logical value is
* `-value - 1`
*/
CBOR_EXPORT void cbor_set_uint64(cbor_item_t *item, uint64_t value);
/** Queries the integer width
*
* @param item[borrow] positive or negative integer item
* @return the width
*/
CBOR_EXPORT cbor_int_width cbor_int_get_width(const cbor_item_t *item);
/** Marks the integer item as a positive integer
*
* The data value is not changed
*
* @param item[borrow] positive or negative integer item
*/
CBOR_EXPORT void cbor_mark_uint(cbor_item_t *item);
/** Marks the integer item as a negative integer
*
* The data value is not changed
*
* @param item[borrow] positive or negative integer item
*/
CBOR_EXPORT void cbor_mark_negint(cbor_item_t *item);
/** Allocates new integer with 1B width
*
* The width cannot be changed once allocated
*
* @return **new** positive integer or `NULL` on memory allocation failure. The
* value is not initialized
*/
CBOR_EXPORT cbor_item_t *cbor_new_int8();
/** Allocates new integer with 2B width
*
* The width cannot be changed once allocated
*
* @return **new** positive integer or `NULL` on memory allocation failure. The
* value is not initialized
*/
CBOR_EXPORT cbor_item_t *cbor_new_int16();
/** Allocates new integer with 4B width
*
* The width cannot be changed once allocated
*
* @return **new** positive integer or `NULL` on memory allocation failure. The
* value is not initialized
*/
CBOR_EXPORT cbor_item_t *cbor_new_int32();
/** Allocates new integer with 8B width
*
* The width cannot be changed once allocated
*
* @return **new** positive integer or `NULL` on memory allocation failure. The
* value is not initialized
*/
CBOR_EXPORT cbor_item_t *cbor_new_int64();
/** Constructs a new positive integer
*
* @param value the value to use
* @return **new** positive integer or `NULL` on memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_build_uint8(uint8_t value);
/** Constructs a new positive integer
*
* @param value the value to use
* @return **new** positive integer or `NULL` on memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_build_uint16(uint16_t value);
/** Constructs a new positive integer
*
* @param value the value to use
* @return **new** positive integer or `NULL` on memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_build_uint32(uint32_t value);
/** Constructs a new positive integer
*
* @param value the value to use
* @return **new** positive integer or `NULL` on memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_build_uint64(uint64_t value);
/** Constructs a new negative integer
*
* @param value the value to use
* @return **new** negative integer or `NULL` on memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_build_negint8(uint8_t value);
/** Constructs a new negative integer
*
* @param value the value to use
* @return **new** negative integer or `NULL` on memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_build_negint16(uint16_t value);
/** Constructs a new negative integer
*
* @param value the value to use
* @return **new** negative integer or `NULL` on memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_build_negint32(uint32_t value);
/** Constructs a new negative integer
*
* @param value the value to use
* @return **new** negative integer or `NULL` on memory allocation failure
*/
CBOR_EXPORT cbor_item_t *cbor_build_negint64(uint64_t value);
#ifdef __cplusplus
}
#endif
#endif // LIBCBOR_INTS_H