public unsafe Message Serialize(MessageInfo msgInfo, object command, bool compress, MessageKey key)
        {
            // InternalHeader kadar boşluk bırakıyor. En son header yazacağız.
            SerializerDATA data = new SerializerDATA();

            // Internal header
            MessageHeader iHeader = msgInfo.CreateMessageHeader();

            // Unique ID
            UniqueID uid = UniqueID.CreateNew();
            iHeader.UniqueID1 = uid.Data1;
            iHeader.UniqueID2 = uid.Data2;
            iHeader.UniqueID3 = uid.Data3;
            iHeader.UniqueID4 = uid.Data4;

            // CommandID
            iHeader.CommandID = MessageAttribute.GetMessageID(command);

            // Komutumuzu yaz
            AddStruct(command, data);

            // Yeni boyutumuz
            iHeader.Size = data.size;
            iHeader.CRC = iHeader.Size ^ Message.CRC_MAGIC_NUMBER;

            // Verinin CMD kısmını sıkıştır. Header'a dokunma.
            if (compress)
            {
                throw new NotSupportedException("Compression is not supported");
            }
            else
            {
                iHeader.Structure = MessageStructure.Default;
            }

            // Encrypt the data
            if (key != null)
            {
                // Sign the data as encrypted
                iHeader.Structure = iHeader.Structure | MessageStructure.Encrypted;

                // Values
                int m = 0;
                byte[] pwd = key.Pwd;
                int keySize = pwd.Length;

                // Loop // TODO: Make some performance improvments.
                for (int k = Message.MESSAGE_INTERNAL_HEADER_SIZE; k < iHeader.Size; k++)
                {
                    data.data[k] = (byte)(data.data[k] ^ pwd[m]);
                    m++;
                    m = m % keySize;
                }
            }

            // Baş tarafa header yaz
            data.size = 0;
            AddStruct(iHeader, data);
            data.size = iHeader.Size;

            return new Message(iHeader, data.data, iHeader.Size);
        }
示例#2
0
        public static Message Create(MessageInfo info, object obj, bool compress, MessageKey key = null)
#endif
        {
            return s_serializer.Serialize(info, obj, compress, key);
        }
示例#3
0
        public static object Parse(byte[] data, MessageHeader header, MessageKey key = null)
#endif
        {
            return s_deserializer.Deserialize(header, data, key);
        }
示例#4
0
 public static Message Create(MessageInfo info, object obj, bool compress, MessageKey key)
示例#5
0
 public static object Parse(byte[] data, MessageHeader header, MessageKey key)