Custom binary serializer of well known types
Esempio n. 1
0
 public decimal GetDecimal()
 {
     int[] bits = new int[4];
     bits[0] = (int)Biser.DecodeZigZag(this.rootDecoder.GetDigit());
     bits[1] = (int)Biser.DecodeZigZag(this.rootDecoder.GetDigit());
     bits[2] = (int)Biser.DecodeZigZag(this.rootDecoder.GetDigit());
     bits[3] = (int)Biser.DecodeZigZag(this.rootDecoder.GetDigit());
     return(new decimal(bits));
 }
Esempio n. 2
0
            public ushort GetUShort()
            {
                if (!this.GetDigit(out var dgt))
                {
                    return(default(ushort));
                }

                return((ushort)Biser.DecodeZigZag(dgt));
            }
Esempio n. 3
0
            /// <summary>
            ///  Javascript Biser decoder
            /// </summary>
            /// <returns></returns>
            public long JSGetLong()
            {
                if (!this.GetDigit(out var dgt))
                {
                    return(default(long));
                }

                return(Biser.DecodeZigZag(dgt));
            }
Esempio n. 4
0
            public int GetInt()
            {
                if (!this.GetDigit(out var dgt))
                {
                    return(default(int));
                }

                return((int)Biser.DecodeZigZag(dgt));
            }
Esempio n. 5
0
            } //eof

            public DateTime GetDateTime()
            {
                if (!this.GetDigit(out var dgt))
                {
                    return(default(DateTime));
                }

                return(new DateTime(Biser.DecodeZigZag(dgt)));
            }
Esempio n. 6
0
            public decimal GetDecimal()
            {
                if (!this.GetDigit(out var dgt))
                {
                    return(default(decimal));
                }

                int[] bits = new int[4];
                bits[0] = (int)Biser.DecodeZigZag(dgt);
                this.GetDigit(out dgt);
                bits[1] = (int)Biser.DecodeZigZag(dgt);
                this.GetDigit(out dgt);
                bits[2] = (int)Biser.DecodeZigZag(dgt);
                this.GetDigit(out dgt);
                bits[3] = (int)Biser.DecodeZigZag(dgt);
                return(new decimal(bits));
            }
Esempio n. 7
0
        /// <summary>
        /// null elements equal to new byte[0]
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        public static byte[] Encode_PROTO_ListByteArray(IList <byte[]> d)
        {
            //null element of the list is not allowed (the same as in protobuf), byte[0]  means String.Empty

            if (d == null || d.Count == 0)
            {
                return(new byte[0]);
            }

            byte[] tar1 = null;
            using (MemoryStream ms = new MemoryStream())
            {
                foreach (var el in d)
                {
                    //Setting key
                    ms.Write(new byte[] { 10 }, 0, 1); //complex Type - 10
                    if (el == null || el.Length == 0)
                    {
                        ms.Write(new byte[] { 0 }, 0, 1);// 0 length element
                    }
                    else
                    {
                        tar1 = Biser.GetVarintBytes((ulong)el.Length);
                        ms.Write(tar1, 0, tar1.Length); //length of key
                        ms.Write(el, 0, el.Length);     //key self
                    }
                }

                tar1 = ms.ToArray();
#if !NETPORTABLE
                ms.Close();
#endif
            }

            return(tar1);
        }
Esempio n. 8
0
 public Encoder Add(short value)
 {
     GetVarintBytes((ulong)Biser.EncodeZigZag(value, 16));
     return(this);
 }
Esempio n. 9
0
 public Encoder Add(long value)
 {
     GetVarintBytes((ulong)Biser.EncodeZigZag(value, 64));
     return(this);
 }
Esempio n. 10
0
 /// <summary>
 ///  Javascript Biser decoder
 /// </summary>
 /// <returns></returns>
 public long JSGetLong()
 {
     return(Biser.DecodeZigZag(this.rootDecoder.GetDigit()));
 }
Esempio n. 11
0
 public ushort GetUShort()
 {
     return((ushort)Biser.DecodeZigZag(this.rootDecoder.GetDigit()));
 }
Esempio n. 12
0
 public int GetInt()
 {
     return((int)Biser.DecodeZigZag(this.rootDecoder.GetDigit()));
 }
Esempio n. 13
0
            } //eof

            public DateTime GetDateTime()
            {
                return(new DateTime(Biser.DecodeZigZag(this.rootDecoder.GetDigit())));
            }
Esempio n. 14
0
 public short GetShort()
 {
     return((short)Biser.DecodeZigZag(this.GetDigit()));
 }
Esempio n. 15
0
 public long GetLong()
 {
     return(Biser.DecodeZigZag(this.GetDigit()));
 }