public Proto.Msg.ExceptionData ExceptionToProtoNet(Exception exception) { var message = new Proto.Msg.ExceptionData(); if (exception == null) { return(message); } var exceptionType = exception.GetType(); message.TypeName = exceptionType.TypeQualifiedName(); message.Message = exception.Message; message.StackTrace = exception.StackTrace ?? ""; message.Source = exception.Source ?? ""; message.InnerException = ExceptionToProto(exception.InnerException); var serializable = exception as ISerializable; var serializationInfo = new SerializationInfo(exceptionType, DefaultFormatterConverter); serializable.GetObjectData(serializationInfo, new StreamingContext()); foreach (var info in serializationInfo) { if (DefaultProperties.Contains(info.Name)) { continue; } var preparedValue = _wrappedPayloadSupport.PayloadToProto(info.Value); message.CustomFields.Add(info.Name, preparedValue); } return(message); }
// // Identify // private byte[] IdentifyToProto(Identify identify) { var protoIdentify = new Proto.Msg.Identify(); if (identify.MessageId != null) { protoIdentify.MessageId = _payloadSupport.PayloadToProto(identify.MessageId); } return(protoIdentify.ToByteArray()); }
/// <inheritdoc /> public override byte[] ToBinary(object obj) { if (obj is ActorSelectionMessage sel) { var envelope = new Proto.Msg.SelectionEnvelope(); envelope.Payload = _payloadSupport.PayloadToProto(sel.Message); foreach (var element in sel.Elements) { Proto.Msg.Selection selection = null; if (element is SelectChildName m1) { selection = BuildPattern(m1.Name, Proto.Msg.Selection.Types.PatternType.ChildName); } else if (element is SelectChildPattern m) { selection = BuildPattern(m.PatternStr, Proto.Msg.Selection.Types.PatternType.ChildPattern); } else if (element is SelectParent) { selection = BuildPattern(null, Proto.Msg.Selection.Types.PatternType.Parent); } envelope.Pattern.Add(selection); } return(envelope.ToByteArray()); } throw new ArgumentException($"Cannot serialize object of type [{obj.GetType().TypeQualifiedName()}]"); }