Esempio n. 1
0
 public void UnPackMap <TKey, TValue>(uint tag, string name, bool require, IDictionary <TKey, TValue> val)
 {
     val.Clear();
     if (SkipToTag(tag))
     {
         SdpPackDataType type = UnPackHead(ref tag);
         if (type == SdpPackDataType.SdpPackDataType_Map)
         {
             uint iSize = Unpack32();
             if (val == null)
             {
                 val = new Dictionary <TKey, TValue>((int)iSize);
             }
             ISerializer keySer = Sdp.GetSerializer <TKey>();
             ISerializer valSer = Sdp.GetSerializer <TValue>();
             for (var i = 0; i < iSize; ++i)
             {
                 TKey   key   = Activator.CreateInstance <TKey>();
                 TValue value = Activator.CreateInstance <TValue>();
                 key   = (TKey)keySer.Read(this, 0, require, key);
                 value = (TValue)valSer.Read(this, 0, require, value);
                 if (val.ContainsKey(key))
                 {
                     val.Remove(key);
                 }
                 val.Add(key, value);
             } //for
         }     //if
     }         //if
 }
Esempio n. 2
0
        public bool SkipToTag(uint iTag)
        {
            uint            iCurTag = 0u;
            SdpPackDataType eType   = SdpPackDataType.SdpPackDataType_Integer_Positive;
            bool            result;

            while (_CurPos < _Size)
            {
                uint i    = PeekHead(ref iCurTag, ref eType);
                bool flag = eType == SdpPackDataType.SdpPackDataType_StructEnd || iCurTag > iTag;
                if (flag)
                {
                    break;
                }
                bool flag2 = iCurTag == iTag;
                if (flag2)
                {
                    result = true;
                    return(result);
                }
                Skip(i);
                SkipField(eType);
            }
            result = false;
            return(result);
        }
Esempio n. 3
0
        private void SkipField()
        {
            uint            iTag    = 0u;
            SdpPackDataType curtype = UnPackHead(ref iTag);

            SkipField(curtype);
        }
Esempio n. 4
0
 public void Visit(uint tag, string name, bool require, ref bool val)
 {
     if (SkipToTag(tag))
     {
         SdpPackDataType type = UnPackHead(ref tag);
         if (type == SdpPackDataType.SdpPackDataType_Integer_Positive)
         {
             uint iValue = Unpack32();
             val = (iValue == 1u);
         }
     }
 }
Esempio n. 5
0
 public void Visit(uint tag, string name, bool require, ref IStruct val)
 {
     if (SkipToTag(tag))
     {
         SdpPackDataType type = UnPackHead(ref tag);
         if (type == SdpPackDataType.SdpPackDataType_StructBegin)
         {
             val.Visit(this);
             SkipToStructEnd();
         }
     }
 }
Esempio n. 6
0
 public void Visit(uint tag, string name, bool require, ref DateTime val)
 {
     if (SkipToTag(tag))
     {
         long            iSecond = 0L;
         SdpPackDataType type    = UnPackHead(ref tag);
         if (type == SdpPackDataType.SdpPackDataType_Integer_Positive)
         {
             iSecond = (long)Unpack64();
         }
         val = Sdp.EpochOrigin.AddSeconds(iSecond);
     }
 }
Esempio n. 7
0
 public void Visit(uint tag, string name, bool require, ref float val)
 {
     if (SkipToTag(tag))
     {
         SdpPackDataType type = UnPackHead(ref tag);
         if (type == SdpPackDataType.SdpPackDataType_Float)
         {
             uint          iValue = Unpack32();
             UnionIntFloat st;
             st.Float   = 0f;
             st.Integer = iValue;
             val        = st.Float;
         }
     }
 }
Esempio n. 8
0
        public void SkipToStructEnd()
        {
            uint curtag = 0u;

            while (true)
            {
                SdpPackDataType curtype = UnPackHead(ref curtag);
                if (curtype == SdpPackDataType.SdpPackDataType_StructEnd)
                {
                    break;
                }

                SkipField(curtype);
            }
        }
Esempio n. 9
0
 public void Visit(uint tag, string name, bool require, ref byte[] val)
 {
     if (SkipToTag(tag))
     {
         SdpPackDataType type = UnPackHead(ref tag);
         if (type == SdpPackDataType.SdpPackDataType_String)
         {
             uint iLen = Unpack32();
             if (iLen > 0u)
             {
                 val = UnPackBytes(iLen);
             }
         }
     }
 }
Esempio n. 10
0
 public void Visit(uint tag, string name, bool require, ref double val)
 {
     if (SkipToTag(tag))
     {
         SdpPackDataType type = UnPackHead(ref tag);
         if (type == SdpPackDataType.SdpPackDataType_Double)
         {
             ulong          iValue = Unpack64();
             UnionIntDouble st;
             st.Double  = 0.0;
             st.Integer = iValue;
             val        = st.Double;
         }
     }
 }
Esempio n. 11
0
        private uint PeekHead(ref uint iTag, ref SdpPackDataType eType)
        {
            uint i = 1u;

            Checksize(1u);
            eType = (SdpPackDataType)(_Stream[(int)_CurPos] >> 4);
            iTag  = (uint)(_Stream[(int)_CurPos] & 15);
            if (iTag == 15u)
            {
                _CurPos += 1u;
                i       += PeekNumber32(ref iTag);
                _CurPos -= 1u;
            }
            return(i);
        }
Esempio n. 12
0
 public void Visit(uint tag, string name, bool require, ref string val)
 {
     if (SkipToTag(tag))
     {
         SdpPackDataType type = UnPackHead(ref tag);
         if (type == SdpPackDataType.SdpPackDataType_String)
         {
             uint iLen  = Unpack32();
             bool flag3 = iLen > 0u;
             if (flag3)
             {
                 val = UnPackString(iLen);
             }
         }
     }
 }
Esempio n. 13
0
        private void SkipField(SdpPackDataType eType)
        {
            switch (eType)
            {
            case SdpPackDataType.SdpPackDataType_Integer_Positive:
            case SdpPackDataType.SdpPackDataType_Integer_Negative:
            case SdpPackDataType.SdpPackDataType_Float:
            case SdpPackDataType.SdpPackDataType_Double:
            {
                Unpack64();
                break;
            }

            case SdpPackDataType.SdpPackDataType_String:
            {
                uint iSize = Unpack32();
                Skip(iSize);
                break;
            }

            case SdpPackDataType.SdpPackDataType_Vector:
            {
                uint iSize2 = Unpack32();
                for (uint i = 0u; i < iSize2; i += 1u)
                {
                    SkipField();
                }
                break;
            }

            case SdpPackDataType.SdpPackDataType_Map:
            {
                uint iSize3 = Unpack32();
                for (uint j = 0u; j < iSize3; j += 1u)
                {
                    SkipField();
                    SkipField();
                }
                break;
            }

            case SdpPackDataType.SdpPackDataType_StructBegin:
                SkipToStructEnd();
                break;
            }
        }
Esempio n. 14
0
 public void Visit(uint tag, string name, bool require, ref IList val, ISerializer ser, Type typeT)
 {
     if (SkipToTag(tag))
     {
         SdpPackDataType type = UnPackHead(ref tag);
         if (type == SdpPackDataType.SdpPackDataType_Vector)
         {
             uint iSize = Unpack32();
             for (uint i = 0; i < iSize; ++i)
             {
                 object t = Activator.CreateInstance(typeT);
                 t = ser.Read(this, 0, require, t);
                 val.Add(t);
             } //for
         }     //if
     }         //if
 }
Esempio n. 15
0
        public void PackHead(uint iTag, SdpPackDataType eType)
        {
            byte head = (byte)((int)eType << 4);
            bool flag = iTag < 15u;

            if (flag)
            {
                head |= (byte)iTag;
                WriteRawByte(head);
            }
            else
            {
                head |= 15;
                WriteRawByte(head);
                PackNum32(iTag);
            }
        }
Esempio n. 16
0
 public void Visit(uint tag, string name, bool require, ref ulong val)
 {
     if (SkipToTag(tag))
     {
         SdpPackDataType type = UnPackHead(ref tag);
         if (type == SdpPackDataType.SdpPackDataType_Integer_Negative)
         {
             ulong iValue = Unpack64();
             val = (ulong)-(long)iValue;
         }
         else
         {
             if (type == SdpPackDataType.SdpPackDataType_Integer_Positive)
             {
                 val = Unpack64();
             }
         }
     }
 }
Esempio n. 17
0
 public void VisitEunm <T>(uint tag, string name, bool require, ref T val)
 {
     if (SkipToTag(tag))
     {
         SdpPackDataType type = UnPackHead(ref tag);
         if (type == SdpPackDataType.SdpPackDataType_Integer_Negative)
         {
             uint iValue = Unpack32();
             val = (T)(object)-(int)iValue;
         }
         else
         {
             if (type == SdpPackDataType.SdpPackDataType_Integer_Positive)
             {
                 uint iValue2 = Unpack32();
                 val = (T)(object)(int)iValue2;
             }
         }
     }
 }
Esempio n. 18
0
 public void Visit <T>(uint tag, string name, bool require, ref List <T> val)
 {
     if (SkipToTag(tag))
     {
         SdpPackDataType type = UnPackHead(ref tag);
         if (type == SdpPackDataType.SdpPackDataType_Vector)
         {
             uint iSize = Unpack32();
             if (val == null)
             {
                 val = new List <T>((int)iSize);
             }
             ISerializer ser = Sdp.GetSerializer <T>();
             for (uint i = 0; i < iSize; ++i)
             {
                 T t = Activator.CreateInstance <T>();
                 t = (T)ser.Read(this, 0, require, t);
                 val.Add(t);
             } //for
         }     //if
     }         //if
 }
Esempio n. 19
0
        public bool SkipToTag(uint iTag)
        {
            uint            iCurTag = 0u;
            SdpPackDataType eType   = SdpPackDataType.SdpPackDataType_Integer_Positive;

            while (_CurPos < _Size)
            {
                uint i = PeekHead(ref iCurTag, ref eType);

                if (eType == SdpPackDataType.SdpPackDataType_StructEnd || iCurTag > iTag)
                {
                    break;
                }

                if (iCurTag == iTag)
                {
                    return(true);
                }
                Skip(i);
                SkipField(eType);
            }
            return(false);
        }
Esempio n. 20
0
 public void Visit(uint tag, string name, bool require, ref IDictionary val, ISerializer keySer, Type keyType, ISerializer valSer, Type valType)
 {
     if (SkipToTag(tag))
     {
         SdpPackDataType type = UnPackHead(ref tag);
         if (type == SdpPackDataType.SdpPackDataType_Map)
         {
             uint iSize = Unpack32();
             for (var i = 0; i < iSize; ++i)
             {
                 object key   = Activator.CreateInstance(keyType);
                 object value = Activator.CreateInstance(valType);
                 key   = keySer.Read(this, 0, require, key);
                 value = valSer.Read(this, 0, require, value);
                 if (val.Contains(key))
                 {
                     val.Remove(key);
                 }
                 val.Add(key, value);
             } //for
         }     //if
     }         //if
 }