Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static byte[] chunk(int maxChunkSize, byte[][] messages) throws java.io.IOException
        public static sbyte[] Chunk(int maxChunkSize, sbyte[][] messages)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ByteBuffer outputBuffer = ByteBuffer.allocate(1024 * 8);
            ByteBuffer outputBuffer = ByteBuffer.allocate(1024 * 8);

            Channel ch = mock(typeof(Channel));

            when(ch.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
            when(ch.writeAndFlush(any(), Null)).then(inv =>
            {
                ByteBuf buf = inv.getArgument(0);
                outputBuffer.limit(outputBuffer.position() + buf.readableBytes());
                buf.readBytes(outputBuffer);
                buf.release();
                return(null);
            });

            int           maxBufferSize = maxChunkSize + CHUNK_HEADER_SIZE;
            ChunkedOutput @out          = new ChunkedOutput(ch, maxBufferSize, maxBufferSize, TransportThrottleGroup.NO_THROTTLE);

            foreach (sbyte[] message in messages)
            {
                @out.BeginMessage();
                @out.WriteBytes(message, 0, message.Length);
                @out.MessageSucceeded();
            }
            @out.Flush();
            @out.Dispose();

            sbyte[] bytes = new sbyte[outputBuffer.limit()];
            outputBuffer.position(0);
            outputBuffer.get(bytes);
            return(bytes);
        }
Exemple #2
0
        public static ReplicatedTransaction Decode(ByteBuf byteBuf)
        {
            int length = byteBuf.readableBytes();

            sbyte[] bytes = new sbyte[length];
            byteBuf.readBytes(bytes);
            return(ReplicatedTransaction.from(bytes));
        }
Exemple #3
0
        public static DummyRequest Decode(ByteBuf byteBuf)
        {
            int length = byteBuf.readableBytes();

            sbyte[] array = new sbyte[length];
            byteBuf.readBytes(array);
            return(new DummyRequest(array));
        }
Exemple #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldWriteToBufferInChunks()
        public virtual void ShouldWriteToBufferInChunks()
        {
            int chunkSize = 5;

            sbyte[] data     = new sbyte[] { 1, 2, 3, 4, 5, 6 };
            sbyte[] readData = new sbyte[6];
            ByteArrayChunkedEncoder byteArraySerializer = new ByteArrayChunkedEncoder(data, chunkSize);

            ByteBuf buffer = byteArraySerializer.ReadChunk(Buffers);

            buffer.readBytes(readData, 0, chunkSize);
            assertEquals(0, buffer.readableBytes());

            buffer = byteArraySerializer.ReadChunk(Buffers);
            buffer.readBytes(readData, chunkSize, 1);
            assertArrayEquals(data, readData);
            assertEquals(0, buffer.readableBytes());

            assertNull(byteArraySerializer.ReadChunk(Buffers));
        }
Exemple #5
0
        public static string Unmarshal(ByteBuf buffer)
        {
            int len = buffer.readInt();

            if (len == NULL_STRING_LENGTH)
            {
                return(null);
            }

            sbyte[] bytes = new sbyte[len];
            buffer.readBytes(bytes);
            return(StringHelper.NewString(bytes, UTF_8));
        }
Exemple #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void get(byte[] bytes, int length) throws java.io.IOException
        public override void Get(sbyte[] bytes, int length)
        {
            EnsureBytes(length);
            @delegate.readBytes(bytes, 0, length);
        }
Exemple #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public PackInput readBytes(byte[] into, int offset, int toRead) throws java.io.IOException
        public override PackInput ReadBytes(sbyte[] into, int offset, int toRead)
        {
            _buf.readBytes(into, offset, toRead);
            return(this);
        }