예제 #1
0
        public ByteBufferBenchmark()
        {
            var unpooled = new UnpooledByteBufferAllocator(true);

            this.unpooledBuffer = unpooled.Buffer(8);
            this.pooledBuffer   = PooledByteBufferAllocator.Default.Buffer(8);
        }
예제 #2
0
        public void NoZeroOut()
        {
            const string Boundary = "E832jQp_Rq2ErFmAduHSR8YlMSm0FCY";

            var aMemFactory = new DefaultHttpDataFactory(false);
            var aRequest    = new DefaultHttpRequest(HttpVersion.Http11, HttpMethod.Post, "http://localhost");

            aRequest.Headers.Set(HttpHeaderNames.ContentType, "multipart/form-data; boundary=" + Boundary);
            aRequest.Headers.Set(HttpHeaderNames.TransferEncoding, HttpHeaderValues.Chunked);

            var aDecoder = new HttpPostRequestDecoder(aMemFactory, aRequest);

            const string BodyData = "some data would be here. the data should be long enough that it " +
                                    "will be longer than the original buffer length of 256 bytes in " +
                                    "the HttpPostRequestDecoder in order to trigger the issue. Some more " +
                                    "data just to be on the safe side.";

            const string Body = "--" + Boundary + "\r\n" +
                                "Content-Disposition: form-data; name=\"root\"\r\n" +
                                "Content-Type: text/plain\r\n" +
                                "\r\n" +
                                BodyData +
                                "\r\n" +
                                "--" + Boundary + "--\r\n";

            byte[]    aBytes = Encoding.UTF8.GetBytes(Body);
            const int Split  = 125;

            UnpooledByteBufferAllocator aAlloc = UnpooledByteBufferAllocator.Default;
            IByteBuffer aSmallBuf = aAlloc.Buffer(Split, Split);
            IByteBuffer aLargeBuf = aAlloc.Buffer(aBytes.Length - Split, aBytes.Length - Split);

            aSmallBuf.WriteBytes(aBytes, 0, Split);
            aLargeBuf.WriteBytes(aBytes, Split, aBytes.Length - Split);

            aDecoder.Offer(new DefaultHttpContent(aSmallBuf));
            aDecoder.Offer(new DefaultHttpContent(aLargeBuf));
            aDecoder.Offer(EmptyLastHttpContent.Default);

            Assert.True(aDecoder.HasNext);
            IInterfaceHttpData aDecodedData = aDecoder.Next();

            Assert.Equal(HttpDataType.Attribute, aDecodedData.DataType);

            var aAttr = (IAttribute)aDecodedData;

            Assert.Equal(BodyData, aAttr.Value);

            aDecodedData.Release();
            aDecoder.Destroy();
        }
예제 #3
0
        /*private uint GetHeader(IByteBuffer content)
         * {
         *  var header = content.ReadInt();
         *  content.DiscardReadBytes();
         *  return (uint)header;
         * }*/

        public IByteBuffer Serialize(IPacket packet)
        {
            try
            {
                var buffer = new UnpooledByteBufferAllocator().Buffer();

                buffer.WriteBytes(
                    MessagePackSerializer.Serialize(new BasicPacketCapsule()
                {
                    Identifier = packet.GetType().GetCustomAttribute <PacketPropertiesAttribute>().Identifier,
                    Packet     = MessagePackSerializer.Serialize(packet.GetType(), packet)
                }));

                /*buffer.WriteInt((int)packet.GetType().GetCustomAttribute<PacketPropertiesAttribute>().Identifier);
                 * buffer.WriteBytes(MessagePackSerializer.Typeless.Serialize(packet));*/

                return(buffer);
            }
            catch (Exception e)
            {
                _log.Error("[SERIALIZE]", e);
                return(null);
            }
        }