Created
September 1, 2011 14:41
-
-
Save theburningmonk/1186303 to your computer and use it in GitHub Desktop.
An implementation of protobuf-net body deserialize to use with Nancy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class ProtobufNetBodyDeserializer : IBodyDeserializer | |
{ | |
public bool CanDeserialize(string contentType) | |
{ | |
return IsProtoBufType(contentType); | |
} | |
public object Deserialize(string contentType, Stream bodyStream, BindingContext context) | |
{ | |
// deserialize the body stream into the destination type | |
return RuntimeTypeModel.Default.Deserialize(bodyStream, null, context.DestinationType); | |
} | |
private static bool IsProtoBufType(string contentType) | |
{ | |
if (string.IsNullOrWhiteSpace(contentType)) | |
{ | |
return false; | |
} | |
var contentMimeType = contentType.Split(';').First(); | |
return contentMimeType.Equals("application/x-protobuf", StringComparison.InvariantCultureIgnoreCase); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment