예제 #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());
         }
     }
 }
예제 #2
0
        public static byte[] Serializer <T>(this T val)
        {
            SdpWriter writer = new SdpWriter();

            writer.Pack(val);
            return(writer.ToBytes());
        }
예제 #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);
     }
 }
예제 #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);
        }
예제 #5
0
        public static bool Serializer <T>(this T val, MemoryStream memst)
        {
            SdpWriter writer = new SdpWriter(memst);

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

            writer.Visit(tag, null, require, ref iValue);
        }
예제 #7
0
 public void Write(object value, SdpWriter writer, uint tag, bool require)
 {
     byte[] str = (byte[])value;
     writer.Visit(tag, null, require, ref str);
 }
예제 #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);
        }
예제 #9
0
        public void Write(object value, SdpWriter writer, uint tag, bool require)
        {
            int val = (int)value;

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

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

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

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

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