forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMsgPackServiceClient.cs
More file actions
61 lines (53 loc) · 1.58 KB
/
MsgPackServiceClient.cs
File metadata and controls
61 lines (53 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using MsgPack.Serialization;
using System.IO;
using ServiceStack.Web;
namespace ServiceStack.MsgPack
{
public class MsgPackServiceClient : ServiceClientBase
{
public override string Format
{
get { return "x-msgpack"; }
}
public MsgPackServiceClient(string baseUri)
{
SetBaseUri(baseUri);
}
public MsgPackServiceClient(string syncReplyBaseUri, string asyncOneWayBaseUri)
: base(syncReplyBaseUri, asyncOneWayBaseUri) { }
public override void SerializeToStream(IRequest requestContext, object request, Stream stream)
{
if (request == null) return;
try
{
MsgPackFormat.Serialize(requestContext, request, stream);
}
catch (Exception ex)
{
MsgPackFormat.HandleException(ex, request.GetType());
}
}
public override T DeserializeFromStream<T>(Stream stream)
{
try
{
var serializer = MessagePackSerializer.Get<T>();
var obj = serializer.Unpack(stream);
return obj;
}
catch (Exception ex)
{
return (T)MsgPackFormat.HandleException(ex, typeof(T));
}
}
public override string ContentType
{
get { return MimeTypes.MsgPack; }
}
public override StreamDeserializerDelegate StreamDeserializer
{
get { return MsgPackFormat.Deserialize; }
}
}
}