/// <summary> /// Deserializes the given <see cref="TransportMessage"/> back into a <see cref="Message"/> /// </summary> public async Task <Message> Deserialize(TransportMessage transportMessage) { var contentType = transportMessage.Headers.GetValue(Headers.ContentType); // Optimize default case by using the same _enconding instance. if (contentType == JsonUtf8ContentType) { return(GetMessage(transportMessage, _encoding)); } if (contentType.StartsWith(JsonContentType)) { var encoding = EncodingUtils.GetEncoding(contentType); return(GetMessage(transportMessage, encoding)); } throw new FormatException($"Unknown content type: '{contentType}' - must be '{JsonUtf8ContentType}' for the JSON serialier to work"); }
void MapContentType(Dictionary <string, string> headers) { string contentType; if (!headers.TryGetValue(Headers.ContentType, out contentType)) { return; } var charset = EncodingUtils.GetCharset(contentType); if (charset == null) { throw new FormatException($"Could not find 'charset' property in the content type: '{contentType}'"); } headers["rebus-content-type"] = "text/json"; headers["rebus-encoding"] = charset; }