2026-06-02 21:23:50 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| JsonNode.mqh |
|
| | | //| Copyright 2026, Niquel Mendoza. |
|
| | | //| https://www.mql5.com/ |
|
| | | //+------------------------------------------------------------------+
|
| | | #property copyright "Copyright 2026, Niquel Mendoza."
|
| | | #property link "https://www.mql5.com/"
|
| | | #property strict
|
| | |
|
2026-06-02 22:52:39 -05:00 | | | #ifndef JSONPARSERBYLEO_SRC_JSONNODE_MQH
|
| | | #define JSONPARSERBYLEO_SRC_JSONNODE_MQH
|
| | |
|
2026-06-02 21:23:50 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-10-01 13:36:22 -05:00 | | | #include "JsonUnescape.mqh"
|
2026-07-19 18:32:50 -05:00 | | | #include "JsonDomSerializer.mqh"
|
2026-07-27 08:40:51 -05:00 | | |
|
2026-06-02 21:23:50 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | namespace TSN
|
| | | {
|
2026-09-23 15:25:08 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-07-19 07:41:52 -05:00 | | | // Layour de los demas en repo base
|
2026-06-02 22:52:39 -05:00 | | | // Layout cinta:
|
2026-06-04 11:36:42 -05:00 | | | // NULL 1 pos [tipo(4)]
|
2026-09-23 15:25:08 -05:00 | | | // Array y obj tambien tine un slot mas (para el stirng raw..)
|
2026-06-02 21:23:50 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-07-27 08:40:51 -05:00 | | | #define CJsonIteratorArray TSN::CNodeBaseIteradorArray<TSN::CJsonParser, TSN::CJsonNode>
|
| | | #define CJsonIteratorArrayFast TSN::CNodeBaseIteradorArrayFast<TSN::CJsonParser, TSN::CJsonNode>
|
| | | #define CJsonIteratorObj TSN::CNodeBaseIteratorObj<TSN::CJsonParser, TSN::CJsonNode>
|
2026-06-02 21:23:50 -05:00 | | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-07-26 16:46:05 -05:00 | | | struct CJsonNode : CNodeSFLBase<CJsonParser, ENUM_JSON_VTYPE, CJsonNode>
|
2026-06-02 21:23:50 -05:00 | | | {
|
2026-06-02 22:52:39 -05:00 | | | public:
|
2026-06-02 21:23:50 -05:00 | | | //---
|
| | | CJsonNode()
|
2026-07-26 16:46:05 -05:00 | | | : CNodeSFLBase<CJsonParser, ENUM_JSON_VTYPE, CJsonNode>(NULL, -1, -1, -1) {}
|
2026-09-23 15:25:08 -05:00 | | | //--- Resuelve m_node_pos una unica vez aqui
|
2026-06-02 21:23:50 -05:00 | | | CJsonNode(CJsonParser* _ctx, const int _idx, const int _end)
|
2026-07-26 16:46:05 -05:00 | | | : CNodeSFLBase<CJsonParser, ENUM_JSON_VTYPE, CJsonNode>(_ctx, _idx, _end, NODEBASEF_RES_BASE(_ctx, _idx)) {}
|
2026-06-21 20:08:59 -05:00 | | |
|
2026-06-23 08:02:37 -05:00 | | | CJsonNode(CJsonParser* _ctx, const int _idx)
|
2026-07-26 16:46:05 -05:00 | | | : CNodeSFLBase<CJsonParser, ENUM_JSON_VTYPE, CJsonNode>(_ctx, _idx, _idx + _ctx.GetStep(_idx), NODEBASEF_RES_BASE(_ctx, _idx)) {}
|
| | |
|
| | | // Exclusivo de copia (Aqui NO RESUELVE NADA NI GET STE NI NADA) (constructor de clonacion)
|
| | | CJsonNode(CJsonParser* _ctx, const int _idx, const int _end, const int _node_pos)
|
| | | : CNodeSFLBase<CJsonParser, ENUM_JSON_VTYPE, CJsonNode>(_ctx, _idx, _end, _node_pos) {}
|
| | |
|
2026-06-02 21:23:50 -05:00 | | |
|
2026-06-02 22:52:39 -05:00 | | | //--- Acceso
|
2026-06-20 13:57:50 -05:00 | | | CJsonNode operator[](const string& key);
|
2026-06-23 08:02:37 -05:00 | | |
|
| | | //--- String
|
2026-06-02 22:52:39 -05:00 | | | string ToString(const string def = "") const;
|
2026-09-23 15:25:08 -05:00 | | | __forceinline int ToStringUArray(uchar& data[]) const;
|
| | | __forceinline string ToStringNoEscape(const string def = "", uint cp = CP_UTF8) const;
|
| | | __forceinline int ToStringUArrayNoEscape(uchar& data[]) const;
|
| | | __forceinline int StrLenRaw() const;
|
| | | __forceinline int StrStart() const;
|
2026-07-10 13:17:36 -05:00 | | |
|
2026-07-19 07:41:52 -05:00 | | | //---
|
2026-09-23 15:25:08 -05:00 | | | string ComplexToString(bool clean, uint cp = CP_ACP) const;
|
2026-07-19 07:41:52 -05:00 | | | int ComplexToData(uchar& data[], bool clean, int dst_start = 0, bool ajustar_arr = true) const;
|
| | |
|
2026-09-30 07:39:54 -05:00 | | | //---
|
| | | //- UInt
|
| | | long ToUInt(const ulong def) const;
|
| | | bool ToUIntSafe(ulong& val) const;
|
| | |
|
| | | //- Int
|
2026-06-02 22:52:39 -05:00 | | | long ToInt(const long def) const;
|
| | | bool ToIntSafe(long& val) const;
|
2026-06-23 08:02:37 -05:00 | | |
|
2026-09-30 07:39:54 -05:00 | | | //- Double
|
2026-06-02 22:52:39 -05:00 | | | double ToDouble(const double def) const;
|
| | | bool ToDoubleSafe(double& val) const;
|
2026-06-23 08:02:37 -05:00 | | |
|
2026-07-27 08:40:51 -05:00 | | | //--- MqlParam
|
| | | bool ToMqlParam(MqlParam& param, const ENUM_DATATYPE type) const;
|
| | |
|
2026-06-02 22:52:39 -05:00 | | | //--- Is
|
2026-09-23 15:25:08 -05:00 | | | __forceinline bool IsNull() const;
|
2026-06-02 22:52:39 -05:00 | | |
|
| | | //--- Navegacion raw
|
2026-07-26 16:46:05 -05:00 | | | static const CJsonNode EMPTY_NODE;
|
2026-07-27 16:07:47 -05:00 | | | static void OnMute(CNodeSFLBase<CJsonParser, ENUM_JSON_VTYPE, CJsonNode>& node);
|
2026-06-02 21:23:50 -05:00 | | | };
|
| | |
|
2026-07-27 08:40:51 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
2026-07-26 16:46:05 -05:00 | | | const CJsonNode CJsonNode::EMPTY_NODE;
|
2026-07-24 14:20:14 -05:00 | | |
|
2026-06-02 21:23:50 -05:00 | | | //+------------------------------------------------------------------+
|
2026-07-27 16:07:47 -05:00 | | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | static void CJsonNode::OnMute(CNodeSFLBase<CJsonParser, ENUM_JSON_VTYPE, CJsonNode> &node)
|
| | | {
|
| | | node.RecalcNodePos(); // Posicion...
|
| | | node.m_end = node.m_idx + node.m_ctx.GetStep(node.m_idx); // Calculamos el fin...
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-07-27 08:40:51 -05:00 | | | //| To MqlParam |
|
| | | //+------------------------------------------------------------------+
|
| | | bool CJsonNode::ToMqlParam(MqlParam& param, const ENUM_DATATYPE type) const
|
| | | {
|
| | | //---
|
| | | // Si no es un tipo de data valido salimos
|
2026-09-30 07:39:54 -05:00 | | | if(NODEBASE_IS_NOT_VALID_F ||
|
| | | CJsonParser::s_dtype_to_str[uchar(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE)].Length() == 0)
|
2026-07-27 08:40:51 -05:00 | | | return false;
|
| | |
|
| | | //---
|
| | | param.type = type;
|
| | |
|
| | | //---
|
| | | switch(type)
|
| | | {
|
| | | case TYPE_BOOL:
|
| | | param.integer_value = ToBool(false);
|
| | | break;
|
| | | case TYPE_CHAR:
|
| | | param.integer_value = char(ToInt(0));
|
| | | break;
|
| | | case TYPE_UCHAR:
|
| | | param.integer_value = uchar(ToInt(0));
|
| | | break;
|
| | | case TYPE_SHORT:
|
| | | param.integer_value = short(ToInt(0));
|
| | | break;
|
| | | case TYPE_USHORT:
|
| | | param.integer_value = ushort(ToInt(0));
|
| | | break;
|
| | | case TYPE_COLOR:
|
| | | param.integer_value = long(color(ToString("")));
|
| | | break;
|
| | | case TYPE_INT:
|
| | | param.integer_value = int(ToInt(0));
|
| | | break;
|
| | | case TYPE_UINT:
|
| | | param.integer_value = uint(ToInt(0));
|
| | | break;
|
| | | case TYPE_DATETIME:
|
| | | param.integer_value = long(datetime(ToString("")));
|
| | | break;
|
| | | case TYPE_LONG:
|
| | | case TYPE_ULONG:
|
2026-09-30 07:39:54 -05:00 | | | param.integer_value = ToInt(0);
|
2026-07-27 08:40:51 -05:00 | | | break;
|
| | | case TYPE_FLOAT:
|
| | | param.double_value = float(ToInt(0));
|
| | | break;
|
| | | case TYPE_DOUBLE:
|
| | | param.double_value = double(ToInt(0));
|
| | | break;
|
| | | case TYPE_STRING:
|
| | | param.string_value = ToString("");
|
| | | break;
|
| | | default:
|
| | | param.string_value = ToString("");
|
| | | break;
|
| | | }
|
| | |
|
| | | //---
|
| | | return true;
|
| | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-06-03 07:50:45 -05:00 | | | //| |
|
2026-06-02 21:23:50 -05:00 | | | //+------------------------------------------------------------------+
|
2026-09-23 15:25:08 -05:00 | | | string CJsonNode::ComplexToString(bool clean, uint cp = CP_ACP) const
|
2026-06-03 12:20:23 -05:00 | | | {
|
2026-07-19 07:41:52 -05:00 | | | if(NODEBASE_IS_NOT_VALID_F || ((1 << int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE)) & (TSN_SBL_BASE_F_OBJ | TSN_SBL_BASE_F_ARR)) == 0)
|
2026-06-03 12:20:23 -05:00 | | | return "";
|
| | |
|
| | | //---
|
2026-09-25 08:00:04 -05:00 | | | const int start = int(m_ctx.m_cinta[m_idx + 1] & TSN_JSON_BIT_RAW_MASK_S);
|
2026-06-03 12:20:23 -05:00 | | | const int end = int(m_ctx.m_cinta[m_idx + 1] >> TSN_JSON_BIT_END_T);
|
2026-09-23 15:25:08 -05:00 | | | return clean ? m_ctx.CleanNode(start, end) : CharArrayToString(m_ctx.m_raw, start, (end - start) + 1, cp);
|
2026-06-03 12:20:23 -05:00 | | | }
|
| | |
|
2026-06-03 16:57:42 -05:00 | | | //+------------------------------------------------------------------+
|
2026-07-15 17:58:56 -05:00 | | | int CJsonNode::ComplexToData(uchar &data[], bool clean, int dst_start = 0, bool ajustar_arr = true) const
|
2026-06-03 16:57:42 -05:00 | | | {
|
2026-07-19 07:41:52 -05:00 | | | if(NODEBASE_IS_NOT_VALID_F || ((1 << int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE)) & (TSN_SBL_BASE_F_OBJ | TSN_SBL_BASE_F_ARR)) == 0)
|
2026-06-03 16:57:42 -05:00 | | | return 0;
|
| | |
|
| | | //---
|
2026-09-25 08:00:04 -05:00 | | | const int start = int(m_ctx.m_cinta[m_idx + 1] & TSN_JSON_BIT_RAW_MASK_S);
|
2026-06-03 16:57:42 -05:00 | | | const int end = int(m_ctx.m_cinta[m_idx + 1] >> TSN_JSON_BIT_END_T);
|
2026-07-15 17:58:56 -05:00 | | | return clean ? m_ctx.CleanNode(start, end, data, dst_start, ajustar_arr) :
|
2026-07-19 07:41:52 -05:00 | | | ArrayCopy(data, m_ctx.m_raw, dst_start, start, (end - start) + 1);
|
2026-06-20 13:57:50 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
| | | //| |
|
| | | //+------------------------------------------------------------------+
|
| | | CJsonNode CJsonNode::operator[](const string& key)
|
2026-06-02 21:23:50 -05:00 | | | {
|
2026-06-02 22:52:39 -05:00 | | | //---
|
2026-07-19 07:41:52 -05:00 | | | if(NODEBASE_IS_NOT_VALID_F || int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE) != JSON_VTYPE_OBJ)
|
2026-07-26 16:46:05 -05:00 | | | return EMPTY_NODE;
|
2026-06-02 22:52:39 -05:00 | | |
|
2026-09-25 08:00:04 -05:00 | | | //--- primero vemos si hay o no hash
|
| | | if(m_node_pos != -1)
|
2026-06-02 22:52:39 -05:00 | | | {
|
2026-09-25 08:00:04 -05:00 | | | const int pos = m_ctx.PerfectHashComputeHash(key, m_node_pos);
|
| | | return pos == -1 ? EMPTY_NODE : CJsonNode(m_ctx, pos + 1);
|
| | | }
|
| | |
|
| | | //--- No esta hasheado..
|
| | | //--- Verificamos si vale la pena hashear este nodo o no
|
| | | const long v = m_ctx.m_cinta[m_idx];
|
| | | const int num_el = int((v >> TSN_SBL_BIT_START_NUM_EL) & TSN_SBL_BIT_MASK_NUM_EL);
|
| | | if(num_el >= TSN_NODEBASEREAD_MIN_JIT_VALUES_TO_HASH) // como minimo buscamores esos elementos
|
| | | {
|
| | | int c = int(v >> TSN_SBL_BIT_START_NUM_C_HASH) & TSN_SBL_BIT_MASK_NUM_C_HASH;
|
2026-07-26 18:16:21 -05:00 | | | if(c >= TSN_NODEBASEREAD_MIN_JIT_ATTEMPS_TO_PHASH) // Veriricamos si supero
|
2026-06-02 22:52:39 -05:00 | | | {
|
2026-09-25 08:00:04 -05:00 | | | if(m_ctx.NodeHashing(m_idx, num_el, m_end, m_node_pos))
|
2026-06-20 13:57:50 -05:00 | | | {
|
2026-09-25 08:00:04 -05:00 | | | m_ctx.m_cinta[m_idx] |= (1LL << TSN_SBL_BIT_START_IS_HASING);
|
| | | const int pos = m_ctx.PerfectHashComputeHash(key, m_node_pos);
|
| | | return pos == -1 ? EMPTY_NODE : CJsonNode(m_ctx, pos + 1);
|
2026-06-20 13:57:50 -05:00 | | | }
|
| | | c = 0;
|
2026-06-02 22:52:39 -05:00 | | | }
|
2026-06-20 13:57:50 -05:00 | | | else
|
| | | c++;
|
2026-06-02 22:52:39 -05:00 | | |
|
2026-09-25 08:00:04 -05:00 | | | //---
|
| | | m_ctx.m_cinta[m_idx] = (v & TSN_SBL_CCLEAN_MASK_JIT_TRY) | (c << TSN_SBL_BIT_START_NUM_C_HASH);
|
2026-06-02 22:52:39 -05:00 | | | }
|
| | |
|
2026-09-25 08:00:04 -05:00 | | | //--- En caso aun estemos porbando o no vale la pena.. entonces lineal..
|
| | | int cur = m_idx + 2;
|
| | | while(cur < m_end)
|
2026-06-24 17:20:42 -05:00 | | | {
|
2026-09-25 08:00:04 -05:00 | | | if(int(m_ctx.m_cinta[cur] & TSN_SBL_BIT_MASK_TYPE) != JSON_VTYPE_KEY)
|
| | | {
|
| | | cur += m_ctx.GetStep(cur);
|
| | | continue;
|
| | | }
|
| | | if(m_ctx.KeysEqual(key, cur))
|
| | | return CJsonNode(m_ctx, cur + 1);
|
| | | //---
|
| | | cur++; // salta KEY
|
| | | cur += m_ctx.GetStep(cur); // salta VAL
|
2026-06-24 17:20:42 -05:00 | | | }
|
2026-09-25 08:00:04 -05:00 | | | //---
|
| | | return EMPTY_NODE;
|
2026-06-02 22:52:39 -05:00 | | | }
|
| | |
|
2026-06-03 16:57:42 -05:00 | | | //+------------------------------------------------------------------+
|
2026-06-23 08:02:37 -05:00 | | | //| String |
|
2026-06-02 22:52:39 -05:00 | | | //+------------------------------------------------------------------+
|
| | | string CJsonNode::ToString(const string def = "") const
|
| | | {
|
2026-06-26 17:53:09 -05:00 | | | //---
|
2026-07-19 07:41:52 -05:00 | | | if(NODEBASE_IS_NOT_VALID_F)
|
2026-06-26 17:53:09 -05:00 | | | return def;
|
| | |
|
2026-06-02 22:52:39 -05:00 | | | //---
|
2026-07-19 07:41:52 -05:00 | | | switch(int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE))
|
2026-06-02 22:52:39 -05:00 | | | {
|
2026-09-30 07:39:54 -05:00 | | | case JSON_VTYPE_UINTEGER:
|
| | | return CValueToBuffer::ULLToStr(ulong(m_ctx.m_cinta[m_idx + 1]));
|
2026-06-02 22:52:39 -05:00 | | | case JSON_VTYPE_INTEGER:
|
| | | return string(m_ctx.m_cinta[m_idx + 1]);
|
| | | case JSON_VTYPE_REAL:
|
2026-07-26 16:46:05 -05:00 | | | {
|
2026-08-28 08:28:32 -05:00 | | | TsnBitInterprete un;
|
2026-07-26 16:46:05 -05:00 | | | un.long_value = m_ctx.m_cinta[m_idx + 1];
|
| | | return string(un.double_value);
|
| | | }
|
2026-06-02 22:52:39 -05:00 | | | case JSON_VTYPE_BOOLEAN:
|
2026-07-19 07:41:52 -05:00 | | | return ((m_ctx.m_cinta[m_idx] >> TSN_SBL_BIT_START_ENDTYPE) & 1) != 0 ? "true" : "false";
|
2026-06-02 22:52:39 -05:00 | | | case JSON_VTYPE_STRING:
|
2026-10-01 08:25:33 -05:00 | | | {
|
2026-10-03 17:00:34 -05:00 | | | static string res;
|
2026-10-01 08:25:33 -05:00 | | | return CJsonParser::MakeString(m_ctx.m_raw, TSN_SBL_CNG_STR_START(m_idx), TSN_SBL_CNG_STR_LEN(m_idx), res) ? res : def;
|
| | | }
|
2026-09-23 15:25:08 -05:00 | | | default:
|
| | | return def;
|
2026-06-02 22:52:39 -05:00 | | | }
|
| | | }
|
| | |
|
2026-07-10 13:17:36 -05:00 | | | //+------------------------------------------------------------------+
|
2026-09-23 15:25:08 -05:00 | | | __forceinline string CJsonNode::ToStringNoEscape(const string def = "", uint cp = CP_UTF8) const
|
2026-07-10 13:17:36 -05:00 | | | {
|
| | | //---
|
2026-07-19 07:41:52 -05:00 | | | if(NODEBASE_IS_NOT_VALID_F || int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE) != JSON_VTYPE_STRING)
|
2026-07-10 13:17:36 -05:00 | | | return def;
|
2026-09-23 15:25:08 -05:00 | | | return CharArrayToString(m_ctx.m_raw, TSN_SBL_CNG_STR_START(m_idx), TSN_SBL_CNG_STR_LEN(m_idx), cp);
|
2026-07-10 13:17:36 -05:00 | | | }
|
| | |
|
2026-06-23 08:02:37 -05:00 | | | //+------------------------------------------------------------------+
|
2026-10-01 08:25:33 -05:00 | | | // NOTA: funciones que trabajan con arrays retornan -1 en este caso como señal de falo.. no
|
| | | // hay def posible aqui
|
2026-09-23 15:25:08 -05:00 | | | __forceinline int CJsonNode::ToStringUArray(uchar & data[]) const
|
2026-06-23 08:02:37 -05:00 | | | {
|
| | | //---
|
2026-07-19 07:41:52 -05:00 | | | if(NODEBASE_IS_NOT_VALID_F || int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE) != JSON_VTYPE_STRING)
|
2026-10-01 08:25:33 -05:00 | | | return -1;
|
| | | return CJsonParser::MakeUArray(m_ctx.m_raw, TSN_SBL_CNG_STR_START(m_idx), TSN_SBL_CNG_STR_LEN(m_idx), data);
|
2026-06-23 08:02:37 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-23 15:25:08 -05:00 | | | __forceinline int CJsonNode::ToStringUArrayNoEscape(uchar &data[]) const
|
2026-06-23 08:02:37 -05:00 | | | {
|
| | | //---
|
2026-07-19 07:41:52 -05:00 | | | if(NODEBASE_IS_NOT_VALID_F || int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE) != JSON_VTYPE_STRING)
|
2026-10-01 08:25:33 -05:00 | | | return -1;
|
2026-09-23 15:25:08 -05:00 | | | return ArrayCopy(data, m_ctx.m_raw, 0, TSN_SBL_CNG_STR_START(m_idx), TSN_SBL_CNG_STR_LEN(m_idx));
|
2026-06-23 08:02:37 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-23 15:25:08 -05:00 | | | __forceinline int CJsonNode::StrLenRaw(void) const
|
2026-06-23 08:02:37 -05:00 | | | {
|
| | | //---
|
2026-07-19 07:41:52 -05:00 | | | if(NODEBASE_IS_NOT_VALID_F || int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE) != JSON_VTYPE_STRING)
|
2026-06-23 08:02:37 -05:00 | | | return 0;
|
2026-09-23 15:25:08 -05:00 | | | return TSN_SBL_CNG_STR_LEN(m_idx);
|
2026-06-23 08:02:37 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-09-23 15:25:08 -05:00 | | | __forceinline int CJsonNode::StrStart(void) const
|
2026-06-23 08:02:37 -05:00 | | | {
|
| | | //---
|
2026-07-19 07:41:52 -05:00 | | | if(NODEBASE_IS_NOT_VALID_F || int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE) != JSON_VTYPE_STRING)
|
2026-06-23 08:02:37 -05:00 | | | return 0;
|
2026-09-23 15:25:08 -05:00 | | | return TSN_SBL_CNG_STR_START(m_idx);
|
2026-06-23 08:02:37 -05:00 | | | }
|
2026-08-25 21:23:08 -05:00 | | |
|
2026-06-02 22:52:39 -05:00 | | | //+------------------------------------------------------------------+
|
2026-07-19 07:41:52 -05:00 | | | //| ToInt |
|
2026-06-02 22:52:39 -05:00 | | | //+------------------------------------------------------------------+
|
2026-07-19 07:41:52 -05:00 | | | long CJsonNode::ToInt(const long def) const
|
2026-06-02 22:52:39 -05:00 | | | {
|
| | | //---
|
2026-07-19 07:41:52 -05:00 | | | if(NODEBASE_IS_NOT_VALID_F)
|
| | | return def;
|
2026-06-02 22:52:39 -05:00 | | |
|
| | | //---
|
2026-07-19 07:41:52 -05:00 | | | switch(int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE))
|
| | | {
|
2026-09-30 07:39:54 -05:00 | | | case TSN_SBL_BASE_TYPE_UINT:
|
2026-07-19 07:41:52 -05:00 | | | case TSN_SBL_BASE_TYPE_INT:
|
| | | return m_ctx.m_cinta[m_idx + 1];
|
| | | case TSN_SBL_BASE_TYPE_FLT:
|
2026-07-26 16:46:05 -05:00 | | | {
|
2026-08-28 08:28:32 -05:00 | | | TsnBitInterprete un;
|
2026-07-26 16:46:05 -05:00 | | | un.long_value = m_ctx.m_cinta[m_idx + 1];
|
| | | return long(un.double_value);
|
| | | }
|
2026-07-19 07:41:52 -05:00 | | | case TSN_SBL_BASE_TYPE_BOL:
|
| | | return long((m_ctx.m_cinta[m_idx] >> TSN_SBL_BIT_START_ENDTYPE) & 1);
|
| | | case TSN_SBL_BASE_TYPE_STR:
|
2026-09-23 15:25:08 -05:00 | | | return long(CharArrayToString(m_ctx.m_raw, TSN_SBL_CNG_STR_START(m_idx), TSN_SBL_CNG_STR_LEN(m_idx)));
|
| | | default:
|
| | | return def;
|
2026-07-19 07:41:52 -05:00 | | | }
|
2026-06-21 20:08:59 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-07-19 07:41:52 -05:00 | | | bool CJsonNode::ToIntSafe(long & val) const
|
2026-06-21 20:08:59 -05:00 | | | {
|
| | | //---
|
2026-07-19 07:41:52 -05:00 | | | if(NODEBASE_IS_NOT_VALID_F)
|
2026-06-21 20:08:59 -05:00 | | | return false;
|
| | |
|
| | | //---
|
2026-07-19 07:41:52 -05:00 | | | switch(int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE))
|
| | | {
|
2026-09-30 07:39:54 -05:00 | | | case TSN_SBL_BASE_TYPE_UINT:
|
2026-07-19 07:41:52 -05:00 | | | case TSN_SBL_BASE_TYPE_INT:
|
| | | val = m_ctx.m_cinta[m_idx + 1];
|
| | | return true;
|
| | | case TSN_SBL_BASE_TYPE_FLT:
|
2026-07-26 16:46:05 -05:00 | | | {
|
2026-08-28 08:28:32 -05:00 | | | TsnBitInterprete un;
|
2026-07-26 16:46:05 -05:00 | | | un.long_value = m_ctx.m_cinta[m_idx + 1];
|
| | | val = long(un.double_value);
|
| | | return true;
|
| | | }
|
2026-07-19 07:41:52 -05:00 | | | case TSN_SBL_BASE_TYPE_BOL:
|
| | | val = long((m_ctx.m_cinta[m_idx] >> TSN_SBL_BIT_START_ENDTYPE) & 1);
|
| | | return true;
|
| | | case TSN_SBL_BASE_TYPE_STR:
|
2026-09-23 15:25:08 -05:00 | | | val = long(CharArrayToString(m_ctx.m_raw, TSN_SBL_CNG_STR_START(m_idx), TSN_SBL_CNG_STR_LEN(m_idx)));
|
2026-07-26 16:46:05 -05:00 | | | return true;
|
2026-09-23 15:25:08 -05:00 | | | default:
|
| | | return false;
|
2026-07-19 07:41:52 -05:00 | | | }
|
2026-06-21 20:08:59 -05:00 | | | }
|
| | |
|
2026-06-02 22:52:39 -05:00 | | | //+------------------------------------------------------------------+
|
2026-07-19 07:41:52 -05:00 | | | //| ToDouble |
|
2026-06-02 22:52:39 -05:00 | | | //+------------------------------------------------------------------+
|
2026-07-19 07:41:52 -05:00 | | | double CJsonNode::ToDouble(const double def) const
|
2026-06-02 22:52:39 -05:00 | | | {
|
2026-07-19 07:41:52 -05:00 | | | //---
|
| | | if(NODEBASE_IS_NOT_VALID_F)
|
| | | return def;
|
2026-06-02 22:52:39 -05:00 | | |
|
2026-07-19 07:41:52 -05:00 | | | //---
|
| | | switch(int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE))
|
| | | {
|
2026-09-30 07:39:54 -05:00 | | | case TSN_SBL_BASE_TYPE_UINT:
|
| | | return double(ulong(m_ctx.m_cinta[m_idx + 1]));
|
2026-07-19 07:41:52 -05:00 | | | case TSN_SBL_BASE_TYPE_INT:
|
| | | return double(m_ctx.m_cinta[m_idx + 1]);
|
| | | case TSN_SBL_BASE_TYPE_FLT:
|
2026-07-26 16:46:05 -05:00 | | | {
|
2026-08-28 08:28:32 -05:00 | | | TsnBitInterprete un;
|
2026-07-26 16:46:05 -05:00 | | | un.long_value = m_ctx.m_cinta[m_idx + 1];
|
| | | return un.double_value;
|
| | | }
|
2026-07-19 07:41:52 -05:00 | | | case TSN_SBL_BASE_TYPE_BOL:
|
| | | return double((m_ctx.m_cinta[m_idx] >> TSN_SBL_BIT_START_ENDTYPE) & 1);
|
| | | case TSN_SBL_BASE_TYPE_STR:
|
2026-09-23 15:25:08 -05:00 | | | return double(CharArrayToString(m_ctx.m_raw, TSN_SBL_CNG_STR_START(m_idx), TSN_SBL_CNG_STR_LEN(m_idx)));
|
| | | default:
|
| | | return def;
|
2026-07-19 07:41:52 -05:00 | | | }
|
2026-06-02 22:52:39 -05:00 | | | }
|
| | |
|
| | | //+------------------------------------------------------------------+
|
2026-07-19 07:41:52 -05:00 | | | bool CJsonNode::ToDoubleSafe(double & val) const
|
2026-06-02 22:52:39 -05:00 | | | {
|
2026-06-26 17:53:09 -05:00 | | | //---
|
2026-07-19 07:41:52 -05:00 | | | if(NODEBASE_IS_NOT_VALID_F)
|
2026-06-26 17:53:09 -05:00 | | | return false;
|
| | |
|
2026-06-02 22:52:39 -05:00 | | | //---
|
2026-07-19 07:41:52 -05:00 | | | switch(int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE))
|
| | | {
|
2026-09-30 07:39:54 -05:00 | | | case TSN_SBL_BASE_TYPE_UINT:
|
| | | val = double(ulong(m_ctx.m_cinta[m_idx + 1]));
|
| | | return true;
|
2026-07-19 07:41:52 -05:00 | | | case TSN_SBL_BASE_TYPE_INT:
|
| | | val = double(m_ctx.m_cinta[m_idx + 1]);
|
| | | return true;
|
| | | case TSN_SBL_BASE_TYPE_FLT:
|
2026-07-26 16:46:05 -05:00 | | | {
|
2026-08-28 08:28:32 -05:00 | | | TsnBitInterprete un;
|
2026-07-26 16:46:05 -05:00 | | | un.long_value = m_ctx.m_cinta[m_idx + 1];
|
| | | val = un.double_value;
|
| | | return true;
|
| | | }
|
2026-07-19 07:41:52 -05:00 | | | case TSN_SBL_BASE_TYPE_BOL:
|
| | | val = double((m_ctx.m_cinta[m_idx] >> TSN_SBL_BIT_START_ENDTYPE) & 1);
|
| | | return true;
|
| | | case TSN_SBL_BASE_TYPE_STR:
|
2026-09-23 15:25:08 -05:00 | | | val = double(CharArrayToString(m_ctx.m_raw, TSN_SBL_CNG_STR_START(m_idx), TSN_SBL_CNG_STR_LEN(m_idx)));
|
2026-07-26 16:46:05 -05:00 | | | return true;
|
2026-09-23 15:25:08 -05:00 | | | default:
|
| | | return false;
|
2026-07-19 07:41:52 -05:00 | | | }
|
| | | }
|
2026-06-21 20:08:59 -05:00 | | |
|
2026-07-19 07:41:52 -05:00 | | | //+------------------------------------------------------------------+
|
| | | //| Is |
|
| | | //+------------------------------------------------------------------+
|
| | | __forceinline bool CJsonNode::IsNull() const
|
| | | {
|
| | | return NODEBASE_IS_VALID && int(m_ctx.m_cinta[m_idx] & TSN_SBL_BIT_MASK_TYPE) == JSON_VTYPE_NULL;
|
2026-06-02 22:52:39 -05:00 | | | }
|
2026-06-02 21:23:50 -05:00 | | | }
|
| | | //+------------------------------------------------------------------+
|
2026-06-02 22:52:39 -05:00 | | | #endif // JSONPARSERBYLEO_SRC_JSONNODE_MQH
|