blob: 14c2ce437a6c1be7b31023a5cd00d67373031262 [file] [log] [blame]
Harisuddin Mohamed Isa600d15a2019-12-20 12:42:26 +08001#pragma once
2
3#include <ctype.h>
4#include <stdio.h>
5
6#include <fstream>
7#include <iomanip>
8#include <iostream>
9#include <string>
10#include <vector>
11
12namespace openpower
13{
14namespace pels
15{
16const uint8_t indentLevel = 4;
17const uint8_t colAlign = 32;
18/**
19 * @brief escape json - use it for PEL hex dumps.
20 * @param[in] std::string - the unescaped JSON as a string literal
21 * @return std::string - escaped JSON string literal
22 */
23std::string escapeJSON(const std::string& input);
24
25/**
26 * @brief get hex dump for PEL section in json format.
27 * @param[in] const void* - Raw PEL data
28 * @param[i] size_t - size of Raw PEL
29 * @return char * - the Hex dump
30 */
31char* dumpHex(const void* data, size_t size);
32
33/**
34 * @brief Inserts key-value into a JSON string
35 *
36 * @param[in] jsonStr - The JSON string
37 * @param[in] fieldName - The JSON key to insert
38 * @param[in] fieldValue - The JSON value to insert
39 * @param[in] indentCount - Indent count for the line
40 */
41void jsonInsert(std::string& jsonStr, const std::string& fieldName,
42 std::string& fieldValue, uint8_t indentCount);
43
44/**
45 * @brief Inserts key-value array into a JSON string
46 *
47 * @param[in] jsonStr - The JSON string
48 * @param[in] fieldName - The JSON key to insert
49 * @param[in] values - The JSON array to insert
50 * @param[in] indentCount - Indent count for the line
51 */
52void jsonInsertArray(std::string& jsonStr, const std::string& fieldName,
53 std::vector<std::string>& values, uint8_t indentCount);
54} // namespace pels
55} // namespace openpower