public void Verify(Stream stream) { stream.Position = 0; var data = Unpacking.UnpackObject(stream); NUnit.Framework.Assert.That(data, Is.Not.Null); if (data.IsDictionary) { var map = data.AsDictionary(); NUnit.Framework.Assert.That(map.ContainsKey("Source")); NUnit.Framework.Assert.That(map["Source"].AsString(), Is.EqualTo(this.Source.ToString())); NUnit.Framework.Assert.That(map.ContainsKey("TimeStamp")); NUnit.Framework.Assert.That(map["TimeStamp"].AsTimestamp().ToDateTime(), Is.EqualTo(this.TimeStamp.ToUniversalTime())); NUnit.Framework.Assert.That(map.ContainsKey("Data")); NUnit.Framework.Assert.That(map["Data"].AsBinary(), Is.EqualTo(this.Data)); NUnit.Framework.Assert.That(map.ContainsKey("History")); NUnit.Framework.Assert.That(map["History"].AsDictionary().Count, Is.EqualTo(this.History.Count)); NUnit.Framework.Assert.That(!map.ContainsKey("NonSerialized")); } else { var array = data.AsList(); NUnit.Framework.Assert.That(array.Count, Is.EqualTo(4)); NUnit.Framework.Assert.That(array[0].AsString(), Is.EqualTo(this.Source.ToString())); NUnit.Framework.Assert.That(array[2].AsTimestamp().ToDateTime(), Is.EqualTo(this.TimeStamp.ToUniversalTime())); NUnit.Framework.Assert.That(array[1].AsBinary(), Is.EqualTo(this.Data)); NUnit.Framework.Assert.That(array[3].AsDictionary().Count, Is.EqualTo(this.History.Count)); } }
private void TestEnumForByUnderlyingValue <T>(SerializationContext context, T value, string property) { var serializer = context.GetSerializer <T>(); using (var stream = new MemoryStream()) { serializer.Pack(stream, value); stream.Position = 0; var deserialized = serializer.Unpack(stream); if (property == null) { Assert.That(deserialized, Is.EqualTo(value)); stream.Position = 0; var result = Unpacking.UnpackObject(stream); Assert.That( result.ToString().Equals((( IFormattable )value).ToString("D", null)), result + " == " + (( IFormattable )value).ToString("D", null) ); } else { var propertyInfo = typeof(T).GetProperty(property); Assert.That(propertyInfo.GetValue(deserialized, null), Is.EqualTo(propertyInfo.GetValue(value, null))); stream.Position = 0; var result = Unpacking.UnpackArray(stream); // Properties are sorted by lexical order var index = Array.IndexOf(typeof(T).GetProperties().OrderBy(p => p.Name).ToArray(), propertyInfo); Assert.That( result[index].ToString().Equals((( IFormattable )propertyInfo.GetValue(value, null)).ToString("D", null)), result[index] + " == " + (( IFormattable )propertyInfo.GetValue(value, null)).ToString("D", null) ); } } }
private void TestEnumForByUnderlyingValue <T>(SerializationContext context, T value, string property) { var serializer = context.GetSerializer <T>(); using (var stream = new MemoryStream()) { serializer.Pack(stream, value); stream.Position = 0; var deserialized = serializer.Unpack(stream); if (property == null) { Assert.That(deserialized, Is.EqualTo(value)); stream.Position = 0; var result = Unpacking.UnpackObject(stream); Assert.That( result.ToString().Equals((( IFormattable )value).ToString("D", null)), result + " == " + (( IFormattable )value).ToString("D", null) ); } else { var propertyInfo = typeof(T).GetProperty(property); Assert.That(propertyInfo.GetValue(deserialized, null), Is.EqualTo(propertyInfo.GetValue(value, null))); stream.Position = 0; var result = Unpacking.UnpackDictionary(stream); Assert.That( result[property].ToString().Equals((( IFormattable )propertyInfo.GetValue(value, null)).ToString("D", null)), result[property] + " == " + (( IFormattable )propertyInfo.GetValue(value, null)).ToString("D", null) ); } } }
private static void TestEnumForByUnderlyingValueCore <T>(Stream stream, T value, T deserialized, string property) { if (property == null) { Assert.That(deserialized, Is.EqualTo(value)); stream.Position = 0; var result = Unpacking.UnpackObject(stream); Assert.That( result.ToString().Equals((( IFormattable )value).ToString("D", null)), result + " == " + (( IFormattable )value).ToString("D", null) ); } else { var propertyInfo = typeof(T).GetProperty(property); #if !UNITY Assert.That(propertyInfo.GetValue(deserialized, null), Is.EqualTo(propertyInfo.GetValue(value, null))); #else Assert.That(propertyInfo.GetGetMethod().Invoke(deserialized, null), Is.EqualTo(propertyInfo.GetGetMethod().Invoke(value, null))); #endif // !UNITY stream.Position = 0; var result = Unpacking.UnpackArray(stream); // Properties are sorted by lexical order var index = Array.IndexOf(typeof(T).GetProperties().OrderBy(p => p.Name).ToArray(), propertyInfo); Assert.That( #if !UNITY result[index].ToString().Equals((( IFormattable )propertyInfo.GetValue(value, null)).ToString("D", null)), result[index] + " == " + (( IFormattable )propertyInfo.GetValue(value, null)).ToString("D", null) #else result[index].ToString().Equals((( IFormattable )propertyInfo.GetGetMethod().Invoke(value, null)).ToString("D", null)), result[index] + " == " + (( IFormattable )propertyInfo.GetGetMethod().Invoke(value, null)).ToString("D", null) #endif // !UNITY ); } }
private static void TestEnumForByUnderlyingValueCore <T>(Stream stream, T value, T deserialized, string property) { if (property == null) { Assert.That(deserialized, Is.EqualTo(value)); stream.Position = 0; var result = Unpacking.UnpackObject(stream); Assert.That( result.ToString().Equals((( IFormattable )value).ToString("D", null)), result + " == " + (( IFormattable )value).ToString("D", null) ); } else { var propertyInfo = typeof(T).GetProperty(property); #if !UNITY Assert.That(propertyInfo.GetValue(deserialized, null), Is.EqualTo(propertyInfo.GetValue(value, null))); #else Assert.That(propertyInfo.GetGetMethod().Invoke(deserialized, null), Is.EqualTo(propertyInfo.GetGetMethod().Invoke(value, null))); #endif // !UNITY stream.Position = 0; var result = Unpacking.UnpackDictionary(stream); Assert.That( #if !UNITY result[property].ToString().Equals((( IFormattable )propertyInfo.GetValue(value, null)).ToString("D", null)), result[property] + " == " + (( IFormattable )propertyInfo.GetValue(value, null)).ToString("D", null) #else result[property].ToString().Equals((( IFormattable )propertyInfo.GetGetMethod().Invoke(value, null)).ToString("D", null)), result[property] + " == " + (( IFormattable )propertyInfo.GetGetMethod().Invoke(value, null)).ToString("D", null) #endif // !UNITY ); } }
public void Verify(Stream stream) { stream.Position = 0; var data = Unpacking.UnpackObject(stream); NUnit.Framework.Assert.That(data, Is.Not.Null); if (data.IsDictionary) { var map = data.AsDictionary(); NUnit.Framework.Assert.That(map.ContainsKey("Source")); NUnit.Framework.Assert.That(this.Source, Is.Not.Null); NUnit.Framework.Assert.That(map["Source"].AsString(), Is.EqualTo(this.Source.ToString())); NUnit.Framework.Assert.That(map.ContainsKey("TimeStamp")); NUnit.Framework.Assert.That(MessagePackConvert.ToDateTime(map["TimeStamp"].AsInt64()), Is.EqualTo(this.TimeStamp)); NUnit.Framework.Assert.That(map.ContainsKey("Data")); NUnit.Framework.Assert.That(map["Data"].AsBinary(), Is.EqualTo(this.Data)); NUnit.Framework.Assert.That(map.ContainsKey("History")); NUnit.Framework.Assert.That(map["History"].AsDictionary().Count, Is.EqualTo(this.History.Count)); NUnit.Framework.Assert.That(map.ContainsKey("Points")); NUnit.Framework.Assert.That(map["Points"].AsList().Count, Is.EqualTo(this.Points.Count)); } else { var array = data.AsList(); NUnit.Framework.Assert.That(this.Source, Is.Not.Null); NUnit.Framework.Assert.That(array[0].AsString(), Is.EqualTo(this.Source.ToString())); NUnit.Framework.Assert.That(MessagePackConvert.ToDateTime(array[2].AsInt64()), Is.EqualTo(this.TimeStamp)); NUnit.Framework.Assert.That(array[1].AsBinary(), Is.EqualTo(this.Data)); NUnit.Framework.Assert.That(array[3].AsDictionary().Count, Is.EqualTo(this.History.Count)); NUnit.Framework.Assert.That(array[4].AsList().Count, Is.EqualTo(this.Points.Count)); } }
public static Event Deserialize(List <byte[]> envelope, byte[] data) { MessagePackObject payloadData = Unpacking.UnpackObject(data).Value; IList <MessagePackObject> parts; MessagePackObjectDictionary header; if (!payloadData.IsArray || (parts = payloadData.AsList()).Count != 3) { throw new Exception("Expected array of size 3"); } if (!parts[0].IsMap || !(header = parts[0].AsDictionary()).ContainsKey("message_id")) { throw new Exception("Bad header"); } if (parts[1].AsString() == null) { throw new Exception("Bad name"); } var headerObj = new EventHeader { Version = header["v"].AsInt32(), MessageId = ProcessUuid(header, "message_id"), ResponseTo = ProcessUuid(header, "response_to") }; var msg = new Event { Envelope = envelope, Header = headerObj, Name = parts[1].AsString(), Args = parts[2].AsList() }; return(msg); }
public static void Main(string[] args) { using (var file = File.OpenRead(args[0])) { Unpacking.UnpackObject(file); } }
public void TestGetServiceInvoker_ReturnsValidInvoker_ErrorCase_IsDebugMode_NotRpcError_SpecifiedMessage() { using (var target = new ServiceInvokerGenerator(true)) { var arg1 = Guid.NewGuid().ToString(); var arg2 = Environment.TickCount; var message = Guid.NewGuid().ToString(); var rpcError = RpcError.CallError; this.TestGetServiceInvokerCore <string, int, bool>( (sender, e) => { Assert.That(e.Arguments.Length, Is.EqualTo(2)); Assert.That(e.Arguments[0], Is.EqualTo(arg1)); Assert.That(e.Arguments[1], Is.EqualTo(arg2)); e.Exception = new Exception(message); }, new RpcServerConfiguration() { IsDebugMode = true }, arg1, arg2, responseContext => { Assert.That(Unpacking.UnpackObject(responseContext.GetErrorData()).Value.Equals(rpcError.Identifier)); var exception = new RpcException(rpcError, Unpacking.UnpackObject(responseContext.GetReturnValueData()).Value); Assert.That(exception.RpcError.Identifier, Is.EqualTo(rpcError.Identifier)); Assert.That(exception.RpcError.ErrorCode, Is.EqualTo(rpcError.ErrorCode)); Assert.That(exception.Message, Is.EqualTo(message)); Assert.That(exception.DebugInformation, Is.StringContaining(message).And.Not.EqualTo(message)); } ); } }
public void TestGetServiceInvoker_ReturnsValidInvoker_NonErrorCase() { using (var target = new ServiceInvokerGenerator(true)) { var arg1 = Guid.NewGuid().ToString(); var arg2 = Environment.TickCount; var returnValue = true; this.TestGetServiceInvokerCore <string, int, bool>( (sender, e) => { Assert.That(e.Arguments.Length, Is.EqualTo(2)); Assert.That(e.Arguments[0], Is.EqualTo(arg1)); Assert.That(e.Arguments[1], Is.EqualTo(arg2)); e.ReturnValue = returnValue; }, new RpcServerConfiguration() { IsDebugMode = true }, arg1, arg2, responseContext => { Assert.That(Unpacking.UnpackObject(responseContext.GetErrorData()).Value.IsNil, Unpacking.UnpackObject(responseContext.GetErrorData()).Value.ToString()); Assert.That(Unpacking.UnpackObject(responseContext.GetReturnValueData()).Value.AsBoolean()); } ); } }
private static void AssertArraySegment(MessagePackObject expected, ArraySegment <byte> actual) { var result = Unpacking.UnpackObject(actual.AsEnumerable().ToArray()); Assert.That(result.ReadCount, Is.EqualTo(actual.Count)); Assert.That(expected.Equals(result.Value)); }
public void SerializeThenDeserialize() { // They are object for just description. var targetObject = new PhotoEntry // See Sample01_BasicUsage.cs { Id = 123, Title = "My photo", Date = DateTime.Now, Image = new byte[] { 1, 2, 3, 4 }, Comment = "This is test object to be serialize/deserialize using MsgPack." }; targetObject.Tags.Add("Sample"); targetObject.Tags.Add("Excellent"); var stream = new MemoryStream(); // Set using Map instead of Array to serialize complex object. See Sample03 for details. var context = new SerializationContext(); context.SerializationMethod = SerializationMethod.Map; // You can use default context if you want to use map in all serializations which use default context. // SerializationContext.Default.SerializationMethod = SerializationMethod.Map; // 1. Create serializer instance. var serializer = MessagePackSerializer.Get <PhotoEntry>(context); // 2. Serialize object to the specified stream. serializer.Pack(stream, targetObject); // Set position to head of the stream to demonstrate deserialization. stream.Position = 0; // 3. Unpack MessagePackObject to get raw representation. var rawObject = Unpacking.UnpackObject(stream); // You can read MPO tree via Unpacker // var unpacker = Unpacker.Create( stream ); // Check its type Debug.WriteLine("Is array? {0}", rawObject.IsArray); // IsList is alias Debug.WriteLine("Is map? {0}", rawObject.IsMap); // IsDictionary is alias Debug.WriteLine("Type: {0}", rawObject.UnderlyingType); // Gets serialized fields. // Note: When the object was serialized as array instead of map, use index instead. var asDictionary = rawObject.AsDictionary(); Debug.WriteLine("Id : {0}({1})", asDictionary["Id"], asDictionary["Id"].UnderlyingType); // String is encoded as utf-8 by default. Debug.WriteLine("Title : {0}({1})", asDictionary["Title"], asDictionary["Title"].UnderlyingType); // Non-primitive is serialized as complex type or encoded primitive type. // DateTimeOffset is encoded as array[2]{ticks,offset} Debug.WriteLine("Date : {0}({1})", asDictionary["Date"], asDictionary["Date"].UnderlyingType); // byte[] is byte[], as you know. Debug.WriteLine("Image : {0}({1})", asDictionary["Image"], asDictionary["Image"].UnderlyingType); }
private void ReadCompleteNotification(IServiceHandler serviceHandler) { // byte[] dataType = new byte[4]; // byte[] data = new byte[serviceHandler.ReadData.Length - 4]; // Buffer.BlockCopy(serviceHandler.ReadData, 0, dataType, 0, 4); // Buffer.BlockCopy(serviceHandler.ReadData, 4, data, 0, serviceHandler.ReadData.Length - 4); // var integer_serializer = MessagePackSerializer.Get<int>(); // added msg pack deserialiser // var deserializedDataType = integer_serializer.UnpackSingleObject(dataType); // switch(deserializedDataType) // { // case 0: // var clock_serializer = MessagePackSerializer.Get<double>(); // break; // case 1: // var date_serializer = MessagePackSerializer.Get<Array<int, 6>>(); // break; // default: // break; // } var rawObject = Unpacking.UnpackObject(serviceHandler.ReadData); if (rawObject.Value.IsArray) { log.InfoFormat("Is Array ? {0}", rawObject.Value.IsArray); var arrayObject = rawObject.Value.AsList(); List <int> dateList = new List <int>(); foreach (var obj in arrayObject) { dateList.Add(obj.AsInt32()); // log.InfoFormat("Container at {0} is of type {1}", // arrayObject.IndexOf(obj), // obj.UnderlyingType); } string listAsString = string.Join(", ", dateList.ToArray()); log.InfoFormat("Array contains [{0}]", listAsString); } else if (rawObject.Value.UnderlyingType == typeof(double)) { var double_serializer = MessagePackSerializer.Get <double>(); var deserialized = double_serializer.UnpackSingleObject(serviceHandler.ReadData); log.InfoFormat("Message received on {0} : {1} --- {2} : Type is {3}", ((IPEndPoint)serviceHandler.RemoteURI).Address.ToString(), ((IPEndPoint)serviceHandler.RemoteURI).Port.ToString(), deserialized, rawObject.Value.UnderlyingType); } //log.InfoFormat("Message received on {0} : {1} --- {2}", ((IPEndPoint)serviceHandler.RemoteURI).Address.ToString(), // ((IPEndPoint)serviceHandler.RemoteURI).Port.ToString(), deserialized); //var str = System.Text.Encoding.UTF8.GetString(serviceHandler.ReadData); // log.InfoFormat("Message received on {0} : {1} --- {2}", ((IPEndPoint)serviceHandler.RemoteURI).Address.ToString(), // ((IPEndPoint)serviceHandler.RemoteURI).Port.ToString(), str); socketEvent?.Invoke(SocketEventType.ReadCompleteEvent); }
public void TestSerialize_OnNullResult_ReturnValueDataIsNil_ErrorDataIsNil() { TestCore((target, transport) => { target.MessageId = 123; target.Serialize(default(object), RpcErrorMessage.Success, null); Assert.That(Unpacking.UnpackObject(target.GetReturnValueData()).Value.Equals(MessagePackObject.Nil)); Assert.That(Unpacking.UnpackObject(target.GetErrorData()).Value.Equals(MessagePackObject.Nil)); } ); }
public void TestSerialize_OnNotNullResult_ReturnValueDataIsSet_ErrorDataIsNil() { TestCore((target, transport) => { target.MessageId = 123; target.Serialize("Test", RpcErrorMessage.Success, MessagePackSerializer.Create <string>()); Assert.That(Unpacking.UnpackObject(target.GetReturnValueData()).Value.Equals("Test")); Assert.That(Unpacking.UnpackObject(target.GetErrorData()).Value.Equals(MessagePackObject.Nil)); } ); }
public void TestSerialize_OnError_ReturnValueDataIsSet_ErrorDataIsSet() { TestCore((target, transport) => { target.MessageId = 123; target.Serialize(default(object), new RpcErrorMessage(RpcError.CallError, "Detail"), null); Assert.That(Unpacking.UnpackObject(target.GetReturnValueData()).Value.Equals("Detail")); Assert.That(Unpacking.UnpackObject(target.GetErrorData()).Value.Equals(RpcError.CallError.Identifier)); } ); }
void HandleOrphan(ClientResponseContext context) { var error = ErrorInterpreter.UnpackError(context); MessagePackObject?returnValue = null; if (error.IsSuccess) { returnValue = Unpacking.UnpackObject(context.resultBuffer); } HandleOrphan(context.MessageId, context.SessionId, GetRemoteEndPoint(BoundSocket, context), error, returnValue); }
/// <summary> /// Serializes object as a single <see cref="MessagePackObject"/>. /// </summary> /// <typeparam name="T">The type of the object to be serialized.</typeparam> /// <param name="source"><see cref="MessagePackSerializer{T}"/> object.</param> /// <param name="obj">The object to be serialized.</param> /// <returns><see cref="MessagePackObject"/>.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="source"/> is <c>null</c>. /// </exception> /// <exception cref="System.Runtime.Serialization.SerializationException"> /// Failed to serialize. /// </exception> public static MessagePackObject ToMessagePackObject <T>(this MessagePackSerializer <T> source, T obj) { if (source == null) { throw new ArgumentNullException("source"); } using (var buffer = new MemoryStream()) { source.Pack(buffer, obj); buffer.Position = 0; return(Unpacking.UnpackObject(buffer)); } }
private static void TestDataContractAndMessagePackMemberAndNonSerializedAreMixedCore(SerializationMethod method) { var context = new SerializationContext() { SerializationMethod = method }; using (var buffer = new MemoryStream()) { var target = new MessagePackMemberAndDataMemberMixedTarget(); target.ShouldSerialized1 = 111; target.ShouldSerialized2 = 222; target.ShouldSerialized3 = 333; target.ShouldNotSerialized1 = 444; target.ShouldNotSerialized2 = 555; var serializer = MessagePackSerializer.Create <MessagePackMemberAndDataMemberMixedTarget>(context); serializer.Pack(buffer, target); buffer.Position = 0; var intermediate = Unpacking.UnpackObject(buffer); if (method == SerializationMethod.Array) { var asArray = intermediate.AsList(); Assert.That(asArray.Count, Is.EqualTo(3)); Assert.That(asArray[0] == target.ShouldSerialized1); Assert.That(asArray[1] == target.ShouldSerialized2); Assert.That(asArray[2] == target.ShouldSerialized3); } else { var asMap = intermediate.AsDictionary(); Assert.That(asMap.Count, Is.EqualTo(3)); Assert.That(asMap["ShouldSerialized1"] == target.ShouldSerialized1); Assert.That(asMap["ShouldSerialized2"] == target.ShouldSerialized2); Assert.That(asMap["ShouldSerialized3"] == target.ShouldSerialized3); } buffer.Position = 0; var result = serializer.Unpack(buffer); Assert.That(result.ShouldSerialized1, Is.EqualTo(target.ShouldSerialized1)); Assert.That(result.ShouldSerialized2, Is.EqualTo(target.ShouldSerialized2)); Assert.That(result.ShouldSerialized3, Is.EqualTo(target.ShouldSerialized3)); Assert.That(result.ShouldNotSerialized1, Is.Not.EqualTo(target.ShouldNotSerialized1).And.EqualTo(0)); Assert.That(result.ShouldNotSerialized2, Is.Not.EqualTo(target.ShouldNotSerialized2).And.EqualTo(0)); } }
protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider) { // Dictionary<object, ocbect>[]へのデシリアライズ var rawObject = Unpacking.UnpackObject(objectProvider.GetData()); var entity = rawObject .AsList() .Select(x => x.AsDictionary()) .Select(x => x.ToDictionary(y => y.Key.ToString(), y => y.Value.ToObject())) .ToArray(); using (var dialog = new EntityDialog(entity)) { dialog.StartPosition = FormStartPosition.CenterParent; dialog.ShowDialog(); } }
public static void Main(string[] args) { Fuzzer.OutOfProcess.Run(stream => { try { Unpacking.UnpackObject(stream); } catch (InvalidMessagePackStreamException) { } catch (MessageNotSupportedException) { } catch (MessageTypeException) { } catch (OutOfMemoryException) { } catch (OverflowException) { } catch (UnpackException) { } }); }
public MessagePackObject ExecuteCommand(string command, object[] args, string token = null) { Dictionary <string, object> message = new Dictionary <string, object>(); message["message"] = command; message["args"] = args; if (token != null) { message["token"] = token; } byte[] packed; using (MemoryStream stream = new MemoryStream()) { Packer packer = Packer.Create(stream); packer.PackMap(message); packed = stream.ToArray(); } byte[] packedLength = BitConverter.GetBytes(packed.Length); if (BitConverter.IsLittleEndian) { Array.Reverse(packedLength); } _stream.Write(packedLength); _stream.Write(packed); byte[] respBytes = ReadMessage(_stream); MessagePackObjectDictionary resp = null; try { resp = Unpacking.UnpackObject(respBytes).Value.AsDictionary(); } catch { byte[] decompressed = DecompressData(respBytes); resp = Unpacking.UnpackObject(decompressed).Value.AsDictionary(); } return(resp.ContainsKey("obj") ? resp["obj"] : resp["exception"]); }
public void TestSetReturnValue_ReturnValueIsValueType_Serialized() { var returnValue = Environment.TickCount; using (var server = new RpcServer()) using (var transportManager = new NullServerTransportManager(server)) using (var transport = new NullServerTransport(transportManager)) using (var responseContext = DispatchTestHelper.CreateResponseContext(transport)) { var target = new Target(server); target.InvokeSetReturnValue(responseContext, returnValue); // Details should be tested in ServerResponseContextTest.TestSerialize... Assert.That(Unpacking.UnpackObject(responseContext.GetErrorData()).Value.IsNil); Assert.That(Unpacking.UnpackObject(responseContext.GetReturnValueData()).Value == returnValue); } }
public void TestInvokeAsync_MethodError_TaskSetSerializedError() { using (var server = new RpcServer()) using (var transportManager = new NullServerTransportManager(server)) using (var transport = new NullServerTransport(transportManager)) { ServerRequestContext requestContext = DispatchTestHelper.CreateRequestContext(); ServerResponseContext responseContext = DispatchTestHelper.CreateResponseContext(transport); using (var result = new Target(null, new RpcErrorMessage(RpcError.ArgumentError, MessagePackObject.Nil)).InvokeAsync(requestContext, responseContext)) { result.Wait(); } var error = Unpacking.UnpackObject(responseContext.GetErrorData()); var errorDetail = Unpacking.UnpackObject(responseContext.GetReturnValueData()); Assert.That(error.Value.Equals(RpcError.ArgumentError.Identifier)); Assert.That(errorDetail.Value.IsNil, Is.True); } }
public void TestInvokeAsync_FatalError_TaskSetSerializedError() { using (var server = new RpcServer()) using (var transportManager = new NullServerTransportManager(server)) using (var transport = new NullServerTransport(transportManager)) { ServerRequestContext requestContext = DispatchTestHelper.CreateRequestContext(); ServerResponseContext responseContext = DispatchTestHelper.CreateResponseContext(transport); using (var result = new Target(new Exception("FAIL"), RpcErrorMessage.Success).InvokeAsync(requestContext, responseContext)) { result.Wait(); } var error = Unpacking.UnpackObject(responseContext.GetErrorData()); var errorDetail = Unpacking.UnpackObject(responseContext.GetReturnValueData()); Assert.That(error.Value.Equals(RpcError.CallError.Identifier)); Assert.That(errorDetail.Value.IsNil, Is.False); } }
public static void Main(string[] args) { Fuzzer.Run(() => { try { using (var file = File.OpenRead(args[0])) { Unpacking.UnpackObject(file); } } catch (InvalidMessagePackStreamException) { } catch (MessageNotSupportedException) { } catch (MessageTypeException) { } catch (OutOfMemoryException) { } catch (OverflowException) { } catch (UnpackException) { } }); }
public Dictionary <object, object> Execute(string method, params object[] args) { if (method != "auth.login" && string.IsNullOrEmpty(_token)) { throw new Exception("Not Authenticated."); } HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_host); request.ContentType = "binary/message-pack"; request.Method = "POST"; request.KeepAlive = true; using (Stream requestStream = request.GetRequestStream()) using (Packer msgpackWriter = Packer.Create(requestStream)) { bool sendToken = (!string.IsNullOrEmpty(_token) && method != "auth.login"); msgpackWriter.PackArrayHeader(1 + (sendToken ? 1 : 0) + args.Length); msgpackWriter.Pack(method); if (sendToken) { msgpackWriter.Pack(_token); } foreach (object arg in args) { msgpackWriter.Pack(arg); } } using (MemoryStream mstream = new MemoryStream()) { using (WebResponse response = request.GetResponse()) using (Stream rstream = response.GetResponseStream()) rstream.CopyTo(mstream); mstream.Position = 0; MessagePackObjectDictionary resp = Unpacking.UnpackObject(mstream).AsDictionary(); return(MessagePackToDictionary(resp)); } }
private void TestEnumForByUnderlyingValue(SerializationContext context, Type builtType, params string[] builtMembers) { var serializer = context.GetSerializer(builtType); var value = ( IFormattable )Enum.Parse(builtType, String.Join(",", builtMembers)); using (var stream = new MemoryStream()) { serializer.PackTo(Packer.Create(stream, false), value); stream.Position = 0; var deserialized = serializer.Unpack(stream); Assert.That(deserialized, Is.EqualTo(value)); stream.Position = 0; var result = Unpacking.UnpackObject(stream); Assert.That( result.ToString().Equals(value.ToString("D", null)), result + " == " + value.ToString("D", null) ); } }
public Packet Unpack(byte[] _data) { MessagePackObject rawObject; var serializer = MessagePackSerializer.Get <Dictionary <string, object> >(context); using (MemoryStream stream = new MemoryStream(_data)) { rawObject = Unpacking.UnpackObject(stream); } var response = rawObject.AsDictionary(); MessagePackObjectDictionary rHeader = response["header"].AsDictionary(); MessagePackObject rPayload = response["payload"]; var header = new Dictionary <string, object>() { { "seq", rHeader["seq"].AsUInt32() } }; return(new Packet(header, rPayload)); }
public void ReadStream(Stream stream) { // skip the first identifying byte 'm' stream.ReadByte(); try { worldObject = Unpacking.UnpackObject(stream); } catch (UnpackException e) { throw new InvalidMapFileException(e); } catch (MessageTypeException e) { throw new InvalidMapFileException(e); } if (!worldObject.IsDictionary) { throw new InvalidMapFileException(); } }