Encode bejArray, bejNull, bejInteger and bejEnum
Signed-off-by: Kasun Athukorala <kasunath@google.com>
Change-Id: I2b851be69b51fe95a14287d1ca5f94ffcf757d0f
diff --git a/src/bej_encoder_core.c b/src/bej_encoder_core.c
index e289032..a4ca935 100644
--- a/src/bej_encoder_core.c
+++ b/src/bej_encoder_core.c
@@ -47,6 +47,65 @@
}
/**
+ * @brief Encode an integer to bejInteger type.
+ */
+static uint8_t bejEncodeInteger(int64_t val,
+ struct BejEncoderOutputHandler* output)
+{
+ uint8_t copyLength = bejIntLengthOfValue(val);
+ return output->recvOutput(&val, copyLength, output->handlerContext);
+}
+
+/**
+ * @brief Encode a BejInteger type.
+ */
+int bejEncodeBejInteger(struct RedfishPropertyLeafInt* node,
+ struct BejEncoderOutputHandler* output)
+{
+ // Encode Sequence number.
+ RETURN_IF_IERROR(
+ bejEncodeNnint(node->leaf.metaData.sequenceNumber, output));
+ // Add the format.
+ RETURN_IF_IERROR(bejEncodeFormat(&node->leaf.nodeAttr.format, output));
+ // Encode the value length.
+ RETURN_IF_IERROR(bejEncodeNnint(node->leaf.metaData.vSize, output));
+ // Encode the value.
+ return bejEncodeInteger(node->value, output);
+}
+
+/**
+ * @brief Encode a BejEnum type.
+ */
+int bejEncodeBejEnum(struct RedfishPropertyLeafEnum* node,
+ struct BejEncoderOutputHandler* output)
+{
+ // S: Encode Sequence number.
+ RETURN_IF_IERROR(
+ bejEncodeNnint(node->leaf.metaData.sequenceNumber, output));
+ // F: Add the format.
+ RETURN_IF_IERROR(bejEncodeFormat(&node->leaf.nodeAttr.format, output));
+ // L: Encode the value length.
+ RETURN_IF_IERROR(bejEncodeNnint(node->leaf.metaData.vSize, output));
+ // V: Encode the value.
+ return bejEncodeNnint(node->enumValueSeq, output);
+}
+
+/**
+ * @brief Encode a BejNull type.
+ */
+int bejEncodeBejNull(struct RedfishPropertyLeafNull* node,
+ struct BejEncoderOutputHandler* output)
+{
+ // S: Encode Sequence number.
+ RETURN_IF_IERROR(
+ bejEncodeNnint(node->leaf.metaData.sequenceNumber, output));
+ // F: Add the format.
+ RETURN_IF_IERROR(bejEncodeFormat(&node->leaf.nodeAttr.format, output));
+ // L: Encode the value length.
+ return bejEncodeNnint(node->leaf.metaData.vSize, output);
+}
+
+/**
* @brief Encode the provided node.
*/
static int bejEncodeNode(void* node, struct BejEncoderOutputHandler* output)
@@ -57,6 +116,18 @@
case bejSet:
RETURN_IF_IERROR(bejEncodeBejSetOrArray(node, output));
break;
+ case bejArray:
+ RETURN_IF_IERROR(bejEncodeBejSetOrArray(node, output));
+ break;
+ case bejNull:
+ RETURN_IF_IERROR(bejEncodeBejNull(node, output));
+ break;
+ case bejInteger:
+ RETURN_IF_IERROR(bejEncodeBejInteger(node, output));
+ break;
+ case bejEnum:
+ RETURN_IF_IERROR(bejEncodeBejEnum(node, output));
+ break;
default:
fprintf(stderr, "Unsupported node type: %d\n",
nodeInfo->format.principalDataType);