ud3tn/include/bundle7/bundle_age.h
Georg Alexander Murzik 298431c68f Insert SPDX license expression comments into our .c, .h, .py, and .sh code
ud3tn is available under multiple licenses and we want to reflect this in
our source code. But which license information should appear first and how
can we manage this efficiently in the future? The Linux Kernel uses SPDX
expressions instead of boilerplate sections. This seems to be a great
approach, so we do the same here.

Signed-off-by: Georg Alexander Murzik <georg.murzik@d3tn.com>
2022-02-20 16:24:38 +01:00

46 lines
1.2 KiB
C

// SPDX-License-Identifier: BSD-3-Clause OR Apache-2.0
#ifndef BUNDLE_AGE_H_INCLUDED
#define BUNDLE_AGE_H_INCLUDED
#include "ud3tn/bundle.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
/**
* Parses the given CBOR-encoded data into a uint64_t value.
* This function can be used to parse the payload of a bundle age
* extension block.
*
* @param bundle_age Pointer for returning the result
* @param buffer CBOR-encoded data
* @param length CBOR data length
*/
bool bundle_age_parse(uint64_t *bundle_age, const uint8_t *buffer,
size_t length);
/**
* Maximum length of a CBOR-encoded bundle age
* - 5 Bit length information
* - 8 Byte uint64_t value
*/
#define BUNDLE_AGE_MAX_ENCODED_SIZE 9
/**
* Generates the CBOR-encoded version of the given bundle age in milliseconds
* and writes it into the passed buffer. The buffer must be at least be
* BUNDLE_AGE_MAX_ENCODED_SIZE bytes long
*
* @param bundle_age uint_64_t Bundle Age in milliseconds
* @param buffer Output buffer
* @param length Buffer length
* @return Number of bytes written into buffer
*/
size_t bundle_age_serialize(const uint64_t bundle_age, uint8_t *const buffer,
const size_t length);
#endif // BUNDLE_AGE_H_INCLUDED