Beispiel #1
0
        public void TestBufferRoundTrip()
        {
            var marshalled            = BinaryHelpers.MarshalStruct(BenchmarkStructure);
            var unmarshalledStructure = BinaryHelpers.BufferToStructure <SimpleStructure>(marshalled);

            Assert.AreEqual(BenchmarkStructure.StringValue, unmarshalledStructure.StringValue);
            Assert.AreEqual(BenchmarkStructure.IntValue, unmarshalledStructure.IntValue);
            Assert.AreEqual(BenchmarkStructure.FloatValue, unmarshalledStructure.FloatValue);
            CollectionAssert.AreEqual(BenchmarkStructure.ByteArray, unmarshalledStructure.ByteArray);
        }
Beispiel #2
0
        public void TestBufferUnmarshal()
        {
            byte[] inData =
            {
                // StringValue
                0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21, 0x00, 0x00, 0x00, 0x00,
                // IntValue
                0x39, 0x05, 0x00, 0x00,
                // FloatValue
                0x00, 0x20, 0xa7, 0x44,
                // ByteArray
                0x13, 0x37, 0x73, 0x31, 0x12, 0x34, 0x56, 0x78
            };

            var unmarshalledStructure = BinaryHelpers.BufferToStructure <SimpleStructure>(inData);

            Assert.AreEqual(BenchmarkStructure.StringValue, unmarshalledStructure.StringValue);
            Assert.AreEqual(BenchmarkStructure.IntValue, unmarshalledStructure.IntValue);
            Assert.AreEqual(BenchmarkStructure.FloatValue, unmarshalledStructure.FloatValue);
            CollectionAssert.AreEqual(BenchmarkStructure.ByteArray, unmarshalledStructure.ByteArray);
        }