Get metadata for bejNull type
Signed-off-by: Kasun Athukorala <kasunath@google.com>
Change-Id: I08d0c8f26e1ed64f67cfcf857fbdd8573dae75d4
diff --git a/include/libbej/bej_tree.h b/include/libbej/bej_tree.h
index 5b502db..32bf82c 100644
--- a/include/libbej/bej_tree.h
+++ b/include/libbej/bej_tree.h
@@ -98,6 +98,14 @@
};
/**
+ * @brief bejNull type property node.
+ */
+ struct RedfishPropertyLeafNull
+ {
+ struct RedfishPropertyLeaf leaf;
+ };
+
+ /**
* @brief bejInteger type property node.
*/
struct RedfishPropertyLeafInt
@@ -181,6 +189,17 @@
bool bejTreeIsParentType(struct RedfishPropertyNode* node);
/**
+ * @brief Initialize a bejNull type node.
+ *
+ * @param parent - a pointer to an initialized parent struct.
+ * @param child - a pointer to an uninitialized bejNull type node.
+ * @param name - name of the bejNull type property.
+ */
+ void bejTreeAddNull(struct RedfishPropertyParent* parent,
+ struct RedfishPropertyLeafNull* child,
+ const char* name);
+
+ /**
* @brief Add a bejInteger type node to a parent node.
*
* @param[in] parent - a pointer to an initialized parent struct.
diff --git a/src/bej_encoder_metadata.c b/src/bej_encoder_metadata.c
index 098c5e7..5e5ce23 100644
--- a/src/bej_encoder_metadata.c
+++ b/src/bej_encoder_metadata.c
@@ -390,6 +390,30 @@
return 0;
}
+static int bejUpdateNullMetaData(const struct BejDictionaries* dictionaries,
+ const uint8_t* parentDictionary,
+ struct RedfishPropertyLeafNull* node,
+ uint16_t nodeIndex,
+ uint16_t dictStartingOffset)
+{
+ uint32_t sequenceNumber;
+ RETURN_IF_IERROR(bejFindSeqNumAndChildDictOffset(
+ dictionaries, parentDictionary, &node->leaf.nodeAttr, nodeIndex,
+ dictStartingOffset, &sequenceNumber, NULL, NULL));
+ node->leaf.metaData.sequenceNumber = sequenceNumber;
+
+ // Calculate the size for encoding this in a SFLV tuple.
+ // S: Size needed for encoding sequence number.
+ node->leaf.metaData.sflSize = bejNnintEncodingSizeOfUInt(sequenceNumber);
+ // F: Size of the format byte is 1.
+ node->leaf.metaData.sflSize += BEJ_TUPLE_F_SIZE;
+ // L: Length needed for the value. Value length for NULL type is 0. So we
+ // need to encode [0x01 0x00]
+ node->leaf.metaData.sflSize += BEJ_TUPLE_L_SIZE_FOR_BEJ_INTEGER;
+ node->leaf.metaData.vSize = 0;
+ return 0;
+}
+
/**
* @brief Update metadata of leaf nodes.
*
@@ -436,6 +460,11 @@
bejUpdateBoolMetaData(dictionaries, parentDictionary, childPtr,
childIndex, dictStartingOffset));
break;
+ case bejNull:
+ RETURN_IF_IERROR(
+ bejUpdateNullMetaData(dictionaries, parentDictionary, childPtr,
+ childIndex, dictStartingOffset));
+ break;
default:
fprintf(stderr, "Child type %u not supported\n",
chNode->nodeAttr.format.principalDataType);
diff --git a/src/bej_tree.c b/src/bej_tree.c
index 53511eb..ff4a9a4 100644
--- a/src/bej_tree.c
+++ b/src/bej_tree.c
@@ -49,6 +49,13 @@
node->nodeAttr.sibling = NULL;
}
+void bejTreeAddNull(struct RedfishPropertyParent* parent,
+ struct RedfishPropertyLeafNull* child, const char* name)
+{
+ bejTreeInitChildNode((struct RedfishPropertyLeaf*)child, name, bejNull);
+ bejTreeLinkChildToParent(parent, child);
+}
+
void bejTreeAddInteger(struct RedfishPropertyParent* parent,
struct RedfishPropertyLeafInt* child, const char* name,
int64_t value)