1
0
Fork 0
forked from lthn/blockchain

more consistent documentation code is working now

This commit is contained in:
cryptozoidberg 2024-03-23 15:45:24 +01:00
parent 256206af09
commit 60bb74cbb0
No known key found for this signature in database
GPG key ID: 2E10CC61CAC8F36D
7 changed files with 42 additions and 48 deletions

View file

@ -71,6 +71,17 @@ public: \
#define KV_SERIALIZE_N_DOC(varialble, val_name, substitute, description) \
epee::serialization::selector<is_store>::serialize(this_ref.varialble, stg, hparent_section, val_name, auto_doc_mode, substitute, description);
#define KV_SERIALIZE_N_DOC2(varialble, val_name) \
{using var_type = decltype(this_ref.varialble); epee::serialization::selector<is_store>::serialize(this_ref.varialble, stg, hparent_section, val_name, auto_doc_mode,
//substitute, description);
#define DOC_EXAMPLE(substitute) substitute,
#define DOC_EX(substitute__) var_type(substitute__),
#define DOC_DSCR(description) description); }
#define KV_SERIALIZE_CUSTOM_N(varialble, stored_type, from_v_to_stored, from_stored_to_v, val_name) \
epee::serialization::selector<is_store>::template serialize_custom<stored_type>(this_ref.varialble, stg, hparent_section, val_name, from_v_to_stored, from_stored_to_v);
@ -97,14 +108,20 @@ public: \
#define END_KV_SERIALIZE_MAP() return true;}
#define KV_SERIALIZE(varialble) KV_SERIALIZE_N(varialble, #varialble)
#define KV_SERIALIZE_DOC(varialble, substitute, description) KV_SERIALIZE_N_DOC( varialble, #varialble, substitute, description)
#define KV_SERIALIZE_VAL_POD_AS_BLOB(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_N(varialble, #varialble)
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, #varialble) //skip is_pod compile time check
#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB(varialble) KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(varialble, #varialble)
#define KV_SERIALIZE(varialble) KV_SERIALIZE_N(varialble, #varialble)
#define KV_SERIALIZE_DOC2(varialble) KV_SERIALIZE_N_DOC2( varialble, #varialble)
#define KV_SERIALIZE_DOC(varialble, substitute, description) KV_SERIALIZE_N_DOC( varialble, #varialble, substitute, description)
//#define KV_SERIALIZE_DOC(varialble, substitute, description) KV_SERIALIZE_N_DOC( varialble, #varialble, substitute, description)
#define KV_SERIALIZE_VAL_POD_AS_BLOB(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_N(varialble, #varialble)
#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(varialble) KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, #varialble) //skip is_pod compile time check
#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB(varialble) KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(varialble, #varialble)
#define KV_SERIALIZE_CUSTOM(varialble, stored_type, from_v_to_stored, from_stored_to_v) KV_SERIALIZE_CUSTOM_N(varialble, stored_type, from_v_to_stored, from_stored_to_v, #varialble)
#define KV_SERIALIZE_POD_AS_HEX_STRING(varialble) KV_SERIALIZE_POD_AS_HEX_STRING_N(varialble, #varialble)
#define KV_SERIALIZE_BLOB_AS_HEX_STRING(varialble) KV_SERIALIZE_BLOB_AS_HEX_STRING_N(varialble, #varialble)
#define KV_SERIALIZE_POD_AS_HEX_STRING(varialble) KV_SERIALIZE_POD_AS_HEX_STRING_N(varialble, #varialble)
#define KV_SERIALIZE_BLOB_AS_HEX_STRING(varialble) KV_SERIALIZE_BLOB_AS_HEX_STRING_N(varialble, #varialble)

View file

@ -479,6 +479,5 @@ namespace epee
return r;
}
}
}

View file

@ -29,7 +29,7 @@
#pragma once
#include "portable_storage.h"
#include "portable_storage.h"
#include "portable_storage_to_description.h"
namespace epee
@ -53,7 +53,7 @@ namespace epee
{
TRY_ENTRY();
std::stringstream ss;
epee::serialization::recursive_visitor<strategy_json>::dump_as_(ss, m_root, indent);
recursive_visitor<strategy_descriptin>::dump_as_(ss, m_root, indent);
buff = ss.str();
return true;
CATCH_ENTRY("portable_storage_base<t_section>::dump_as_json", false)

View file

@ -120,7 +120,7 @@ namespace epee
auto it_last = --sec.m_entries.end();
for (auto it = sec.m_entries.begin(); it != sec.m_entries.end(); it++)
{
if (constexpr t_strategy_layout_strategy::use_descriptions::value)
if constexpr (t_strategy_layout_strategy::use_descriptions::value)
{
std::string descr;
auto it_descr = sec.m_descriptions.find(it->first);

View file

@ -36,25 +36,11 @@ namespace epee
{
namespace serialization
{
inline const char* get_endline(end_of_line_t eol)
{
switch (eol)
{
case eol_lf: return "\n";
case eol_cr: return "\r";
case eol_space: return " ";
default: return "\r\n";
}
}
inline std::string make_indent(size_t indent)
{
return std::string(indent * 2, ' ');
}
class strategy_json
class strategy_descriptin
{
public:
using use_descriptions = std::true_type;
inline static const char* eol = get_endline(eol_crlf);
//static const end_of_line_t eol = eol_crlf;
@ -83,10 +69,10 @@ namespace epee
{}
template<class t_stream>
static void handle_print_key(t_stream& strm, const std::string& key, size_t indent)
static void handle_print_key(t_stream& strm, const std::string& key, const std::string& description, size_t indent)
{
const std::string indent_str = make_indent(indent);
strm << indent_str << "\"" << misc_utils::parse::transform_to_json_escape_sequence(key) << "\"" << ": ";
strm << indent_str << "\"" << key << "\"" << ": " << description;
}
template<class t_stream>

View file

@ -55,7 +55,7 @@ namespace epee
class strategy_json
{
public:
typedef std::false_type use_descriptions;
using use_descriptions = std::false_type;
inline static const char* eol = get_endline(eol_crlf);
//static const end_of_line_t eol = eol_crlf;
@ -109,15 +109,11 @@ namespace epee
template<class t_stream>
static void handle_obj_begin(t_stream& strm, size_t indent)
{
strm << "{";
}
{}
template<class t_stream>
static void handle_obj_end(t_stream& strm, size_t indent)
{
strm << "}";
}
{}
template<class t_stream>
static void handle_print_key(t_stream& strm, const std::string& key, size_t indent)
@ -129,15 +125,11 @@ namespace epee
template<class t_stream>
static void handle_section_entry_separator(t_stream& strm, size_t indent)
{
strm << ",";
}
{}
template<class t_stream>
static void handle_array_entry_separator(t_stream& strm, size_t indent)
{
strm << ",";
}
{}
template<class t_stream>
static void handle_line_break(t_stream& strm, size_t indent)

View file

@ -149,8 +149,8 @@ namespace currency
std::string status;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_DOC(height, uint64_t(11111), "Some height of the block")
KV_SERIALIZE_DOC(status, std::string("OK"), "Status of the operation")
KV_SERIALIZE_DOC2(height) DOC_EX(11111) DOC_DSCR("Some height of the block")
KV_SERIALIZE_DOC2(status) DOC_EX("OK") DOC_DSCR("Status of the operation")
END_KV_SERIALIZE_MAP()
};
};
@ -212,9 +212,9 @@ namespace currency
std::string status;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(txs_as_hex)
KV_SERIALIZE(missed_tx)
KV_SERIALIZE(status)
KV_SERIALIZE_DOC(txs_as_hex, std::list<std::string>(1, "97d91442f8f3c22683585eaa60b53757d49bf046a96269cef45c1bc9ff7300cc97d914497d91442f8f3c22683585eaa60b53757d49bf046a96269cef45c1bc9ff7300cc2f8f3c22683585eaa60b53757d49bf046a96269cef45c1bc9ff7300cc"), "Transactions stored as blobs")
KV_SERIALIZE_DOC(missed_tx, std::list<std::string>(1, "97d91442f8f3c22683585eaa60b53757d49bf046a96269cef45c1bc9ff7300cc"), "Missed transactions hashes")
KV_SERIALIZE_DOC(status, std::string("OK"), "Command response status")
END_KV_SERIALIZE_MAP()
};
};