Exemple #1
0
 internal bool DeSerializeTcpServer <valueType>(ref SubArray <byte> data, ref valueType value)
 {
     fixed(byte *dataFixed = data.GetFixedBuffer())
     {
         end = (jsonFixed = Current = (char *)(dataFixed + data.Start)) + (data.Length >> 1);
         return(deSerializeTcpServer(ref value));
     }
 }
        public static DeSerializeResult DeSerialize <valueType>(ref SubArray <byte> data, ref valueType value, DeSerializeConfig config = null)
        {
            if (data.Length == 0)
            {
                return new DeSerializeResult {
                           State = DeSerializeState.UnknownData
                }
            }
            ;

            fixed(byte *dataFixed = data.GetFixedBuffer()) return(DeSerialize <valueType>(data.Array, dataFixed + data.Start, data.Length, ref value, config));
        }
Exemple #3
0
 /// <summary>
 /// 字节数组 HASH
 /// </summary>
 /// <param name="data">字节数组</param>
 public unsafe HashBytes(ref SubArray <byte> data)
 {
     SubArray = data;
     if (data.Length == 0)
     {
         HashCode = 0;
     }
     else
     {
         fixed(byte *dataFixed = data.GetFixedBuffer()) HashCode = AutoCSer.Memory.Common.GetHashCode(dataFixed + data.Start, data.Length) ^ Random.Hash;
     }
 }
        /// <summary>
        /// 反序列化
        /// </summary>
        /// <typeparam name="valueType">数据类型</typeparam>
        /// <param name="data">数据</param>
        /// <param name="value">目标对象</param>
        /// <returns>是否成功</returns>
        internal bool DeSerializeTcpServer <valueType>(ref SubArray <byte> data, ref valueType value)
        {
            if (data.Length >= sizeof(int) * 3 && (data.Length & 3) == 0)
            {
                fixed(byte *dataFixed = (Buffer = data.GetFixedBuffer()))
                {
                    start = dataFixed + (bufferIndex = data.Start);
                    int length = data.Length - sizeof(int);

                    End = start + length;
                    if (((uint)(*(int *)End ^ length) | ((*(uint *)start & SerializeConfig.HeaderMapAndValue) ^ SerializeConfig.HeaderMapValue)) == 0)
                    {
                        //MemberMap = null;
                        getGlobalVersion();
                        if (isReferenceMember == TypeDeSerializer <valueType> .IsReferenceMember)
                        {
                            if (points != null)
                            {
                                points.Clear();
                            }
                        }
                        else
                        {
                            if (isReferenceMember)
                            {
                                isReferenceMember = false;
                            }
                            else
                            {
                                isReferenceMember = true;
                                if (points == null)
                                {
                                    points = ReusableDictionary.CreateInt <object>();
                                }
                                else
                                {
                                    points.Clear();
                                }
                            }
                        }
                        isReferenceArray = true;
                        State            = DeSerializeState.Success;
                        TypeDeSerializer <valueType> .DeSerializeTcpServer(this, ref value);

                        return(State == DeSerializeState.Success && Read == End);
                    }
                }
            }
            return(false);
        }
Exemple #5
0
        /// <summary>
        /// 判断时间是否相等
        /// </summary>
        /// <param name="date"></param>
        /// <param name="dataArray"></param>
        /// <returns></returns>
        internal unsafe static int UniversalByteEquals(DateTime date, SubArray <byte> dataArray)
        {
            fixed(byte *dataFixed = dataArray.GetFixedBuffer())
            {
                byte *data = dataFixed + dataArray.Start;

                if (((*(int *)data ^ weekData.Int[(int)date.DayOfWeek]) | (*(data + sizeof(int) * 7) ^ (byte)'T')) != 0)
                {
                    return(1);
                }
                int value = date.Day, value10 = (value * (int)NumberExtension.Div10_16Mul) >> NumberExtension.Div10_16Shift;

                if (*(int *)(data + sizeof(int)) != ((' ' + (value10 << 8) + ((value - value10 * 10) << 16) + (' ' << 24)) | 0x303000))
                {
                    return(1);
                }
                value = date.Year;
                if (*(int *)(data + sizeof(int) * 2) != monthData.Int[date.Month - 1])
                {
                    return(1);
                }
                value10 = (value * (int)NumberExtension.Div10_16Mul) >> NumberExtension.Div10_16Shift;
                int value100  = (value10 * (int)NumberExtension.Div10_16Mul) >> NumberExtension.Div10_16Shift;
                int value1000 = (value100 * (int)NumberExtension.Div10_16Mul) >> NumberExtension.Div10_16Shift;

                if (*(int *)(data + sizeof(int) * 3) != ((value1000 + ((value100 - value1000 * 10) << 8) + ((value10 - value100 * 10) << 16) + ((value - value10 * 10) << 24)) | 0x30303030))
                {
                    return(1);
                }


                value100   = (int)(date.Ticks % TimeSpan.TicksPerDay / TimeSpan.TicksPerSecond);
                value1000  = (int)(((ulong)value100 * Div60_32Mul) >> Div60_32Shift);
                value100  -= value1000 * 60;
                value      = (value1000 * (int)Div60_16Mul) >> Div60_16Shift;
                value1000 -= value * 60;

                value10 = (value * (int)NumberExtension.Div10_16Mul) >> NumberExtension.Div10_16Shift;
                if (*(int *)(data + sizeof(int) * 4) != ((' ' + (value10 << 8) + ((value - value10 * 10) << 16) + (':' << 24)) | 0x303000))
                {
                    return(1);
                }
                value10 = (value1000 * (int)NumberExtension.Div10_16Mul) >> NumberExtension.Div10_16Shift;
                value   = (value100 * (int)NumberExtension.Div10_16Mul) >> NumberExtension.Div10_16Shift;
                return((*(int *)(data + sizeof(int) * 5) ^ ((value10 + ((value1000 - value10 * 10) << 8) + (':' << 16) + (value << 24)) | 0x30003030))
                       | (*(int *)(data + sizeof(int) * 6) ^ ((value100 - value * 10) + '0') + (' ' << 8) + ('G' << 16) + ('M' << 24)));
            }
        }
        public static valueType DeSerialize <valueType>(ref SubArray <byte> data, DeSerializeConfig config = null)
        {
            if (data.Length != 0)
            {
                fixed(byte *dataFixed = data.GetFixedBuffer())
                {
                    valueType value = default(valueType);

                    if (DeSerialize <valueType>(data.Array, dataFixed + data.Start, data.Length, ref value, config))
                    {
                        return(value);
                    }
                }
            }
            return(default(valueType));
        }
Exemple #7
0
 /// <summary>
 /// 写字节数据
 /// </summary>
 /// <param name="charStream"></param>
 /// <param name="buffer"></param>
 internal void WriteBytes(CharStream charStream, ref SubArray <byte> buffer)
 {
     fixed(byte *bufferFixed = buffer.GetFixedBuffer())
     {
         if ((Type & (EncodingType.Ascii | EncodingType.Unicode)) == 0)
         {
             Encoding.GetBytes(charStream.Char, charStream.Data.CurrentIndex >> 1, bufferFixed + buffer.Start, buffer.Length);
         }
         else if ((Type & EncodingType.Unicode) != 0)
         {
             AutoCSer.Memory.Common.CopyNotNull(charStream.Char, bufferFixed + buffer.Start, buffer.Length);
         }
         else
         {
             AutoCSer.Extensions.StringExtension.WriteBytes(charStream.Char, buffer.Length, bufferFixed + buffer.Start);
         }
     }
 }