90 lines
4.3 KiB
MQL5
90 lines
4.3 KiB
MQL5
//+------------------------------------------------------------------+
| |
//| SaxTest.mq5 |
| |
//| Copyright 2026, Niquel Mendoza |
| |
//| https://www.mql5.com |
| |
//+------------------------------------------------------------------+
| |
#property copyright "Copyright 2026, Niquel Mendoza"
| |
#property link "https://www.mql5.com"
| |
#property version "1.00"
| |
#property strict
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
#include "..\\Src\\Json.mqh"
| |
| |
//+------------------------------------------------------------------+
| |
//| |
| |
//+------------------------------------------------------------------+
| |
class CTestStream : public TSN::ITsnJsonParserStream
| |
{
| |
| |
private:
| |
string ToStr(const uchar& in[], int i, int len)
| |
{
| |
string str;
| |
return TSN::CJsonParser::MakeString(in, i, len, str) ? str : NULL;
| |
}
| |
| |
public:
| |
CTestStream(void) {}
| |
~CTestStream(void) {}
| |
| |
//---
| |
void OnStartDocument() override final { Print("Inicio de documento"); }
| |
void OnEndDocument() override final { Print("Fin de documento"); }
| |
void OnStartObj() override final { Print("Inicio de objeto: ", m_ctx.CurrentStack()); }
| |
void OnEndObJ() override final { Print("Fin de objeto: ", m_ctx.CurrentStack()); }
| |
void OnStartArr() override final { Print("Inicio de array: ", m_ctx.CurrentStack()); }
| |
void OnEndArr() override final { Print("Fin de array: ", m_ctx.CurrentStack()); }
| |
void OnInteger(long v) override final { Print("Numero: ", v); }
| |
void OnReal(double v) override final { Print("Real: ", v); }
| |
void OnString(int s, int len) override final { Print("Texto: ", ToStr(m_ctx.m_raw, s, len)); }
| |
void OnBool(bool v) override final { Print("Boleano: ", v); }
| |
void OnNull() override final { Print("Null"); }
| |
void OnKey(int s, int len) override final { Print("Clave: ", ToStr(m_ctx.m_raw, s, len)); }
| |
void OnError() { Print(EnumToString(m_ctx.LastErr())); }
| |
| |
void OnBigDecimal(int s, int len) override final { Print("Big decimal: ", CharArrayToString(m_ctx.m_raw, s, len)); }
| |
void OnBigInteger(int s, int len) override final { Print("Big integer: ", CharArrayToString(m_ctx.m_raw, s, len)); }
| |
};
| |
| |
//+------------------------------------------------------------------+
| |
//| Script program start function |
| |
//+------------------------------------------------------------------+
| |
void OnStart()
| |
{
| |
//---
| |
TSN::CJsonParserStream stream;
| |
stream.SetCaller(new CTestStream(), true);
| |
| |
//---
| |
string json = "{\"ae\":[[10,10],[20,20]],\"comida\":\"\\ud83d\\ude00\",\"trapo\":10e+2,\"a\":true,\"invalid\":\"☣\",\"precios\":[10,20,30,40,50],\"va\":1"
| |
",\"interpolado\":\"${{valor}}\"}";
| |
uchar raw[];
| |
const int l = StringToCharArray(json, raw, 0, WHOLE_ARRAY, CP_UTF8);
| |
int p = 0;
| |
//Print(CharArrayToString(raw));
| |
//Print(CharToString(raw[0]));
| |
| |
// Simular pasadas de 64 bytes
| |
while(p < l) // tien que ser menor, en un caso real quizas ahsta on end document
| |
{
| |
//--- le damos datos
| |
// Tambien antes de dar los datos odemos llamar a CheckLimpieza
| |
// Para que mueva pos a posicion 0 (reutlziacion) en caso se pueda si no seguir acomulando
| |
// Ahora en este caso vamos sumando dado que m_len neceista crecer.... luego quizas se le peude reinicar..
| |
stream.m_len += ArrayCopy(stream.m_raw, raw, stream.m_pos, p, 64); //
| |
// intermante va parseando aumentado m_pos
| |
// Otro si no da el documento para otro el bulce se dentecia aunqeu array copy ya menaja eso intemante
| |
// si nos pamaos normaliza asi que no hay problema pero eso un aviso..
| |
if(!stream.ParseSreamSax())
| |
{
| |
Print("Error");
| |
return;
| |
}
| |
// Aqui por ejemplo se peuden hacer mas cosas.. tu lo llamas cuando quieres
| |
p += 64; // ya le dimos 64
| |
}
| |
}
| |
//+------------------------------------------------------------------+
|