public static TS2 BiserDecode(byte[] enc = null, Biser.Decoder extDecoder = null) //!!! change return type { Biser.Decoder decoder = null; if (extDecoder == null) { if (enc == null || enc.Length == 0) { return(null); } decoder = new Biser.Decoder(enc); if (decoder.CheckNull()) { return(null); } } else { if (extDecoder.CheckNull()) { return(null); } else { decoder = extDecoder; } //decoder = new Biser.Decoder(extDecoder); //if (decoder.IsNull) // return null; } TS2 m = new TS2(); //!!!!!!!!!!!!!! change return type m.P1 = decoder.GetLong(); m.P2 = decoder.GetDouble(); m.P3 = decoder.CheckNull() ? null : new List <TS3>(); if (m.P3 != null) { decoder.GetCollection(() => { return(TS3.BiserDecode(null, decoder)); }, m.P3, true); } m.P4 = TS3.BiserDecode(null, decoder); m.P5 = decoder.GetUInt_NULL(); return(m); }
public static TS3 BiserJsonDecode(string enc = null, Biser.JsonDecoder extDecoder = null, Biser.JsonSettings settings = null) //!!!!!!!!!!!!!! change return type { Biser.JsonDecoder decoder = null; if (extDecoder == null) { if (enc == null || String.IsNullOrEmpty(enc)) { return(null); } decoder = new Biser.JsonDecoder(enc, settings); if (decoder.CheckNull()) { return(null); } } else { //JSONSettings of the existing decoder will be used decoder = extDecoder; } TS3 m = new TS3(); //!!!!!!!!!!!!!! change return type foreach (var props in decoder.GetDictionary <string>()) { switch (props) { case "P1": m.P1 = decoder.GetString(); break; case "P2": m.P2 = decoder.GetInt_NULL(); break; case "P3": m.P3 = decoder.GetDateTime(); break; default: decoder.SkipValue(); //Must be here break; } } return(m); }//eof
public static TS3 BiserDecode(byte[] enc = null, Biser.Decoder extDecoder = null) //!!! change return type { Biser.Decoder decoder = null; if (extDecoder == null) { if (enc == null || enc.Length == 0) { return(null); } decoder = new Biser.Decoder(enc); if (decoder.CheckNull()) { return(null); } } else { if (extDecoder.CheckNull()) { return(null); } else { decoder = extDecoder; } //decoder = new Biser.Decoder(extDecoder); //if (decoder.IsNull) // return null; } TS3 m = new TS3(); //!!!!!!!!!!!!!! change return type m.P1 = decoder.GetString(); m.P2 = decoder.GetInt_NULL(); m.P3 = decoder.GetDateTime(); return(m); }//eof
public static TS2 BiserJsonDecode(string enc = null, Biser.JsonDecoder extDecoder = null, Biser.JsonSettings settings = null) //!!!!!!!!!!!!!! change return type { Biser.JsonDecoder decoder = null; if (extDecoder == null) { if (enc == null || String.IsNullOrEmpty(enc)) { return(null); } decoder = new Biser.JsonDecoder(enc, settings); if (decoder.CheckNull()) { return(null); } } else { //JSONSettings of the existing decoder will be used decoder = extDecoder; } TS2 m = new TS2(); //!!!!!!!!!!!!!! change return type foreach (var props in decoder.GetDictionary <string>()) { switch (props) { case "P1": m.P1 = decoder.GetLong(); break; case "P2": m.P2 = decoder.GetDouble(); break; case "P3": m.P3 = decoder.CheckNull() ? null : new List <TS3>(); if (m.P3 != null) { foreach (var el in decoder.GetList()) { m.P3.Add(TS3.BiserJsonDecode(null, decoder)); } } //decoder.GetCollection( // () => { return TS3.BiserJsonDecode(null, decoder); }, m.P3, true); break; case "P4": m.P4 = TS3.BiserJsonDecode(null, decoder); break; case "P5": m.P5 = decoder.GetUInt_NULL(); break; default: decoder.SkipValue(); //Must be here break; } } return(m); }//eof
public static TS1 BiserDecode(byte[] enc = null, Biser.Decoder extDecoder = null) //!!!!!!!!!!!!!! change return type { Biser.Decoder decoder = null; if (extDecoder == null) { if (enc == null || enc.Length == 0) { return(null); } decoder = new Biser.Decoder(enc); if (decoder.CheckNull()) { return(null); } } else { if (extDecoder.CheckNull()) { return(null); } else { decoder = extDecoder; } //decoder = new Biser.Decoder(extDecoder); //if (decoder.IsNull) // return null; } TS1 m = new TS1(); //!!!!!!!!!!!!!! change return type m.P1 = decoder.GetInt(); m.P2 = decoder.GetInt(); m.P3 = decoder.GetDecimal(); m.P4 = decoder.CheckNull() ? null : new List <TS2>(); if (m.P4 != null) { decoder.GetCollection(() => { return(TS2.BiserDecode(null, decoder)); }, m.P4, true); } m.P5 = decoder.CheckNull() ? null : new Dictionary <long, TS3>(); if (m.P5 != null) { decoder.GetCollection(() => { return(decoder.GetLong()); }, () => { return(TS3.BiserDecode(null, decoder)); }, m.P5, true); } m.P6 = decoder.CheckNull() ? null : new Dictionary <uint, List <TS3> >(); if (m.P6 != null) { decoder.GetCollection( () => { return(decoder.GetUInt()); }, () => { var iList = decoder.CheckNull() ? null : new List <TS3>(); if (iList != null) { decoder.GetCollection(() => { return(TS3.BiserDecode(extDecoder: decoder)); }, iList, true); } return(iList); }, m.P6, true); } m.P7 = TS2.BiserDecode(extDecoder: decoder); m.P8 = decoder.CheckNull() ? null : new List <Tuple <string, byte[], TS3> >(); if (m.P8 != null) { decoder.GetCollection (() => { return(new Tuple <string, byte[], TS3> (decoder.GetString(), decoder.GetByteArray(), TS3.BiserDecode(null, decoder))); }, m.P8, true); } m.P9 = new Tuple <float, TS2, TS3, decimal?> (decoder.GetFloat(), TS2.BiserDecode(null, decoder), TS3.BiserDecode(null, decoder), decoder.GetDecimal_NULL()); return(m); }
public static TS1 BiserJsonDecode(string enc = null, Biser.JsonDecoder extDecoder = null, Biser.JsonSettings settings = null) //!!!!!!!!!!!!!! change return type { Biser.JsonDecoder decoder = null; if (extDecoder == null) { if (enc == null || String.IsNullOrEmpty(enc)) { return(null); } decoder = new Biser.JsonDecoder(enc, settings); if (decoder.CheckNull()) { return(null); } } else { //JSONSettings of the existing decoder will be used decoder = extDecoder; } TS1 m = new TS1(); //!!!!!!!!!!!!!! change return type foreach (var props in decoder.GetDictionary <string>()) { switch (props) { case "P1": m.P1 = decoder.GetInt(); break; case "P2": m.P2 = decoder.GetInt(); break; case "P3": m.P3 = decoder.GetDecimal(); break; case "P4": m.P4 = decoder.CheckNull() ? null : new List <TS2>(); if (m.P4 != null) { foreach (var el in decoder.GetList()) { m.P4.Add(TS2.BiserJsonDecode(null, decoder)); } } break; case "P5": m.P5 = decoder.CheckNull() ? null : new Dictionary <long, TS3>(); if (m.P5 != null) { foreach (var el in decoder.GetDictionary <long>()) { m.P5.Add(el, TS3.BiserJsonDecode(null, decoder)); } } break; case "P6": m.P6 = decoder.CheckNull() ? null : new Dictionary <uint, List <TS3> >(); if (m.P6 != null) { foreach (var el in decoder.GetDictionary <uint>()) { var lst = decoder.CheckNull() ? null : new List <TS3>(); if (lst != null) { foreach (var el1 in decoder.GetList()) { lst.Add(TS3.BiserJsonDecode(null, decoder)); } } m.P6.Add(el, lst); } } break; case "P7": m.P7 = TS2.BiserJsonDecode(null, decoder); break; case "P8": m.P8 = decoder.CheckNull() ? null : new List <Tuple <string, byte[], TS3> >(); if (m.P8 != null) { Tuple <string, byte[], TS3> tpl = null; foreach (var el in decoder.GetList()) { //foreach (var el1 in decoder.GetList()) //Tuple was also represented as an array //{ // tpl = new Tuple<string, byte[], TS3>( // decoder.GetString(), // decoder.GetByteArray(), // TS3.BiserJsonDecode(null, decoder)); //}//must come to the end, no returns in the middle of iteration //Or Dictionary that is represented with Item1, item2, Item3 for compatibility with other systems string i1 = ""; byte[] i2 = null; TS3 i3 = null; foreach (var tupleProps in decoder.GetDictionary <string>()) { switch (tupleProps) { case "Item1": i1 = decoder.GetString(); break; case "Item2": i2 = decoder.GetByteArray(); break; case "Item3": i3 = TS3.BiserJsonDecode(null, decoder); break; default: decoder.SkipValue(); break; } } tpl = new Tuple <string, byte[], TS3>(i1, i2, i3); m.P8.Add(tpl); } } break; case "P9": if (decoder.CheckNull()) { m.P9 = null; } else { //foreach (var el in decoder.GetList()) //heterogenous array //{ // m.P9 = new Tuple<float, TS2, TS3, decimal?>(decoder.GetFloat(), // TS2.BiserJsonDecode(null, decoder), TS3.BiserJsonDecode(null, decoder), decoder.GetDecimal_NULL()); //} //Or Dictionary that is represented with Item1, item2, Item3, Item4 for compatibility with other systems float i1 = 0; TS2 i2 = null; TS3 i3 = null; decimal?i4 = null; foreach (var tupleProps in decoder.GetDictionary <string>()) { switch (tupleProps) { case "Item1": i1 = decoder.GetFloat(); break; case "Item2": i2 = TS2.BiserJsonDecode(null, decoder); break; case "Item3": i3 = TS3.BiserJsonDecode(null, decoder); break; case "Item4": i4 = decoder.GetDecimal_NULL(); break; default: decoder.SkipValue(); //must be here break; } } m.P9 = new Tuple <float, TS2, TS3, decimal?>(i1, i2, i3, i4); } break; case "P11": m.P11 = decoder.CheckNull() ? null : new Dictionary <int, int>(); if (m.P11 != null) { foreach (var el in decoder.GetDictionary <int>()) { m.P11.Add(el, decoder.GetInt()); } } break; case "P12": m.P12 = decoder.GetInt(); break; case "P13": m.P13 = decoder.CheckNull() ? null : new List <TS3>(); if (m.P13 != null) { foreach (var el in decoder.GetList()) { m.P13.Add(TS3.BiserJsonDecode(null, decoder)); } } break; case "P14": m.P14 = decoder.CheckNull() ? null : new Dictionary <int, int>(); if (m.P14 != null) { foreach (var el in decoder.GetDictionary <int>()) { m.P14.Add(el, decoder.GetInt()); } } break; case "P15": m.P15 = decoder.CheckNull() ? null : new List <List <TS3> >(); if (m.P15 != null) { foreach (var el in decoder.GetList()) { var lst = decoder.CheckNull() ? null : new List <TS3>(); if (lst != null) { foreach (var el1 in decoder.GetList()) { lst.Add(TS3.BiserJsonDecode(null, decoder)); } } m.P15.Add(lst); } } break; case "P16": m.P16 = decoder.CheckNull() ? null : new Dictionary <long, List <TS3> >(); if (m.P16 != null) { foreach (var el in decoder.GetDictionary <long>()) { var lst = decoder.CheckNull() ? null : new List <TS3>(); if (lst != null) { foreach (var el1 in decoder.GetList()) { lst.Add(TS3.BiserJsonDecode(null, decoder)); } } m.P16.Add(el, lst); } } break; case "P17": m.P17 = decoder.GetDateTime(); break; case "P18": m.P18 = decoder.CheckNull() ? null : new List <int>(); if (m.P18 != null) { foreach (var el in decoder.GetList()) { m.P18.Add(decoder.GetInt()); } } break; case "P19": if (decoder.CheckNull()) { m.P19 = null; } else { //When stored as List //foreach (var el in decoder.GetList()) //heterogenous array //{ // m.P19 = new Tuple<int, TS3>(decoder.GetInt(), TS3.BiserJsonDecode(null, decoder)); //} //Or Dictionary that is represented with Item1, item2, Item3 for compatibility with other systems int i1 = 0; TS3 i2 = null; foreach (var tupleProps in decoder.GetDictionary <string>()) { switch (tupleProps) { case "Item1": i1 = decoder.GetInt(); break; case "Item2": i2 = TS3.BiserJsonDecode(null, decoder); break; default: decoder.SkipValue(); break; } } m.P19 = new Tuple <int, TS3>(i1, i2); } break; default: decoder.SkipValue(); //must be here break; } } return(m); }
static void TestDecodeV1() { TS3 ts3 = new TS3() { P1 = "dsf", P2 = 45, P3 = DateTime.UtcNow }; var xl = new List <TS3>(); for (int i = 0; i < 10; i++) { xl.Add(ts3); } TS2 ts2 = new TS2() { P1 = 17, P2 = 45.7, //P3 = new List<TS3> { ts3, ts3 }, P3 = xl, P4 = ts3, P5 = 47 }; TS1 ts1 = new TS1() { P1 = 12, P2 = 17, P3 = 478.5879m, P4 = new List <TS2> { ts2, ts2 }, P5 = new Dictionary <long, TS3> { { 1, new TS3 { P1 = "t1" } }, { 2, new TS3 { P1 = "t2" } }, { 3, new TS3 { P1 = "t3" } } }, P6 = new Dictionary <uint, List <TS3> > { { 1, new List <TS3> { new TS3 { P1 = "h1" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h3", P3 = DateTime.UtcNow } } }, { 2, new List <TS3> { new TS3 { P1 = "h2" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h4" } } }, { 3, new List <TS3> { new TS3 { P1 = "h3" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h5" } } }, { 4, new List <TS3> { new TS3 { P1 = "h4" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h6" } } } }, P7 = new TS2 { P1 = -789 }, P8 = new List <Tuple <string, byte[], TS3> > { new Tuple <string, byte[], TS3>("tt1", new byte[] { 1, 2, 3 }, new TS3 { P1 = "z1" }), new Tuple <string, byte[], TS3>("tt2", new byte[] { 3, 2, 3 }, new TS3 { P1 = "z2" }), new Tuple <string, byte[], TS3>("tt3", new byte[] { 4, 2, 3 }, new TS3 { P1 = "z3" }), }, P9 = new Tuple <float, TS2, TS3, decimal?>(-.8f, new TS2 { P2 = 45 }, new TS3 { P2 = 12 }, -58.8m) }; var bt1 = new Biser.Encoder(ts1).Encode(); var ts1a = TS1.BiserDecode(bt1); var jsonSet = new JsonSettings() { DateFormat = JsonSettings.DateTimeStyle.ISO }; var str = new JsonEncoder(ts1, jsonSet).GetJSON(); var ts1b = TS1.BiserJsonDecode(str, settings: jsonSet); }
static void Main(string[] args) { var resbof = BiserObjectify.Generator.Run(typeof(TS6), true, @"D:\Temp\1\", forBiserBinary: true, forBiserJson: true); return; TS6 t6 = new TS6() { //P1 = "dsfs", //P2 = 456, //P3 = DateTime.UtcNow, //P4 = new List<Dictionary<DateTime, Tuple<int, string>>> // { // new Dictionary<DateTime, Tuple<int, string>>{ // { DateTime.UtcNow.AddMinutes(-1), new Tuple<int, string>(12,"pipec") }, // { DateTime.UtcNow.AddMinutes(-2), new Tuple<int, string>(125,"pipec123") } // }, // new Dictionary<DateTime, Tuple<int, string>>{ // { DateTime.UtcNow.AddMinutes(-3), new Tuple<int, string>(17,"pihfpec") }, // { DateTime.UtcNow.AddMinutes(-4), new Tuple<int, string>(15625,"pipfghec123") } // } // }, //P5 = new Dictionary<int, Tuple<int, string>> { // { 12, new Tuple<int, string>(478,"dsffdf") }, // { 178, new Tuple<int, string>(5687,"sdfsd") } // }, //P6 = new Tuple<int, string, Tuple<List<string>, DateTime>>(445, "dsfdfgfgfg", //new Tuple<List<string>, DateTime>(new List<string> { "a1", "a2" }, DateTime.Now.AddDays(58))), //P7 = new List<string> { "fgdfgrdfg", "dfgfdgdfg" }, //P8 = new Dictionary<int, List<string>> { // { 34,new List<string> { "drtttz","ghhtht"} }, // { 4534,new List<string> { "dfgfghfgz","6546ghhtht"} } // }, //P13 = new List<List<int>> { new List<int> { 12, 43, 54 }, new List<int> { 12, 43, 54 } }, //P15 = new Tuple<int, string, DateTime, byte[]>(147, "sdffgfdsg", DateTime.UtcNow, new byte[] { 45, 78, 95 }), //P16 = new List<Dictionary<int, Tuple<int, string>>> // { // new Dictionary<int, Tuple<int, string>>{ // { 1, new Tuple<int, string>(12,"pipec") }, // { 2, new Tuple<int, string>(125,"pipec123") } // }, // new Dictionary<int, Tuple<int, string>>{ // { 3, new Tuple<int, string>(17,"pihfpec") }, // { 4, new Tuple<int, string>(15625,"pipfghec123") } // } // }, //P17 = new int[3] { 12, 3545, 7987 } }; #region "pars" //t6.P19 = new Dictionary<int, List<string>>[2][]; //t6.P19[0] = new Dictionary<int, List<string>>[3]; //t6.P19[1] = new Dictionary<int, List<string>>[5]; //t6.P19[0][0] = new Dictionary<int, List<string>> { { 1, new List<string> { "dsf", "dsfd" } }, { 3, new List<string> { "fdsf", "tzutr" } } }; //t6.P11 = new int[2][]; //t6.P11[0] = new int[3]; //t6.P11[1] = new int[3]; //t6.P11[0][0] = 12; //t6.P11[0][1] = 14; //t6.P11[1][0] = 125; //t6.P11[1][2] = 19; //t6.P18 = new List<int>[2, 3, 4]; //t6.P18[0, 0, 0] = new List<int> { 1, 2 }; //t6.P18[0, 0, 1] = new List<int> { 12, 4 }; //t6.P18[0, 1, 0] = new List<int> { 3, 12, 7, 8 }; //t6.P18[0, 1, 1] = new List<int> { 99, 14, 7, 7 }; //t6.P18[1, 0, 0] = new List<int> { 4, 17, 9, 9, 9, 6 }; //t6.P18[1, 0, 1] = new List<int> { 2, 12, 5, 0 }; //t6.P12 = new int[2, 3, 4]; //t6.P12[0, 0, 0] = 12; //t6.P12[0, 0, 1] = 13; //t6.P12[0, 1, 0] = 14; //t6.P12[0, 1, 1] = 15; //t6.P12[1, 0, 0] = 16; //t6.P12[1, 0, 1] = 17; //t6.P121 = new string[2, 3, 4]; //t6.P121[0, 0, 0] = "dsf"; //t6.P121[0, 0, 1] = "dsf"; //t6.P121[0, 1, 0] = "dsf"; //t6.P121[0, 1, 1] = "dsf"; //t6.P121[1, 0, 0] = "dsf"; //t6.P121[1, 0, 1] = "dsf"; //var ar1 = new int[2, 3, 4]; //ar1[0, 0, 0] = 12; //ar1[0, 0, 1] = 13; //ar1[0, 1, 0] = 14; //ar1[0, 1, 1] = 15; //ar1[1, 0, 0] = 16; //ar1[1, 0, 1] = 17; //t6.P21 = new List<int[,,]>(); //t6.P21.Add(ar1); //ar1 = new int[2, 3, 4]; //ar1[0, 0, 0] = 12; //ar1[0, 0, 1] = 13; //ar1[0, 1, 0] = 14; //ar1[0, 1, 1] = 15; //ar1[1, 0, 0] = 16; //ar1[1, 0, 1] = 17; //ar1[0, 0, 0] = 122; //ar1[0, 0, 1] = 132; //t6.P21.Add(ar1); #endregion //Json test //t6.P25 = new System.Collections.Generic.Dictionary<System.Int32, System.Collections.Generic.List<System.String[,][][,,]>> // [2, 3, 4, 8][][,,]; //var njSer = NetJSON.NetJSON.Serialize(t6, new NetJSON.NetJSONSettings { DateFormat = NetJSON.NetJSONDateFormat.ISO }); //var jsonSet = new Biser.JsonSettings { DateFormat = Biser.JsonSettings.DateTimeStyle.ISO }; //Biser.JsonEncoder enc = new Biser.JsonEncoder(t6, jsonSet); //string es = enc.GetJSON(Biser.JsonSettings.JsonStringStyle.Prettify); //var ot2 = TS6.BiserJsonDecode(es, settings: jsonSet); ////var ot2 = TS6.BiserJsonDecode(njSer, settings: jsonSet); //Binary test //var encb = t6.BiserEncoder().Encode(); //var t6n = TS6.BiserDecode(encb); return; TestDecodeV1(); return; //var jsres = NetJSON.NetJSON.Serialize((int)12); //12 //var ojsres = NetJSON.NetJSON.Deserialize<int>(jsres); //var jsres2 = NetJSON.NetJSON.Serialize((double)12.45687); //12.45687 //var ojsres2 = NetJSON.NetJSON.Deserialize<double>(jsres2); //Dictionary<string, byte[]> dic1d = new Dictionary<string, byte[]>(); //dic1d.Add("str1", new byte[] { 1, 2, 3 }); //dic1d.Add("str2", new byte[] { 1, 2 }); //dic1d.Add("str3", null); //var jsres1 = NetJSON.NetJSON.Serialize(dic1d); //{"str1":"AQID","str2":"AQI=","str3":null} //var ojsres1 = NetJSON.NetJSON.Deserialize<Dictionary<string, byte[]>>(jsres1); //List<Dictionary<string, byte[]>> ldic1d = new List<Dictionary<string, byte[]>>(); //ldic1d.Add(dic1d); //ldic1d.Add(dic1d); //var jsres3 = NetJSON.NetJSON.Serialize(ldic1d); //[{"str1":"AQID","str2":"AQI=","str3":null},{"str1":"AQID","str2":"AQI=","str3":null}] //var ojsres3 = NetJSON.NetJSON.Deserialize<List<Dictionary<string, byte[]>>>(jsres3); //var jsres4 = NetJSON.NetJSON.Serialize((string)"ds\"fs{d}f"); //"ds\"fs{d}f" //// var jsres4 = NetJSON.NetJSON.Serialize("dsf\"sdfdsf{fdgdfgdf{dsfdsf[sdf\"\"dfdsf}"); //"dsf\"sdfdsf{fdgdfgdf{dsfdsf[sdf\"\"dfdsf}" //var ojsres4 = NetJSON.NetJSON.Deserialize<string>(jsres4); //"ds"fsdf" TS2 jts2 = new TS2() { P1 = long.MinValue, P2 = 4587.4564, P3 = new List <TS3> { new TS3 { P3 = DateTime.UtcNow.AddDays(-1) }, null, //new TS3 { P3 = DateTime.UtcNow.AddDays(-2) }, new TS3 { P3 = DateTime.UtcNow.AddDays(-3) } }, P4 = new TS3 { P1 = "hi" }, P5 = 111 }; //TS1 jts1 = new TS1() //{ // P1 = 12, // P2 = 15, // P3 = 478.5879m, // P4 = new List<TS2> { jts2, jts2 }, // P5 = new Dictionary<long, TS3> { // { 1, new TS3{ P1 = "t1" } }, // { 2, new TS3{ P1 = "t2" } }, // { 3, new TS3{ P1 = "t3" } } // }, // P6 = new Dictionary<uint, List<TS3>> { // { 1, new List<TS3>{ new TS3 { P1 = "h1" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h3" } } }, // { 2, new List<TS3>{ new TS3 { P1 = "h2" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h4" } } }, // { 3, new List<TS3>{ new TS3 { P1 = "h3" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h5" } } }, // { 4, new List<TS3>{ new TS3 { P1 = "h4" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h6" } } } // }, // P7 = new TS2 { P1 = -789 }, // P8 = new List<Tuple<string, byte[], TS3>> { // new Tuple<string, byte[], TS3>("tt1",new byte[] { 1,2,3},new TS3 { P1 = "z1" }), // new Tuple<string, byte[], TS3>("tt2",new byte[] { 3,2,3},new TS3 { P1 = "z2" }), // new Tuple<string, byte[], TS3>("tt3",new byte[] { 4,2,3},new TS3 { P1 = "z3" }), // }, // P9 = new Tuple<float, TS2, TS3, decimal?>(-.8f, new TS2 { P2 = 45 }, new TS3 { P2 = 12 }, -58.8m), // P10 = "dsf\"sdfdsf{fdgdfgdf{dsfdsf[sdf\"\"dfdsf}" //}; //var jsres5 = NetJSON.NetJSON.Serialize(jts1, new NetJSON.NetJSONSettings { DateFormat = NetJSON.NetJSONDateFormat.ISO, Format = NetJSON.NetJSONFormat.Prettify }); ///*{"P1":12,"P2":15,"P3":478.5879,"P4":[{"P1":-9223372036854775808,"P2":4587.4564,"P3":[{"P3":"\/Date(15340651396274201)\/"},null,{"P3":"\/Date(15338923396274201)\/"}],"P4":{"P1":"hi"},"P5":111},{"P1":-9223372036854775808,"P2":4587.4564,"P3":[{"P3":"\/Date(15340651396274201)\/"},null,{"P3":"\/Date(15338923396274201)\/"}],"P4":{"P1":"hi"},"P5":111}],"P5":{"1":{"P1":"t1"},"2":{"P1":"t2"},"3":{"P1":"t3"}},"P6":{"1":[{"P1":"h1"},{"P1":"h2"},{"P1":"h3"}],"2":[{"P1":"h2"},{"P1":"h2"},{"P1":"h4"}],"3":[{"P1":"h3"},{"P1":"h2"},{"P1":"h5"}],"4":[{"P1":"h4"},{"P1":"h2"},{"P1":"h6"}]},"P7":{"P1":-789},"P8":[{"Item1":"tt1","Item2":"AQID","Item3":{"P1":"z1"}},{"Item1":"tt2","Item2":"AwID","Item3":{"P1":"z2"}},{"Item1":"tt3","Item2":"BAID","Item3":{"P1":"z3"}}],"P9":{"Item1":12.8,"Item2":{"P2":45},"Item3":{"P2":12},"Item4":-58.8}}*/ //var ojsres5 = NetJSON.NetJSON.Deserialize<TS1>(jsres5); //"ds"fsdf" //Dictionary<int, byte[]> dic1d2 = new Dictionary<int, byte[]>(); //key will be transformed toString, so key can't be byte[] //dic1d2.Add(12, new byte[] { 1, 2, 3 }); //dic1d2.Add(17, new byte[] { 1, 2 }); //var jsres6 = NetJSON.NetJSON.Serialize(dic1d2); //{"12":"AQID","17":"AQI="} //var ojsres6 = NetJSON.NetJSON.Deserialize<Dictionary<int, byte[]>>(jsres6); //Dictionary<int, string> dic1d3 = new Dictionary<int, string>(); //key will be transformed toString, so key can't be byte[] //dic1d3.Add(12, "dsf\"sdfdsf{fdgdfgdf{dsfdsf[sdf\"\"dfdsf}"); //dic1d3.Add(17, "dsf\"sdfdsf{fdgddddf{dsfdsf[sdf\"\"dfdsf}"); //var jsres7 = NetJSON.NetJSON.Serialize(dic1d3, new NetJSON.NetJSONSettings { DateFormat = NetJSON.NetJSONDateFormat.ISO, Format = NetJSON.NetJSONFormat.Prettify }); //{"12":"AQID","17":"AQI="} //var ojsres7 = NetJSON.NetJSON.Deserialize<Dictionary<int, string>>(jsres7); ////var jsres8 = NetJSON.NetJSON.Serialize((int?)null); //{"12":"AQID","17":"AQI="} ////var ojsres8 = NetJSON.NetJSON.Deserialize<int?>(jsres8); ////var jsres8 = NetJSON.NetJSON.Serialize("dsf\"sdfdsf{fdgdfgdf{dsfdsf[sdf\"\"dfdsf}"); //{"12":"AQID","17":"AQI="} ////var ojsres8 = NetJSON.NetJSON.Deserialize<string>(jsres8); ////Dictionary<int, int> dic1d4 = new Dictionary<int, int>(); //key will be transformed toString, so key can't be byte[] ////dic1d4.Add(12, 15); ////dic1d4.Add(17, 57); ////var jsres8 = NetJSON.NetJSON.Serialize(dic1d4); //{"12":"AQID","17":"AQI="} ////var ojsres8 = NetJSON.NetJSON.Deserialize<Dictionary<int, int>>(jsres8); //List<int> dic1d4 = new List<int>(); //dic1d4.Add(324); //dic1d4.Add(33); //var jsres8 = NetJSON.NetJSON.Serialize(dic1d4); //{"12":"AQID","17":"AQI="} ////var ojsres8 = NetJSON.NetJSON.Deserialize<List<int, int>>(jsres8); //JsonDecoder jsdec = new JsonDecoder(jsres8); //{"12":15,"17":57} ////var iuz = jsdec.GetInt_NULL(); ////var iuz = jsdec.GetString(); ////Dictionary<int,int> iuzd = jsdec.CheckNull() ? null : new Dictionary<int, int>(); //List<int> iuzd = jsdec.CheckNull() ? null : new List<int>(); //if (iuzd != null) //{ // //jsdec.GetCollection(() => { return jsdec.GetInt(); }, // // () => { return jsdec.GetInt(); }, iuzd, true); // //foreach (var item in iuzd) // // Debug.WriteLine(item.Key); // jsdec.GetCollection(() => { return jsdec.GetInt(); }, iuzd, true); // foreach (var item in iuzd) // Debug.WriteLine(item); //} TS1 jsts1 = new TS1() { P1 = 12, P2 = 17, P3 = 478.5879m, P4 = new List <TS2> { jts2, jts2 }, //P5 = new Dictionary<long, TS3> { // { 1, new TS3{ P1 = "t1" } }, // { 2, new TS3{ P1 = "t2" } }, // { 3, new TS3{ P1 = "t3" } } // }, P6 = new Dictionary <uint, List <TS3> > { { 1, new List <TS3> { new TS3 { P1 = "h1" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h3" } } }, { 2, new List <TS3> { new TS3 { P1 = "h2" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h4" } } }, { 3, new List <TS3> { new TS3 { P1 = "h3" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h5" } } }, { 4, new List <TS3> { new TS3 { P1 = "h4" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h6" } } } }, P7 = new TS2 { P1 = -789 }, P8 = new List <Tuple <string, byte[], TS3> > { new Tuple <string, byte[], TS3>("tt1", new byte[] { 1, 2, 3 }, new TS3 { P1 = "z1" }), new Tuple <string, byte[], TS3>("tt2", new byte[] { 3, 2, 3 }, new TS3 { P1 = "z2" }), new Tuple <string, byte[], TS3>("tt3", new byte[] { 4, 2, 3 }, new TS3 { P1 = "z3" }), }, P9 = new Tuple <float, TS2, TS3, decimal?>(-.8f, new TS2 { P2 = 45 }, new TS3 { P2 = 12 }, -58.8m), }; jsts1.P11 = new Dictionary <int, int>(); jsts1.P11.Add(12, 14); jsts1.P11.Add(17, 89); //jsts1.P14 = new Dictionary<int, int>(); //jsts1.P14.Add(17, 14); //jsts1.P14.Add(19, 89); jsts1.P5 = new Dictionary <long, TS3>(); jsts1.P5.Add(189, new TS3 { P1 = "dsf", P2 = 45, P3 = DateTime.UtcNow }); jsts1.P5.Add(178, new TS3 { P1 = "sdfsdfsdfs", P2 = null, P3 = DateTime.UtcNow }); jsts1.P5.Add(148, new TS3 { P1 = "dfdff", P2 = null, P3 = DateTime.UtcNow }); jsts1.P12 = 789; jsts1.P13 = new List <TS3>(); jsts1.P13.Add(new TS3 { P1 = "dsf", P2 = 45, P3 = DateTime.UtcNow }); jsts1.P13.Add(new TS3 { P1 = "sdfsdfsdfs", P2 = null, P3 = DateTime.UtcNow }); jsts1.P15 = new List <List <TS3> >(); jsts1.P15.Add(jsts1.P13); jsts1.P15.Add(jsts1.P13); jsts1.P16 = new Dictionary <long, List <TS3> >(); jsts1.P16.Add(12, jsts1.P13); jsts1.P16.Add(14, jsts1.P13); jsts1.P16.Add(28, jsts1.P13); jsts1.P18 = new List <int>(); jsts1.P18.Add(178); jsts1.P18.Add(912); jsts1.P19 = new Tuple <int, TS3>(12, new TS3 { P1 = "dsf", P2 = 45, P3 = DateTime.UtcNow }); jsts1.P17 = new DateTime(2018, 6, 5, 17, 44, 15, 443, DateTimeKind.Utc); //var jsres9 = NetJSON.NetJSON.Serialize(jsts1, new NetJSON.NetJSONSettings() { Format = NetJSON.NetJSONFormat.Prettify }); var jsres9 = NetJSON.NetJSON.Serialize(jsts1, new NetJSON.NetJSONSettings() { Format = NetJSON.NetJSONFormat.Prettify, DateFormat = NetJSON.NetJSONDateFormat.Default }); var njdv1 = NetJSON.NetJSON.Deserialize <TS1>(jsres9, new NetJSON.NetJSONSettings() { //Format = NetJSON.NetJSONFormat.Prettify, DateFormat = NetJSON.NetJSONDateFormat.Default }); //var jsres9 = NetJSON.NetJSON.Serialize(jsts1); TS1 jsts1d = null; //jsts1d = TS1.BiserJsonDecode(jsres9, null, new JsonSettings { DateFormat = JsonSettings.DateTimeStyle.ISO }); //----------------- //var jsres91 = NetJSON.NetJSON.Serialize(jsts1.P13, new NetJSON.NetJSONSettings() //{ //Format = NetJSON.NetJSONFormat.Prettify, // DateFormat = NetJSON.NetJSONDateFormat.ISO //}); JsonEncoder jenc = new JsonEncoder(null, new JsonSettings { DateFormat = JsonSettings.DateTimeStyle.Default, JsonStringFormat = JsonSettings.JsonStringStyle.Prettify }); // jsts1.BiserJsonEncode(jenc); string wow1 = jenc.GetJSON(); var jsts1d1 = TS1.BiserJsonDecode(wow1, null, new JsonSettings { DateFormat = JsonSettings.DateTimeStyle.Default }); //TestJSONv1(); //StreamReader sr=new StreamReader("",Encoding.UTF8) //StreamWriter sw=new StreamWriter() Console.WriteLine("Press to start test"); Console.ReadLine(); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); for (int i = 0; i < 10000; i++) { jenc = new JsonEncoder(new JsonSettings { DateFormat = JsonSettings.DateTimeStyle.Default, JsonStringFormat = JsonSettings.JsonStringStyle.Default }); jsts1.BiserJsonEncode(jenc); wow1 = jenc.GetJSON(); } sw.Stop(); Console.WriteLine($"Biser encode: {sw.ElapsedMilliseconds} ms"); sw.Reset(); sw.Start(); for (int i = 0; i < 10000; i++) { jsres9 = NetJSON.NetJSON.Serialize(jsts1, new NetJSON.NetJSONSettings() { Format = NetJSON.NetJSONFormat.Default, DateFormat = NetJSON.NetJSONDateFormat.Default }); } sw.Stop(); Console.WriteLine($"NetJSON encode: {sw.ElapsedMilliseconds} ms"); sw.Reset(); sw.Start(); for (int i = 0; i < 10000; i++) { jsts1d = TS1.BiserJsonDecode(wow1, null, new JsonSettings { DateFormat = JsonSettings.DateTimeStyle.Default }); } sw.Stop(); Console.WriteLine($"Biser decode: {sw.ElapsedMilliseconds} ms"); sw.Reset(); sw.Start(); for (int i = 0; i < 10000; i++) { jsts1d = NetJSON.NetJSON.Deserialize <TS1>(jsres9); } sw.Stop(); Console.WriteLine($"NetJSON decode: {sw.ElapsedMilliseconds} ms"); sw.Reset(); // jsts1d = TS1.BiserJsonDecode(jsres9); Console.ReadLine(); return; Biser.Encoder en2 = new Biser.Encoder(); en2.Add((int)12); Dictionary <string, byte[]> dic1 = new Dictionary <string, byte[]>(); dic1.Add("str1", new byte[] { 1, 2, 3 }); dic1.Add("str2", new byte[] { 1, 2 }); dic1.Add("str3", null); dic1.Add("str4", new byte[0]); dic1.Add("str5", new byte[] { 1, 2, 3, 4, 5 }); en2.Add(dic1, r => { en2.Add(r.Key); en2.Add(r.Value); }); //List<int> lst1 = new List<int>(); //lst1.Add(1); //lst1.Add(2); //lst1.Add(3); //en2.Add(lst1, r => { en2.Add(r); }); en2.Add((int)14); Biser.Decoder de2 = new Biser.Decoder(en2.Encode()); Debug.WriteLine(de2.GetInt()); //List<int> lst = de2.CheckNull() ? null : new List<int>(); //if (lst != null) //{ // de2.GetCollection(() => { return de2.GetInt(); }, lst, true); // foreach (var item in lst) // Debug.WriteLine(item); //} Dictionary <string, byte[]> dic = de2.CheckNull() ? null : new Dictionary <string, byte[]>(); if (dic != null) { de2.GetCollection(() => { return(de2.GetString()); }, () => { return(de2.GetByteArray()); }, dic, true); foreach (var item in dic) { Debug.WriteLine(item.Key); } } Debug.WriteLine(de2.GetInt()); return; //var le = BitConverter.IsLittleEndian; Biser.Encoder enn = new Biser.Encoder(); byte[] btEnn = null; double flv = -17.32; enn.Add(flv); //enn.Add((long)1); btEnn = enn.Encode(); var res = true ^ false; //BitConverter.ToDouble() var fltBts = BitConverter.GetBytes(flv); return; //enn.Add((long)-123879); enn.Add((ulong)1521797378957); btEnn = enn.Encode(); long tr = 1521797378957; do { tr = tr >> 7; Console.WriteLine("М " + tr); } while (tr != 0); Biser.Decoder denn = new Biser.Decoder(btEnn); //var hzj = denn.GetLong(); var hzj = denn.GetULong(); var tt = Biser.Biser.EncodeZigZag((long)-123879, 64); var value = -123879; var tt1 = (value << 1) ^ (value >> 63); var tt2 = Biser.Biser.DecodeZigZag((ulong)tt1); Console.WriteLine("L=" + (value << 1)); Console.WriteLine("R=" + (value >> 63)); Console.WriteLine("T=" + tt1 + "; dec=" + tt2); Console.WriteLine("tmp=" + (100000000000 & 0x7fffffff)); Console.WriteLine("tmp=" + ((-100000000000) & 0x7fffffff)); /* * var v1 = 123879; * var hi = 0x80000000; * var low = 0x7fffffff; * var hi1 = ~~(v1 / hi); * var low1 = v1 & low; * var v1b = hi1 * hi + low1; */ //var tm = new DateTime(1521797378957*10000, DateTimeKind.Utc); var tm = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc) .AddMilliseconds(1521797378957); // for (int i = 0; i < 256; i++) { //Console.WriteLine((sbyte)(i) + " _ " + (i & 0x80)+ " _ " + i + " _ " + (i - (i&0x80))); sbyte p = (sbyte)(i); sbyte s = (sbyte)(i); byte b = (byte)((p + 128) + (1 - 2 * (((p + 128) & 0x80) >> 7)) * 128); byte b1 = (byte)(s + (256 & ((s & 0x80) << 1))); Console.WriteLine(i + " _ " + (sbyte)(i) + " _ " + (i - ((i & 128) << 1)) + " _ " + b + " _> " + b1 ); //128 0x80 byte to sbyte converter } //double flv = 12.56; //double flv = 124.56; var uBts = BitConverter.ToUInt64(fltBts, 0); return; //float flv = 12.56f; //flv = 0; //flv = float.MinValue; //flv = float.MaxValue; //var fltBts = BitConverter.GetBytes(flv); //var uBts = BitConverter.ToUInt32(fltBts, 0); return; TS3 ts3 = new TS3() { P1 = "welldone", P2 = null, P3 = DateTime.UtcNow }; //var bt3 = ts3.BiserEncoder().Encode(); //TS3 ts2D = TS3.BiserDecode(bt3); TS2 ts2 = new TS2() { P1 = long.MinValue, P2 = 4587.4564, P3 = new List <TS3> { new TS3 { P3 = DateTime.UtcNow.AddDays(-1) }, null, //new TS3 { P3 = DateTime.UtcNow.AddDays(-2) }, new TS3 { P3 = DateTime.UtcNow.AddDays(-3) } }, P4 = new TS3 { P1 = "hi" }, P5 = 111 }; //var bt2 = ts2.BiserEncoder().Encode(); //TS2 ts2D = TS2.BiserDecode(bt2); TS1 ts1 = new TS1() { P1 = 12, P2 = 15, P3 = 478.5879m, P4 = new List <TS2> { ts2, ts2 }, P5 = new Dictionary <long, TS3> { { 1, new TS3 { P1 = "t1" } }, { 2, new TS3 { P1 = "t2" } }, { 3, new TS3 { P1 = "t3" } } }, P6 = new Dictionary <uint, List <TS3> > { { 1, new List <TS3> { new TS3 { P1 = "h1" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h3" } } }, { 2, new List <TS3> { new TS3 { P1 = "h2" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h4" } } }, { 3, new List <TS3> { new TS3 { P1 = "h3" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h5" } } }, { 4, new List <TS3> { new TS3 { P1 = "h4" }, new TS3 { P1 = "h2" }, new TS3 { P1 = "h6" } } } }, P7 = new TS2 { P1 = -789 }, P8 = new List <Tuple <string, byte[], TS3> > { new Tuple <string, byte[], TS3>("tt1", new byte[] { 1, 2, 3 }, new TS3 { P1 = "z1" }), new Tuple <string, byte[], TS3>("tt2", new byte[] { 3, 2, 3 }, new TS3 { P1 = "z2" }), new Tuple <string, byte[], TS3>("tt3", new byte[] { 4, 2, 3 }, new TS3 { P1 = "z3" }), }, P9 = new Tuple <float, TS2, TS3, decimal?>(12.8f, new TS2 { P2 = 45 }, new TS3 { P2 = 12 }, -58.8m) }; var bt1 = ts1.BiserEncoder().Encode(); TS1 ts1D = TS1.BiserDecode(bt1); //TestMultiDimensionArray //TestCustom(); //TestPrimitives(); //TestBE1(); TestT5(); //TestListDictionary(); Console.ReadLine(); //var enc = new Biser.Encoder(); //enc.Add(double.MinValue); //enc.Add(double.MaxValue); //enc.Add((double)-455.45); //enc.Add((double)465.45); //var decoder = new Biser.Decoder(enc.Encode()); //var d1 = decoder.GetDouble(); //var d2 = decoder.GetDouble(); //var d3 = decoder.GetDouble(); //var d4 = decoder.GetDouble(); //var enc = new Biser.Encoder(); //enc.Add(float.MinValue); //enc.Add(float.MaxValue); //enc.Add((float)-455.45); //enc.Add((float)465.45); //var decoder = new Biser.Decoder(enc.Encode()); //var d1 = decoder.GetFloat(); //var d2 = decoder.GetFloat(); //var d3 = decoder.GetFloat(); //var d4 = decoder.GetFloat(); }