Exemplo n.º 1
0
 public void Visit(uint tag, string name, bool require, ref IStruct val)
 {
     if (val == null)
     {
         return;
     }
     if (require)
     {
         PackHead(tag, SdpPackDataType.SdpPackDataType_StructBegin);
         val.Visit(this);
         PackHead(0u, SdpPackDataType.SdpPackDataType_StructEnd);
     }
     else
     {
         SdpWriter sdp = new SdpWriter();
         sdp.PackHead(tag, SdpPackDataType.SdpPackDataType_StructBegin);
         uint iStartPos = sdp.CurrPos();
         val.Visit(sdp);
         if (iStartPos < sdp.CurrPos())
         {
             sdp.PackHead(0u, SdpPackDataType.SdpPackDataType_StructEnd);
             WriteRawByte(sdp.ToBytes());
         }
     }
 }
Exemplo n.º 2
0
        public static byte[] Serializer <T>(this T val)
        {
            SdpWriter writer = new SdpWriter();

            writer.Pack(val);
            return(writer.ToBytes());
        }
Exemplo n.º 3
0
 public void Write(object value, SdpWriter writer, uint tag, bool require)
 {
     if (value != null)
     {
         IStruct t = (IStruct)value;
         writer.Visit(tag, null, require, ref t);
     }
 }
Exemplo n.º 4
0
        public static bool Serializer <T>(this T val, MemoryStream memst)
        {
            SdpWriter writer = new SdpWriter(memst);
            var       ser    = GetSerializer <T>();

            if (ser != null)
            {
                ser.Write(val, writer, 0, true);
                return(true);
            }
            else
            {
                Type type = typeof(T);
                if (type.IsEnum)
                {
                    writer.VisitEunm(0, null, true, ref val);
                    return(true);
                }
                else
                {
                    foreach (var it in type.GetInterfaces())
                    {
                        if (it == typeof(IDictionary))
                        {
                            Type[]      genericTypes = type.GetGenericArguments();
                            IDictionary dir          = (IDictionary)val;
                            var         keySer       = GetSerializer(genericTypes[0]);
                            var         valSer       = GetSerializer(genericTypes[1]);
                            writer.Visit(0, null, true, ref dir, keySer, genericTypes[0], valSer, genericTypes[1]);
                            return(true);
                        }
                        else if (it == typeof(IList))
                        {
                            Type[] genericTypes = type.GetGenericArguments();
                            IList  list         = (IList)val;
                            var    serT         = GetSerializer(genericTypes[0]);
                            writer.Visit(0, null, true, ref list, serT, genericTypes[0]);
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        public static bool Serializer <T>(this T val, MemoryStream memst)
        {
            SdpWriter writer = new SdpWriter(memst);

            return(writer.Pack(val, 0));
        }
Exemplo n.º 6
0
        public void Write(object value, SdpWriter writer, uint tag, bool require)
        {
            ulong iValue = (ulong)value;

            writer.Visit(tag, null, require, ref iValue);
        }
Exemplo n.º 7
0
 public void Write(object value, SdpWriter writer, uint tag, bool require)
 {
     byte[] str = (byte[])value;
     writer.Visit(tag, null, require, ref str);
 }
Exemplo n.º 8
0
        public void Write(object value, SdpWriter writer, uint tag, bool require)
        {
            string str = ((Guid)value).ToString();

            writer.Visit(tag, null, require, ref str);
        }
Exemplo n.º 9
0
        public void Write(object value, SdpWriter writer, uint tag, bool require)
        {
            int val = (int)value;

            writer.Visit(tag, null, require, ref val);
        }
Exemplo n.º 10
0
        public void Write(object value, SdpWriter writer, uint tag, bool require)
        {
            string str = (string)value;

            writer.Visit(tag, null, require, ref str);
        }
Exemplo n.º 11
0
        public void Write(object value, SdpWriter writer, uint tag, bool require)
        {
            DateTime time = (DateTime)value;

            writer.Visit(tag, null, require, ref time);
        }
Exemplo n.º 12
0
        public void Write(object value, SdpWriter writer, uint tag, bool require)
        {
            bool bValue = (bool)value;

            writer.Visit(tag, null, require, ref bValue);
        }
Exemplo n.º 13
0
        public void Write(object value, SdpWriter writer, uint tag, bool require)
        {
            double fValue = (double)value;

            writer.Visit(tag, null, require, ref fValue);
        }