Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testCanDoStreamingStructUnpacking() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void TestCanDoStreamingStructUnpacking()
        {
            // Given
            Machine machine = new Machine();

            PackStream.Packer packer = machine.Packer();
            packer.PackStructHeader(4, ( sbyte )'~');
            packer.pack(1);
            packer.pack(2);
            packer.pack(3);
            packer.PackListHeader(2);
            packer.pack(4);
            packer.pack(5);
            packer.Flush();

            // When I unpack this value
            PackStream.Unpacker unpacker = NewUnpacker(machine.Output());

            // Then I can do streaming unpacking
            long size      = unpacker.UnpackStructHeader();
            char signature = unpacker.UnpackStructSignature();
            long a         = unpacker.UnpackLong();
            long b         = unpacker.UnpackLong();
            long c         = unpacker.UnpackLong();

            long innerSize = unpacker.UnpackListHeader();
            long d         = unpacker.UnpackLong();
            long e         = unpacker.UnpackLong();

            // And all the values should be sane
            assertEquals(4, size);
            assertEquals('~', signature);
            assertEquals(2, innerSize);
            assertEquals(1, a);
            assertEquals(2, b);
            assertEquals(3, c);
            assertEquals(4, d);
            assertEquals(5, e);
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void testCanPackAndUnpackStruct() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void TestCanPackAndUnpackStruct()
        {
            // Given
            Machine machine = new Machine();

            // When
            PackStream.Packer packer = machine.Packer();
            packer.PackStructHeader(3, ( sbyte )'N');
            packer.pack(12);
            packer.PackListHeader(2);
            packer.Pack("Person");
            packer.Pack("Employee");
            packer.PackMapHeader(2);
            packer.Pack("name");
            packer.Pack("Alice");
            packer.Pack("age");
            packer.pack(33);
            packer.Flush();
            PackStream.Unpacker unpacker = NewUnpacker(machine.Output());

            // Then
            assertThat(unpacker.UnpackStructHeader(), equalTo(3L));
            assertThat(unpacker.UnpackStructSignature(), equalTo('N'));

            assertThat(unpacker.UnpackLong(), equalTo(12L));

            assertThat(unpacker.UnpackListHeader(), equalTo(2L));
            assertThat(unpacker.UnpackString(), equalTo("Person"));
            assertThat(unpacker.UnpackString(), equalTo("Employee"));

            assertThat(unpacker.UnpackMapHeader(), equalTo(2L));
            assertThat(unpacker.UnpackString(), equalTo("name"));
            assertThat(unpacker.UnpackString(), equalTo("Alice"));
            assertThat(unpacker.UnpackString(), equalTo("age"));
            assertThat(unpacker.UnpackLong(), equalTo(33L));
        }