Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ServiceStack/src/ServiceStack.ProtoBuf/ProtoBufServiceClient.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
60 lines (52 sloc)
1.76 KB
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
using System; | |
using System.IO; | |
using System.Runtime.Serialization; | |
using ServiceStack.Web; | |
namespace ServiceStack.ProtoBuf | |
{ | |
public class ProtoBufServiceClient : ServiceClientBase | |
{ | |
public override string Format => "x-protobuf"; | |
public ProtoBufServiceClient(string baseUri) | |
{ | |
SetBaseUri(baseUri); | |
} | |
public ProtoBufServiceClient(string syncReplyBaseUri, string asyncOneWayBaseUri) | |
: base(syncReplyBaseUri, asyncOneWayBaseUri) { } | |
public override void SerializeToStream(IRequest req, object request, Stream stream) | |
{ | |
try | |
{ | |
ProtoBufFormat.Serialize(req, request, stream); | |
} | |
catch (Exception ex) | |
{ | |
throw new SerializationException("ProtoBufServiceClient: Error serializing: " + ex.Message, ex); | |
} | |
} | |
public override T DeserializeFromStream<T>(Stream stream) | |
{ | |
try | |
{ | |
return ProtoBufFormat.Deserialize<T>(stream); | |
} | |
catch (Exception ex) | |
{ | |
throw new SerializationException("ProtoBufServiceClient: Error deserializing: " + ex.Message, ex); | |
} | |
} | |
public override string ContentType => MimeTypes.ProtoBuf; | |
public override StreamDeserializerDelegate StreamDeserializer => Deserialize; | |
private static object Deserialize(Type type, Stream source) | |
{ | |
try | |
{ | |
return ProtoBufFormat.Deserialize(type, source); | |
} | |
catch (Exception ex) | |
{ | |
throw new SerializationException("ProtoBufServiceClient: Error deserializing: " + ex.Message, ex); | |
} | |
} | |
} | |
} |