Beispiel #1
0
        //public bool CryptoPackage<T>(T msg, Func<MemoryStream, MemoryStream, bool> func)
        //{
        //    MemoryStream body = new MemoryStream();
        //    ProtoBuf.Serializer.Serialize(body, msg);
        //    UInt16 protobufLen = (ushort)body.Length;

        //    if (blowFishInst != null && protobufLen > 0)
        //    {
        //        body = blowFishInst.Encrypt_CBC(body);
        //    }

        //    UInt16 len = (ushort)body.Length;
        //    MemoryStream header = new MemoryStream(PacketHeader.Size);

        //    header.Write(BitConverter.GetBytes(len), 0, 2);
        //    header.Write(BitConverter.GetBytes(protobufLen), 0, 2);
        //    header.Write(BitConverter.GetBytes(Engine.Foundation.Id<T>.Value), 0, 4);

        //    return func(header, body);
        //}

        //public bool Package<T>(T msg, Func<MemoryStream, bool> func)
        //{
        //    MemoryStream body = new MemoryStream();
        //    ProtoBuf.Serializer.Serialize(body, msg);

        //    UInt16 protobufLen = (ushort)body.Length;
        //    UInt16 len = (ushort)body.Length;
        //    //if (blowFishInst != null && protobufLen > 0)
        //    //{
        //    //    body = blowFishInst.Encrypt_CBC(body);
        //    //}
        //    MemoryStream packet = new MemoryStream(PacketHeader.Size);

        //    packet.Write(BitConverter.GetBytes(len), 0, 2);
        //    packet.Write(BitConverter.GetBytes(protobufLen), 0, 2);
        //    packet.Write(BitConverter.GetBytes(Engine.Foundation.Id<T>.Value), 0, 4);
        //    packet.Write(body.GetBuffer(), 0, len);

        //    return func(packet);
        //}
        public bool Package1 <T>(T msg, Func <MemoryStream, bool> func, uint msgid) where T : Google.Protobuf.IMessage <T>
        {
            MemoryStream body = new MemoryStream();

            Google.Protobuf.CodedOutputStream outbody = new Google.Protobuf.CodedOutputStream(body);
            outbody.WriteGroup(msg);
            outbody.Flush();
            UInt16 protobufLen = (ushort)body.Length;
            UInt16 len         = (ushort)body.Length;
            //if (blowFishInst != null && protobufLen > 0)
            //{
            //    body = blowFishInst.Encrypt_CBC(body);
            //}
            MemoryStream packet = new MemoryStream(PacketHeader.Size);

            packet.Write(BitConverter.GetBytes(len), 0, 2);
            //packet.Write(BitConverter.GetBytes(protobufLen), 0, 2);
            packet.Write(BitConverter.GetBytes(msgid), 0, 4);
            packet.Write(body.GetBuffer(), 0, len);

            return(func(packet));
        }