public async Task BuilderDeserialize() { using (var memoryStream = new MemoryStream()) { using (var builder = new MessageProtocolWriter(memoryStream)) { builder.Write( ab => ab.Write("GET"), ab => ab.Write("key1"), ab => ab.Write(true), ab => ab.Write(5), ab => ab.Write(1.2d), ab => ab.Write((long)int.MaxValue + 1), ab => ab.WriteError("errorcod", "error message")); await builder.FlushAsync(); Assert.IsTrue(memoryStream.Length > 0); } memoryStream.Position = 0; var commands = await CommandSerializer.DeserializeAsync(memoryStream); Assert.AreEqual(1, commands.Count); var command = commands[0]; Assert.AreEqual("GET", command.Keyword); Assert.AreEqual("key1", (command.Parameters.Span[0] as StringProtocolObject)?.Value); Assert.AreEqual(true, (command.Parameters.Span[1] as BooleanProtocolObject)?.Value); Assert.AreEqual(5, (command.Parameters.Span[2] as IntegerProtocolObject)?.Value); Assert.AreEqual(1.2d, (command.Parameters.Span[3] as DoubleProtocolObject)?.Value); Assert.AreEqual((long)int.MaxValue + 1, (command.Parameters.Span[4] as LongProtocolObject)?.Value); Assert.AreEqual("errorcod", (command.Parameters.Span[5] as ErrorProtocolObject)?.Code); Assert.AreEqual("error message", (command.Parameters.Span[5] as ErrorProtocolObject)?.Message); } }
public async Task DeserializeTest() { using (var memStream = new MemoryStream()) using (var binaryWriter = new BinaryWriter(memStream)) { binaryWriter.Write(new ArrayProtocolObject { Items = new MessageProtocolObject[] { new StringProtocolObject { Value = "SET" }, new StringProtocolObject { Value = "Test:Key:SubKey" }, new BlobProtocolObject { Bytes = Guid.NewGuid().ToByteArray() } } }); memStream.Position = 0; var commands = await CommandSerializer.DeserializeAsync(memStream); Assert.AreEqual(1, commands.Count); Assert.AreEqual("SET", commands[0].Keyword); Assert.AreEqual(2, commands[0].Parameters.Length); var parameters = commands[0].Parameters.ToArray(); Assert.IsInstanceOfType(parameters[0], typeof(StringProtocolObject)); var param1String = parameters[0] as StringProtocolObject; Assert.AreEqual("Test:Key:SubKey", param1String.Value); Assert.IsInstanceOfType(parameters[1], typeof(BlobProtocolObject)); } }