Example #1
0
        public void TestEncoderDecoder()
        {
            Value value = new Value(new SubValue(new SubSubValue("")), Value.bytes);

            Value decoded = new Value();

            this.Measure(() => {
                byte[] buffer = new byte[8 * 1024];
                int length    = BinaryEncoder.Encode(value, buffer, 0);

                Logger.Log($"Encoded message size: {length}");

                decoded = BinaryDecoder.Decode <Value>(buffer, 0, length);
            }, "Encoder and Decoder");

            Assert.AreEqual(value.intVal, decoded.intVal);
            Assert.AreEqual(value.shortVal, decoded.shortVal);
            Assert.AreEqual(value.longVal, decoded.longVal);
            Assert.AreEqual(value.uintVal, decoded.uintVal);
            Assert.AreEqual(value.ushortVal, decoded.ushortVal);
            Assert.AreEqual(value.ulongVal, decoded.ulongVal);
            Assert.AreEqual(value.stringVal, decoded.stringVal);
            Assert.AreEqual(value.bytesVal, decoded.bytesVal);
            Assert.AreEqual(value.subValue, decoded.subValue);
            Assert.AreEqual(value.subValue?.subSubValue.empty, decoded.subValue?.subSubValue.empty);
        }
Example #2
0
        public void TestDecoder()
        {
            Value value = new Value(new SubValue(new SubSubValue("")), Value.bytes);

            byte[] buffer = new byte[8 * 1024];
            int    length = BinaryEncoder.Encode(value, buffer, 0);

            this.Measure(() => {
                _ = BinaryDecoder.Decode <Value>(buffer, 0, length);
            }, "Decoder");
        }
Example #3
0
 public TMessage Parse <TMessage>() where TMessage : struct, IDecodable
 => BinaryDecoder.Decode <TMessage>(this._buffer, sizeof(int), this._length - sizeof(int));