diff options
author | Luca Muscariello <lumuscar+fdio@cisco.com> | 2017-02-23 20:44:26 +0100 |
---|---|---|
committer | Luca Muscariello <lumuscar+fdio@cisco.com> | 2017-02-23 19:51:14 +0000 |
commit | d18ae43123fcd7604d1c36a1ec8450dbe6071824 (patch) | |
tree | 2d49fc3aabd0f2607251c854565648d47b56b2e9 /libccnx-common/ccnx/common/ccnx_NameSegmentNumber.h | |
parent | 9b30fc10fb1cbebe651e5a107e8ca5b24de54675 (diff) |
Initial commit: ccnxlibs.
Change-Id: I1b376527a7dd01a6b9e083a6cb646955902f45c0
Signed-off-by: Luca Muscariello <lumuscar+fdio@cisco.com>
Diffstat (limited to 'libccnx-common/ccnx/common/ccnx_NameSegmentNumber.h')
-rwxr-xr-x | libccnx-common/ccnx/common/ccnx_NameSegmentNumber.h | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/libccnx-common/ccnx/common/ccnx_NameSegmentNumber.h b/libccnx-common/ccnx/common/ccnx_NameSegmentNumber.h new file mode 100755 index 00000000..a685c713 --- /dev/null +++ b/libccnx-common/ccnx/common/ccnx_NameSegmentNumber.h @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file ccnx_NameSegmentNumber.h + * @ingroup Naming + * @brief Utilities for creating and parsing CCNxNameSegments that contain an integer value. + * + * CCNxNameSegments may optionally contain an integer value. This file contains some utilities + * for creating and parsing CCNxNameSegments with integer values. + * See {@link CCNxNameSegment}, {@link CCNxNameLabelType}, and {@link CCNxName} for more information. + * + */ +#ifndef libccnx_ccnx_NameSegmentNumber_h +#define libccnx_ccnx_NameSegmentNumber_h + +#include <stdbool.h> + +#include <ccnx/common/ccnx_NameSegment.h> +#include <ccnx/common/ccnx_NameLabel.h> + +/** + * Create a new {@link CCNxNameSegment} consisting of a type and integer value. + * + * The newly created instance must eventually be released by calling {@link ccnxNameSegment_Release}(). + * + * @param [in] type A valid {@link CCNxNameLabelType}. + * @param [in] value The integer value to assign to the `CCNxNameSegment`. + * @return A pointer to a new `CCNxNameSegment` instance, consisting of a type and integer value. + * + * Example: + * @code + * { + * uint64_t expected = 0x123456789ABCDEF0; + * CCNxNameSegment *segment = ccnxNameSegmentNumber_Create(CCNxNameLabelType_CHUNK, expected); + * + * uint64_t actual = ccnxNameSegmentNumber_Value(segment); + * + * assertTrue(expected == actual, "Expected 0x%" PRIX64 " actual 0x%" PRIX64 "", expected, actual); + * + * ccnxNameSegment_Release(&segment); + * } + * @endcode + * + * @see {@link ccnxNameSegment_Release} + * @see `CCNxNameLabelType` + */ +CCNxNameSegment *ccnxNameSegmentNumber_Create(CCNxNameLabelType type, uint64_t value); + +/** + * Decode an integer value from a {@link CCNxNameSegment}. + * + * Given a `CCNxNameSegment` with a numeric type, return the integer value associated with the `CCNxNameSegment`. + * + * @param [in] nameSegment A pointer a `CCNxNameSegment` instance containing an integer value. + * @return The integer value of the `CCNxNameSegment`. + * + * Example: + * @code + * { + * uint64_t expected = 0x123456789ABCDEF0; + * CCNxNameSegment *segment = ccnxNameSegmentNumber_Create(CCNxNameLabelType_CHUNK, expected); + * + * uint64_t actual = ccnxNameSegmentNumber_Value(segment); + * + * assertTrue(expected == actual, "Expected 0x%" PRIX64 " actual 0x%" PRIX64 "", expected, actual); + * + * ccnxNameSegment_Release(&segment); + * } + * @endcode + */ +uint64_t ccnxNameSegmentNumber_Value(const CCNxNameSegment *nameSegment); + +/** + * Determine if the given CCNxNameSegment value represents a valid encoded number. + * + * A valid encoded number contains at least 1 byte and nor more than 8 bytes. + * + * @param [in] nameSegment A pointer to a CCNxNameSegment instance. + * + * Example: + * @code + * { + * uint64_t expected = 0x123456789ABCDEF0; + * CCNxNameSegment *segment = ccnxNameSegmentNumber_Create(CCNxNameLabelType_CHUNK, expected); + * + * ccnxNameSegmentNumber_AssertValid(segment); + * } + * @endcode + */ +bool ccnxNameSegmentNumber_IsValid(const CCNxNameSegment *nameSegment); + +/** + * Assert that the given CCNxNameSegment value represents a valid encoded number. + * + * @param [in] nameSegment A pointer to a CCNxNameSegment instance. + * + * Example: + * @code + * { + * uint64_t expected = 0x123456789ABCDEF0; + * CCNxNameSegment *segment = ccnxNameSegmentNumber_Create(CCNxNameLabelType_CHUNK, expected); + * + * ccnxNameSegmentNumber_AssertValid(segment); + * } + * @endcode + */ +void ccnxNameSegmentNumber_AssertValid(const CCNxNameSegment *nameSegment); +#endif // libccnx_ccnx_NameSegmentNumber_h |