1 #pragma once
2 
3 #include "bej_common.h"
4 #include "bej_encoder_core.h"
5 
6 #include <vector>
7 
8 namespace libbej
9 {
10 
11 /**
12  * @brief Callback for stackEmpty. Check if stack is empty
13  *
14  * @param[in] dataPtr - pointer to a valid stack of type std::vector<void*>
15  * @return true if the stack is empty.
16  */
17 
18 bool stackEmpty(void* dataPtr);
19 
20 /**
21  * @brief Callback for stackPeek. Read the first element from the stack
22  *
23  * @param[in] dataPtr - pointer to a valid stack of type std::vector<void*>
24  * @return the value of first element in the stack
25  */
26 
27 void* stackPeek(void* dataPtr);
28 
29 /**
30  * @brief Callback for stackPop. Remove the top element from the stack.
31  *
32  * @param[in] dataPtr - pointer to a valid stack of type std::vector<void*>
33  * @return the value of first element in the stack
34  */
35 
36 void* stackPop(void* dataPtr);
37 
38 /**
39  * @brief Callback for stackPush. Push a new element to the top of the stack.
40  *
41  * @param[in] property - property to push.
42  * @param[in] dataPtr - pointer to a valid stack of type std::vector<void*>
43  * @return 0 if successful.
44  */
45 
46 int stackPush(void* property, void* dataPtr);
47 
48 /**
49  * @brief Callback to get the encoded json payload.
50  *
51  * @param[in] data - pointer to a valid stack of type std::vector<void*>
52  * @param[in] dataSize - size of the stack
53  * @param[in] handlerContext - Buffer to store the payload
54  * @return 0 if successful.
55  */
56 
57 int getBejEncodedBuffer(const void* data, size_t dataSize,
58                         void* handlerContext);
59 
60 /**
61  * @brief Class for encoding JSON input.
62  */
63 class BejEncoderJson
64 {
65   public:
66     /**
67      * @brief Encode the resource data.
68      *
69      * @param[in] dictionaries - dictionaries needed for encoding.
70      * @param[in] schemaClass - BEJ schema class.
71      * @param[in] root - pointer to a RedfishPropertyParent struct.
72      * @return 0 if successful.
73      */
74     int encode(const struct BejDictionaries* dictionaries,
75                enum BejSchemaClass schemaClass,
76                struct RedfishPropertyParent* root);
77 
78     /**
79      * @brief Get the JSON encoded payload.
80      *
81      * @return std::vector<uint8_t> containing encoded JSON bytes. If the
82      * encoding was unsuccessful, the vector will be empty. Note that the
83      * vector resource will be moved to the requester API
84      */
85     std::vector<uint8_t> getOutput();
86 
87   private:
88     std::vector<uint8_t> encodedPayload;
89     std::vector<void*> stack;
90 };
91 
92 } // namespace libbej
93