Add common data structures

This adds some common data structures and functions needed for RDE BEJ.

The decoder core is written in C so that we can use this with some other
future platforms.
clang-tidy is complaining about C style header. I tried adding a
.clang-tidy-ignore file but it did not work. And since this is mainly a
C library, I deleted the .clang-tidy.

Signed-off-by: Kasun Athukorala <kasunath@google.com>
Change-Id: Ice07527b23cd00c65cd11ed114ea4faefcc085fb
diff --git a/.clang-tidy b/.clang-tidy
deleted file mode 100644
index bdf15ab..0000000
--- a/.clang-tidy
+++ /dev/null
@@ -1,299 +0,0 @@
-Checks: '
--*,
-boost-use-to-string,
-bugprone-argument-comment,
-bugprone-assert-side-effect,
-bugprone-bad-signal-to-kill-thread,
-bugprone-bool-pointer-implicit-conversion,
-bugprone-branch-clone,
-bugprone-copy-constructor-init,
-bugprone-dangling-handle,
-bugprone-dynamic-static-initializers,
-bugprone-exception-escape,
-bugprone-fold-init-type,
-bugprone-forward-declaration-namespace,
-bugprone-forwarding-reference-overload,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-inaccurate-erase,
-bugprone-incorrect-roundings,
-bugprone-infinite-loop,
-bugprone-integer-division,
-bugprone-lambda-function-name,
-bugprone-macro-parentheses,
-bugprone-macro-repeated-side-effects,
-bugprone-misplaced-operator-in-strlen-in-alloc,
-bugprone-misplaced-pointer-arithmetic-in-alloc,
-bugprone-misplaced-widening-cast,
-bugprone-move-forwarding-reference,
-bugprone-multiple-statement-macro,
-bugprone-narrowing-conversions,
-bugprone-no-escape,
-bugprone-not-null-terminated-result,
-bugprone-parent-virtual-call,
-bugprone-posix-return,
-bugprone-redundant-branch-condition,
-bugprone-reserved-identifier,
-bugprone-signal-handler,
-bugprone-signed-char-misuse,
-bugprone-sizeof-container,
-bugprone-sizeof-expression,
-bugprone-spuriously-wake-up-functions,
-bugprone-string-constructor,
-bugprone-string-integer-assignment,
-bugprone-string-literal-with-embedded-nul,
-bugprone-suspicious-enum-usage,
-bugprone-suspicious-include,
-bugprone-suspicious-memset-usage,
-bugprone-suspicious-missing-comma,
-bugprone-suspicious-semicolon,
-bugprone-suspicious-string-compare,
-bugprone-swapped-arguments,
-bugprone-terminating-continue,
-bugprone-throw-keyword-missing,
-bugprone-too-small-loop-variable,
-bugprone-undefined-memory-manipulation,
-bugprone-undelegated-constructor,
-bugprone-unhandled-exception-at-new,
-bugprone-unhandled-self-assignment,
-bugprone-unused-raii,
-bugprone-unused-return-value,
-bugprone-use-after-move,
-bugprone-virtual-near-miss,
-cert-con36-c,
-cert-con54-cpp,
-cert-dcl03-c,
-cert-dcl16-c,
-cert-dcl21-cpp,
-cert-dcl37-c,
-cert-dcl50-cpp,
-cert-dcl51-cpp,
-cert-dcl54-cpp,
-cert-dcl58-cpp,
-cert-dcl59-cpp,
-cert-env33-c,
-cert-err09-cpp,
-cert-err34-c,
-cert-err52-cpp,
-cert-err60-cpp,
-cert-err61-cpp,
-cert-fio38-c,
-cert-flp30-c,
-cert-mem57-cpp,
-cert-msc30-c,
-cert-msc32-c,
-cert-msc50-cpp,
-cert-msc51-cpp,
-cert-oop11-cpp,
-cert-oop54-cpp,
-cert-oop57-cpp,
-cert-oop58-cpp,
-cert-pos44-c,
-cert-pos47-c,
-cert-sig30-c,
-cert-str34-c,
-clang-analyzer-apiModeling.StdCLibraryFunctions,
-clang-analyzer-apiModeling.TrustNonnull,
-clang-analyzer-apiModeling.google.GTest,
-clang-analyzer-apiModeling.llvm.CastValue,
-clang-analyzer-apiModeling.llvm.ReturnValue,
-clang-analyzer-core.CallAndMessageModeling,
-clang-analyzer-core.DivideZero,
-clang-analyzer-core.DynamicTypePropagation,
-clang-analyzer-core.NonNullParamChecker,
-clang-analyzer-core.NonnilStringConstants,
-clang-analyzer-core.NullDereference,
-clang-analyzer-core.StackAddrEscapeBase,
-clang-analyzer-core.StackAddressEscape,
-clang-analyzer-core.UndefinedBinaryOperatorResult,
-clang-analyzer-core.VLASize,
-clang-analyzer-core.builtin.BuiltinFunctions,
-clang-analyzer-core.builtin.NoReturnFunctions,
-clang-analyzer-core.uninitialized.ArraySubscript,
-clang-analyzer-core.uninitialized.Assign,
-clang-analyzer-core.uninitialized.Branch,
-clang-analyzer-core.uninitialized.CapturedBlockVariable,
-clang-analyzer-core.uninitialized.UndefReturn,
-clang-analyzer-cplusplus.InnerPointer,
-clang-analyzer-cplusplus.Move,
-clang-analyzer-cplusplus.NewDelete,
-clang-analyzer-cplusplus.NewDeleteLeaks,
-clang-analyzer-cplusplus.PlacementNew,
-clang-analyzer-cplusplus.PureVirtualCall,
-clang-analyzer-cplusplus.SelfAssignment,
-clang-analyzer-cplusplus.SmartPtrModeling,
-clang-analyzer-cplusplus.VirtualCallModeling,
-clang-analyzer-deadcode.DeadStores,
-clang-analyzer-fuchsia.HandleChecker,
-clang-analyzer-nullability.NullPassedToNonnull,
-clang-analyzer-nullability.NullReturnedFromNonnull,
-clang-analyzer-nullability.NullabilityBase,
-clang-analyzer-nullability.NullableDereferenced,
-clang-analyzer-nullability.NullablePassedToNonnull,
-clang-analyzer-nullability.NullableReturnedFromNonnull,
-clang-analyzer-optin.cplusplus.UninitializedObject,
-clang-analyzer-optin.cplusplus.VirtualCall,
-clang-analyzer-optin.mpi.MPI-Checker,
-clang-analyzer-optin.osx.OSObjectCStyleCast,
-clang-analyzer-optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,
-clang-analyzer-optin.osx.cocoa.localizability.NonLocalizedStringChecker,
-clang-analyzer-optin.performance.GCDAntipattern,
-clang-analyzer-optin.performance.Padding,
-clang-analyzer-optin.portability.UnixAPI,
-clang-analyzer-osx.API,
-clang-analyzer-osx.MIG,
-clang-analyzer-osx.NSOrCFErrorDerefChecker,
-clang-analyzer-osx.NumberObjectConversion,
-clang-analyzer-osx.OSObjectRetainCount,
-clang-analyzer-osx.ObjCProperty,
-clang-analyzer-osx.SecKeychainAPI,
-clang-analyzer-osx.cocoa.AtSync,
-clang-analyzer-osx.cocoa.AutoreleaseWrite,
-clang-analyzer-osx.cocoa.ClassRelease,
-clang-analyzer-osx.cocoa.Dealloc,
-clang-analyzer-osx.cocoa.IncompatibleMethodTypes,
-clang-analyzer-osx.cocoa.Loops,
-clang-analyzer-osx.cocoa.MissingSuperCall,
-clang-analyzer-osx.cocoa.NSAutoreleasePool,
-clang-analyzer-osx.cocoa.NSError,
-clang-analyzer-osx.cocoa.NilArg,
-clang-analyzer-osx.cocoa.NonNilReturnValue,
-clang-analyzer-osx.cocoa.ObjCGenerics,
-clang-analyzer-osx.cocoa.RetainCount,
-clang-analyzer-osx.cocoa.RetainCountBase,
-clang-analyzer-osx.cocoa.RunLoopAutoreleaseLeak,
-clang-analyzer-osx.cocoa.SelfInit,
-clang-analyzer-osx.cocoa.SuperDealloc,
-clang-analyzer-osx.cocoa.UnusedIvars,
-clang-analyzer-osx.cocoa.VariadicMethodTypes,
-clang-analyzer-osx.coreFoundation.CFError,
-clang-analyzer-osx.coreFoundation.CFNumber,
-clang-analyzer-osx.coreFoundation.CFRetainRelease,
-clang-analyzer-osx.coreFoundation.containers.OutOfBounds,
-clang-analyzer-osx.coreFoundation.containers.PointerSizedValues,
-clang-analyzer-security.FloatLoopCounter,
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
-clang-analyzer-security.insecureAPI.SecuritySyntaxChecker,
-clang-analyzer-security.insecureAPI.UncheckedReturn,
-clang-analyzer-security.insecureAPI.bcmp,
-clang-analyzer-security.insecureAPI.bcopy,
-clang-analyzer-security.insecureAPI.bzero,
-clang-analyzer-security.insecureAPI.decodeValueOfObjCType,
-clang-analyzer-security.insecureAPI.getpw,
-clang-analyzer-security.insecureAPI.gets,
-clang-analyzer-security.insecureAPI.mkstemp,
-clang-analyzer-security.insecureAPI.mktemp,
-clang-analyzer-security.insecureAPI.rand,
-clang-analyzer-security.insecureAPI.strcpy,
-clang-analyzer-security.insecureAPI.vfork,
-clang-analyzer-unix.API,
-clang-analyzer-unix.DynamicMemoryModeling,
-clang-analyzer-unix.Malloc,
-clang-analyzer-unix.MallocSizeof,
-clang-analyzer-unix.MismatchedDeallocator,
-clang-analyzer-unix.Vfork,
-clang-analyzer-unix.cstring.BadSizeArg,
-clang-analyzer-unix.cstring.CStringModeling,
-clang-analyzer-unix.cstring.NullArg,
-clang-analyzer-valist.CopyToSelf,
-clang-analyzer-valist.Uninitialized,
-clang-analyzer-valist.Unterminated,
-clang-analyzer-valist.ValistBase,
-clang-analyzer-webkit.NoUncountedMemberChecker,
-clang-analyzer-webkit.RefCntblBaseVirtualDtor,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-c-copy-assignment-signature,
-cppcoreguidelines-explicit-virtual-functions,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-interfaces-global-init,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-narrowing-conversions,
-cppcoreguidelines-no-malloc,
-cppcoreguidelines-prefer-member-initializer,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-const-cast,
-cppcoreguidelines-pro-type-cstyle-cast,
-cppcoreguidelines-pro-type-member-init,
-cppcoreguidelines-pro-type-static-cast-downcast,
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-slicing,
-cppcoreguidelines-special-member-functions,
-misc-misplaced-const,
-#misc-no-recursion,
-misc-redundant-expression,
-misc-static-assert,
-misc-throw-by-value-catch-by-reference,
-misc-unconventional-assign-operator,
-misc-uniqueptr-reset-release,
-misc-unused-using-decls,
-modernize-avoid-bind,
-modernize-deprecated-headers,
-modernize-deprecated-ios-base-aliases,
-modernize-loop-convert,
-modernize-make-shared,
-modernize-make-unique,
-modernize-raw-string-literal,
-modernize-replace-auto-ptr,
-modernize-replace-random-shuffle,
-modernize-return-braced-init-list,
-modernize-shrink-to-fit,
-modernize-unary-static-assert,
-modernize-use-bool-literals,
-modernize-use-default-member-init,
-modernize-use-emplace,
-modernize-use-equals-default,
-modernize-use-equals-delete,
-modernize-use-noexcept,
-modernize-use-nullptr,
-modernize-use-override,
-modernize-use-transparent-functors,
-modernize-use-uncaught-exceptions,
-modernize-use-using,
-performance-faster-string-find,
-performance-for-range-copy,
-performance-implicit-conversion-in-loop,
-performance-inefficient-algorithm,
-performance-inefficient-string-concatenation,
-performance-inefficient-vector-operation,
-performance-move-const-arg,
-performance-move-constructor-init,
-performance-no-automatic-move,
-performance-no-int-to-ptr,
-performance-noexcept-move-constructor,
-performance-trivially-destructible,
-performance-type-promotion-in-math-fn,
-performance-unnecessary-copy-initialization,
-performance-unnecessary-value-param,
-readability-avoid-const-params-in-decls,
-readability-braces-around-statements,
-readability-const-return-type,
-readability-container-size-empty,
-readability-delete-null-pointer,
-readability-deleted-default,
-readability-else-after-return,
-readability-implicit-bool-conversion,
-readability-named-parameter,
-readability-redundant-control-flow,
-readability-redundant-declaration,
-readability-redundant-function-ptr-dereference,
-readability-redundant-member-init,
-readability-redundant-preprocessor,
-readability-redundant-smartptr-get,
-readability-redundant-string-cstr,
-readability-redundant-string-init,
-readability-static-accessed-through-instance,
-readability-identifier-naming,
-readability-uppercase-literal-suffix'
-
-WarningsAsErrors: '*'
-HeaderFilterRegex: '.*'
-CheckOptions:
-  - { key: readability-identifier-naming.ClassCase,     value: CamelCase  }
-  - { key: readability-identifier-naming.VariableCase,  value: camelBack }
-  - { key: readability-identifier-naming.FunctionCase,  value: camelBack }
-  - { key: readability-identifier-naming.ParameterCase, value: camelBack }
-  - { key: readability-identifier-naming.NamespaceCase, value: lower_case }
-  - { key: readability-identifier-naming.StructCase,    value: CamelCase  }
-  - { key: cppcoreguidelines-macro-usage.AllowedRegexp, value: ((ERASE_MIN_GEOMETRY)|(ERASE_MAX_GEOMETRY)|(twiddleextCsdEraseGroupDef))  }
-
diff --git a/include/rde_common.h b/include/rde_common.h
new file mode 100644
index 0000000..bb55a37
--- /dev/null
+++ b/include/rde_common.h
@@ -0,0 +1,218 @@
+#pragma once
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * @brief If expr is non zero, return with that value.
+ */
+#ifndef RETURN_IF_IERROR
+#define RETURN_IF_IERROR(expr)                                                 \
+    do                                                                         \
+    {                                                                          \
+        int __status = (expr);                                                 \
+        if (__status != 0)                                                     \
+        {                                                                      \
+            return __status;                                                   \
+        }                                                                      \
+    } while (0)
+#endif
+
+    /**
+     * @brief RDE BEJ decoding errors.
+     */
+    enum BejError
+    {
+        BejErrorNoError = 0,
+        BejErrorUnknown,
+        BejErrorInvalidSize,
+        BejErrorNotSuppoted,
+        BejErrorUnknownProperty,
+        BejErrorInvalidSchemaType,
+        BejErrorInvalidPropertyOffset,
+    };
+
+    /**
+     * @brief BEJ schema classes.
+     */
+    enum BejSchemaClass
+    {
+        BejMajorSchemaClass = 0,
+        BejEventSchemaClass = 1,
+        BejAnnotationSchemaClass = 2,
+        BejCollectionMemberTypeSchemaClass = 3,
+        BejErrorSchemaClass = 4,
+    };
+
+    /**
+     * @brief BEJ data types supported in BEJ version 0xF1F0F000.
+     */
+    enum BejPrincipalDataType
+    {
+        BejSet = 0,
+        BejArray = 1,
+        BejNull = 2,
+        BejInteger = 3,
+        BejEnum = 4,
+        BejString = 5,
+        BejReal = 6,
+        BejBoolean = 7,
+        BejBytestring = 8,
+        BejChoice = 9,
+        BejPropertyAnnotation = 10,
+        Reserved1 = 11,
+        Reserved2 = 12,
+        Reserved3 = 13,
+        BejResourceLink = 14,
+        BejResourceLinkExpansion = 15,
+    };
+
+    /**
+     * @brief Format BEJ tuple.
+     */
+    struct BejTupleF
+    {
+        uint8_t deferredBinding : 1;
+        uint8_t readOnlyProperty : 1;
+        uint8_t nullableProperty : 1;
+        uint8_t reserved : 1;
+        enum BejPrincipalDataType principalDataType : 4;
+    } __attribute__((__packed__));
+
+    /**
+     * @brief Sequence Number BEJ tuple.
+     */
+    struct BejTupleS
+    {
+        uint8_t schema;
+        // Dictionaries contain 16bit sequence numbers. So allocating 16bits for
+        // the sequence number here.
+        uint16_t sequenceNumber;
+    };
+
+    /**
+     * @brief Represent offsets of Format, Value Length and Value of a SFLV
+     * tuple.
+     */
+    struct BejSFLVOffset
+    {
+        uint32_t formatOffset;
+        uint32_t valueLenNnintOffset;
+        uint32_t valueOffset;
+    };
+
+    /**
+     * @brief Fields in Bej Real data type.
+     */
+    struct BejReal
+    {
+        // Number bytes in exp.
+        uint8_t expLen;
+        int64_t whole;
+        uint64_t zeroCount;
+        uint64_t fract;
+        int64_t exp;
+    };
+
+    /**
+     * @brief SFLV BEJ tuple infomation.
+     */
+    struct BejSFLV
+    {
+        struct BejTupleS tupleS;
+        struct BejTupleF format;
+        // Value portion size in bytes.
+        uint32_t valueLength;
+        // Value end-offset with respect to the begining of the encoded stream.
+        uint32_t valueEndOffset;
+        // Pointer to the value.
+        const uint8_t* value;
+    };
+
+    /**
+     * @brief bejEncoding PLDM data type header.
+     */
+    struct BejPldmBlockHeader
+    {
+        uint32_t bejVersion;
+        uint16_t reserved;
+        uint8_t schemaClass;
+    } __attribute__((__packed__));
+
+    enum RdeOperationInitType
+    {
+        RdeOpInitOperationHead = 0,
+        RdeOpInitOperationRead = 1,
+        RdeOpInitOperationCreate = 2,
+        RdeOpInitOperationDelete = 3,
+        RdeOpInitOperationUpdate = 4,
+        RdeOpInitOperationReplace = 5,
+        RdeOpInitOperationAction = 6,
+    };
+
+    enum RdeMultiReceiveTransferFlag
+    {
+        RdeMRecFlagStart = 0,
+        RdeMRecFlagMiddle = 1,
+        RdeMRecFlagEnd = 2,
+        RdeMRecFlagStartAndEnd = 3,
+    };
+
+    struct RdeOperationInitReqHeader
+    {
+        uint32_t resourceID;
+        uint16_t operationID;
+        uint8_t operationType;
+
+        // OperationFlags bits
+        uint8_t locatorValid : 1;
+        uint8_t containsRequestPayload : 1;
+        uint8_t containsCustomRequestParameters : 1;
+
+        uint8_t reserved : 5;
+        uint32_t sendDataTransferHandle;
+        uint8_t operationLocatorLength;
+        uint32_t requestPayloadLength;
+    } __attribute__((__packed__));
+
+    struct MultipartReceiveResHeader
+    {
+        uint8_t completionCode;
+        uint8_t transferFlag;
+        uint32_t nextDataTransferHandle;
+        uint32_t dataLengthBytes;
+    } __attribute__((__packed__));
+
+    /**
+     * @brief Get the unsigned integer value from provided bytes.
+     *
+     * @param bytes - valid pointer to a byte stream in little-endian format.
+     * @param numOfBytes - number of bytes belongs to the value. Maximum number
+     * of bytes supported is 8. If numOfBytes > 8, the result is undefined.
+     * @return unsigend 64bit representation of the value.
+     */
+    uint64_t rdeGetUnsignedInteger(const uint8_t* bytes, uint8_t numOfBytes);
+
+    /**
+     * @brief Get the value from nnint type.
+     *
+     * @param  nnint - nnint should be pointing to a valid nnint.
+     * @return unsigend 64bit representation of the value.
+     */
+    uint64_t rdeGetNnint(const uint8_t* nnint);
+
+    /**
+     * @brief Get the size of the complete nnint.
+     *
+     * @param nnint - pointer to a valid nnint.
+     * @return size of the complete nnint.
+     */
+    uint8_t rdeGetNnintSize(const uint8_t* nnint);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..85ffb79
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,18 @@
+project(
+  'libbej',
+  'c',
+  'cpp',
+  version: '0.1',
+  meson_version: '>=0.57.0',
+  default_options: [
+    'c_std=c18',
+    'cpp_std=c++20',
+    'werror=true',
+    'warning_level=3',
+  ])
+
+libbej_incs = include_directories('include')
+subdir('src')
+if not get_option('tests').disabled()
+  subdir('test')
+endif
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..0fc2767
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1 @@
+option('tests', type: 'feature', description: 'Build tests')
diff --git a/src/meson.build b/src/meson.build
new file mode 100644
index 0000000..0d2703d
--- /dev/null
+++ b/src/meson.build
@@ -0,0 +1,11 @@
+libbej_lib = static_library(
+  'libbej',
+  'rde_common.c',
+  include_directories : libbej_incs,
+  implicit_include_directories: false
+)
+
+libbej = declare_dependency(
+  include_directories: libbej_incs,
+  link_with: libbej_lib
+)
diff --git a/src/rde_common.c b/src/rde_common.c
new file mode 100644
index 0000000..258a543
--- /dev/null
+++ b/src/rde_common.c
@@ -0,0 +1,25 @@
+#include "rde_common.h"
+
+uint64_t rdeGetUnsignedInteger(const uint8_t* bytes, uint8_t numOfBytes)
+{
+    uint64_t num = 0;
+    for (uint8_t i = 0; i < numOfBytes; ++i)
+    {
+        num |= (uint64_t)(*(bytes + i)) << (i * 8);
+    }
+    return num;
+}
+
+uint64_t rdeGetNnint(const uint8_t* nnint)
+{
+    // In nnint, first byte indicate how many bytes are there. Remaining bytes
+    // represent the value in little-endian format.
+    const uint8_t size = *nnint;
+    return rdeGetUnsignedInteger(nnint + sizeof(uint8_t), size);
+}
+
+uint8_t rdeGetNnintSize(const uint8_t* nnint)
+{
+    // In nnint, first byte indicate how many bytes are there.
+    return *nnint + sizeof(uint8_t);
+}
diff --git a/test/meson.build b/test/meson.build
new file mode 100644
index 0000000..a775a0c
--- /dev/null
+++ b/test/meson.build
@@ -0,0 +1,26 @@
+gtest = dependency('gtest', main: true, disabler: true, required: get_option('tests'))
+gmock = dependency('gmock', disabler: true, required: get_option('tests'))
+
+if not gtest.found() or not gmock.found()
+  gtest_proj = import('cmake').subproject('googletest', required: false)
+  if gtest_proj.found()
+    gtest = declare_dependency(
+      dependencies: [
+        gtest_proj.dependency('gtest'),
+        gtest_proj.dependency('gtest_main'),
+      ])
+    gmock = gtest_proj.dependency('gmock')
+  else
+    assert(not get_option('tests').enabled(), 'Googletest is required')
+  endif
+endif
+
+gtests = [
+  'rde_common',
+]
+foreach t : gtests
+  test(t, executable(t.underscorify(), t + '_test.cpp',
+                     build_by_default: false,
+                     implicit_include_directories: false,
+                     dependencies: [libbej, gtest, gmock]))
+endforeach
diff --git a/test/rde_common_test.cpp b/test/rde_common_test.cpp
new file mode 100644
index 0000000..3217ffd
--- /dev/null
+++ b/test/rde_common_test.cpp
@@ -0,0 +1,39 @@
+#include "rde_common.h"
+
+#include <gmock/gmock-matchers.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+namespace rde
+{
+
+TEST(RdeCommonTest, RdeGetUnsignedIntegerTest)
+{
+    constexpr uint8_t bytes[] = {0xab, 0xcd, 0xef, 0x12,
+                                 0x13, 0x65, 0x23, 0x89};
+    EXPECT_THAT(rdeGetUnsignedInteger(bytes, /*numOfBytes=*/1), 0xab);
+    EXPECT_THAT(rdeGetUnsignedInteger(bytes, /*numOfBytes=*/2), 0xcdab);
+    EXPECT_THAT(rdeGetUnsignedInteger(bytes, /*numOfBytes=*/5), 0x1312efcdab);
+    EXPECT_THAT(rdeGetUnsignedInteger(bytes, /*numOfBytes=*/8),
+                0x8923651312efcdab);
+}
+
+TEST(RdeCommonTest, RdeGetNnintTest)
+{
+    constexpr uint8_t nnint1[] = {0x03, 0xcd, 0xef, 0x12};
+    constexpr uint8_t nnint2[] = {0x08, 0xab, 0xcd, 0xef, 0x12,
+                                  0x13, 0x65, 0x23, 0x89};
+    EXPECT_THAT(rdeGetNnint(nnint1), 0x12efcd);
+    EXPECT_THAT(rdeGetNnint(nnint2), 0x8923651312efcdab);
+}
+
+TEST(RdeCommonTest, RdeGetNnintSizeTest)
+{
+    constexpr uint8_t nnint1[] = {0x03, 0xcd, 0xef, 0x12};
+    constexpr uint8_t nnint2[] = {0x08, 0xab, 0xcd, 0xef, 0x12,
+                                  0x13, 0x65, 0x23, 0x89};
+    EXPECT_THAT(rdeGetNnintSize(nnint1), 4);
+    EXPECT_THAT(rdeGetNnintSize(nnint2), 9);
+}
+
+} // namespace rde