| //+------------------------------------------------------------------+
|
| //| 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\\JsonNode.mqh"
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| class CTestStream : public TSN::ITsnJsonParserStream
|
| {
|
| 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: ", m_ctx.Unescape(s, s + len - 1)); }
|
| 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: ", m_ctx.Unescape(s, s + len - 1)); }
|
| };
|
|
|
| //+------------------------------------------------------------------+
|
| //| 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\":10.05,\"a\":true,\"invalid\":\"\\xFF\",\"precios\":[10,20,30,40,50],\"va\":1"
|
| ",\"interpolado\":\"${{valor}}\"}";
|
| uchar raw[];
|
| const int l = StringToCharArray(json, raw);
|
| int p = 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..
|
| stream.ParseSreamSax();
|
| // Aqui por ejemplo se peuden hacer mas cosas.. tu lo llamas cuando quieres
|
| p += 64; // ya le dimos 64
|
| }
|
| }
|
| //+------------------------------------------------------------------+
|