Ejemplo n.º 1
0
        static void TestT4()
        {
            TS4 voc = new TS4()
            {
                TermId   = 12,
                VoteType = TS4.eVoteType.VoteReject
            };

            Biser.Encoder enc = new Biser.Encoder()
                                .Add(voc);

            var voc1 = TS4.BiserDecode(enc.Encode());
        }
Ejemplo n.º 2
0
        public static TS4 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;
            }

            TS4 m = new TS4();  //!!!!!!!!!!!!!! change return type

            m.TermId   = decoder.GetUInt();
            m.VoteType = (eVoteType)decoder.GetInt();

            return(m);
        }
Ejemplo n.º 3
0
        static void TestListDictionary()
        {
            //Encoding
            Biser.Encoder enc = new Biser.Encoder();
            enc.Add((int)123);
            enc.Add(new List <string> {
                "Hi", "there"
            }, r => { enc.Add(r); });
            enc.Add((float)-458.4f);

            enc.Add(new Dictionary <uint, string> {
                { 1, "Well" }, { 2, "done" }
            }
                    , r => { enc.Add(r.Key); enc.Add(r.Value); });

            enc.Add((decimal) - 587.7m);

            //TS4 implements IEncoder
            enc.Add(new Dictionary <uint, TS4> {
                { 1, new TS4 {
                      TermId = 1
                  } }, { 2, new TS4 {
                             TermId = 5
                         } }
            }
                    , r => { enc.Add(r.Key); enc.Add(r.Value); });

            enc.Add(new TS4 {
                TermId = 188
            });

            //Decoding

            var decoder = new Biser.Decoder(enc.Encode());

            Console.WriteLine(decoder.GetInt());


            //////Alternative to the following instruction. Slower than supplying List directly
            ////foreach (var item in decoder.GetCollection().Select(r => r.GetString()))
            ////{
            ////    Console.WriteLine(item);
            ////}

            List <string> lst = decoder.CheckNull() ? null : new List <string>();

            if (lst != null)
            {
                decoder.GetCollection(() => { return(decoder.GetString()); }, lst, true);
                foreach (var item in lst)
                {
                    Console.WriteLine(item);
                }
            }

            Console.WriteLine(decoder.GetFloat());


            ////////Alternative to the following instruction. Slower than supplying Dictionary directly
            //////foreach (var item in decoder.GetCollection())
            //////{
            //////    Console.WriteLine($"K: {item.GetUInt()}; V: {item.GetString()}");
            //////}

            Dictionary <uint, string> d1 = decoder.CheckNull() ? null : new Dictionary <uint, string>();

            if (d1 != null)
            {
                decoder.GetCollection(
                    () => { return(decoder.GetUInt()); },
                    () => { return(decoder.GetString()); },
                    d1, true);
                foreach (var item in d1)
                {
                    Console.WriteLine(item.Key + "; " + item.Value);
                }
            }

            Console.WriteLine(decoder.GetDecimal());

            Dictionary <uint, TS4> d2 = decoder.CheckNull() ? null : new Dictionary <uint, TS4>();

            if (d2 != null)
            {
                decoder.GetCollection(
                    () => { return(decoder.GetUInt()); },
                    () => { return(TS4.BiserDecode(extDecoder: decoder)); },
                    d2, true);
                foreach (var item in d2)
                {
                    Console.WriteLine(item.Key + "; " + item.Value.TermId);
                }
            }

            Console.WriteLine(TS4.BiserDecode(extDecoder: decoder).TermId);
        }