Пример #1
0
 public static void Encode(XdrDataOutputStream stream, Uint64 encodedUint64)
 {
     stream.WriteLong(encodedUint64.InnerValue);
 }
Пример #2
0
        public void XdrCompatibilityTest()
        {
            var testArray = new byte[32];

            Array.Fill(testArray, (byte)100);

            //forward compatibility
            var legacyXdrSerializationStream = new XdrDataOutputStream();

            legacyXdrSerializationStream.WriteInt(435);
            legacyXdrSerializationStream.WriteUInt(435);
            legacyXdrSerializationStream.WriteLong(43546345634657565L);
            legacyXdrSerializationStream.WriteDoubleArray(new double[] { 435.15, 64656.11 });
            legacyXdrSerializationStream.WriteString("oiewurouqwe");
            legacyXdrSerializationStream.WriteVarOpaque(32, testArray);

            var bufferReader = new XdrBufferReader(legacyXdrSerializationStream.ToArray());

            Assert.AreEqual(435, bufferReader.ReadInt32());
            Assert.AreEqual((uint)435, bufferReader.ReadUInt32());
            Assert.AreEqual(43546345634657565L, bufferReader.ReadInt64());
            {
                var length = bufferReader.ReadInt32();
                var value  = new double[length];
                for (var i = 0; i < length; i++)
                {
                    value[i] = bufferReader.ReadDouble();
                }
                Assert.AreEqual(new double[] { 435.15, 64656.11 }, value);
            }
            Assert.AreEqual("oiewurouqwe", bufferReader.ReadString());
            Assert.AreEqual(testArray, bufferReader.ReadVariable());

            using var streamReader = new XdrStreamReader(new MemoryStream(legacyXdrSerializationStream.ToArray()));
            Assert.AreEqual(435, streamReader.ReadInt32());
            Assert.AreEqual((uint)435, streamReader.ReadUInt32());
            Assert.AreEqual(43546345634657565L, streamReader.ReadInt64());
            {
                var length = streamReader.ReadInt32();
                var value  = new double[length];
                for (var i = 0; i < length; i++)
                {
                    value[i] = streamReader.ReadDouble();
                }
                Assert.AreEqual(new double[] { 435.15, 64656.11 }, value);
            }
            Assert.AreEqual("oiewurouqwe", streamReader.ReadString());
            Assert.AreEqual(testArray, streamReader.ReadVariable());

            //backward compatibility
            var bufferWriter = new XdrBufferWriter();

            bufferWriter.WriteInt32(435);
            bufferWriter.WriteUInt32((uint)435);
            {
                var arr = new double[] { 435.15, 64656.11 };
                bufferWriter.WriteInt32(arr.Length);
                foreach (var d in arr)
                {
                    bufferWriter.WriteDouble(d);
                }
            }
            bufferWriter.WriteString("oiewurouqwe");
            bufferWriter.WriteVariable(testArray);

            var legacyXdrReader = new XdrDataInputStream(bufferWriter.ToArray());

            Assert.AreEqual(435, legacyXdrReader.ReadInt());
            Assert.AreEqual((uint)435, legacyXdrReader.ReadUInt());
            Assert.AreEqual(new double[] { 435.15, 64656.11 }, legacyXdrReader.ReadDoubleArray());
            Assert.AreEqual("oiewurouqwe", legacyXdrReader.ReadString());
            Assert.AreEqual(testArray, legacyXdrReader.ReadVarOpaque(32));


            using var memoryStream = new MemoryStream();
            var streamWriter = new XdrStreamWriter(memoryStream);

            streamWriter.WriteInt32(435);
            streamWriter.WriteUInt32((uint)435);
            {
                var arr = new double[] { 435.15, 64656.11 };
                streamWriter.WriteInt32(arr.Length);
                foreach (var d in arr)
                {
                    streamWriter.WriteDouble(d);
                }
            }
            streamWriter.WriteString("oiewurouqwe");
            streamWriter.WriteVariable(testArray);
            var res       = memoryStream.ToArray();
            var reference = bufferWriter.ToArray();

            CollectionAssert.AreEqual(reference, res);
        }