#include "bej_encoder_json.hpp" namespace libbej { bool stackEmpty(void* dataPtr) { return (reinterpret_cast*>(dataPtr))->empty(); } void* stackPeek(void* dataPtr) { auto stack = reinterpret_cast*>(dataPtr); if (stack->empty()) { return nullptr; } return stack->back(); } void* stackPop(void* dataPtr) { auto stack = reinterpret_cast*>(dataPtr); if (stack->empty()) { return nullptr; } void* value = stack->back(); stack->pop_back(); return value; } int stackPush(void* property, void* dataPtr) { auto stack = reinterpret_cast*>(dataPtr); stack->emplace_back(property); return 0; } int getBejEncodedBuffer(const void* data, size_t dataSize, void* handlerContext) { auto stack = reinterpret_cast*>(handlerContext); const uint8_t* dataBuf = reinterpret_cast(data); stack->insert(stack->end(), dataBuf, dataBuf + dataSize); return 0; } std::vector BejEncoderJson::getOutput() { std::vector currentEncodedPayload = std::move(encodedPayload); // Re-Initialize encodedPayload with empty vector to be used again for // next encoding encodedPayload = {}; return currentEncodedPayload; } int BejEncoderJson::encode(const struct BejDictionaries* dictionaries, enum BejSchemaClass schemaClass, struct RedfishPropertyParent* root) { struct BejEncoderOutputHandler output = { .handlerContext = &encodedPayload, .recvOutput = &getBejEncodedBuffer, }; struct BejPointerStackCallback stackCallbacks = { .stackContext = &stack, .stackEmpty = stackEmpty, .stackPeek = stackPeek, .stackPop = stackPop, .stackPush = stackPush, .deleteStack = nullptr, }; return bejEncode(dictionaries, BEJ_DICTIONARY_START_AT_HEAD, schemaClass, root, &output, &stackCallbacks); } } // namespace libbej