| ofs | hex dump | ascii |
|---|
| 0000 | 47 49 46 38 39 61 28 02 e8 02 f7 ff 00 f1 65 33 ea a9 47 10 73 9c cf dc 8e 30 a8 9a 64 af b8 99 | GIF89a(.......e3..G.s....0..d... |
| 0020 | a8 69 31 8e ab 98 ce 79 53 a9 b2 db bd 54 79 c7 86 6a ca 6b 90 cf b1 ab d6 74 b0 b1 b3 d6 c6 5a | .i1....yS....Ty..j.k.....t.....Z |
| 0040 | af dc b1 4a 96 b4 67 ba 8b 6b 6d 6e db db dc b5 d6 e7 73 af c7 25 97 9c 45 a8 95 b6 d7 75 52 52 | ...J..g..kmn......s..%..E....uRR |
| 0060 | 5a f2 ed 6a 8f 91 91 86 c7 85 2a aa 74 f7 92 38 d4 ef 6b ed da ac 35 9b 9c 88 bc ce d0 e7 93 75 | Z..j......*.t..8..k...5........u |
| 0080 | bd 87 e7 e7 e7 ec d0 91 f6 db 67 8a c7 7b cb eb ea f9 f8 e7 f7 af 9b ba e7 d5 e9 ea b7 dd f7 ec | ..........g..{.................. |
| 00a0 | 29 aa cc d7 ec ec 17 84 9c cd ce 62 20 8b 9d c8 dd 7d db ef cb ec ba 6e 97 c7 d6 ca ec da c3 de | )..........b.....}.....n........ |
| 00c0 | e7 27 75 8c b5 e7 6b 4e 6a 6b e9 f7 dc 57 b6 8c 73 c5 dc db e7 a7 da ed b9 47 ba 6b f0 9c 40 99 | .'u...kNjk...W..s........G.k..@. |
| 00e0 | a8 aa e9 ee c8 77 c4 b0 a9 d8 df f6 ce 57 57 b6 97 c6 c6 c7 74 79 80 10 88 a9 53 ad 95 b8 dc 88 | .....w.......WW.....ty....S..... |
| 0100 | ca ea cb a9 d8 9b ba de 9a 71 90 6d a5 ce 74 18 9c bd bd ef e7 da cb 65 cb e7 aa a9 d6 86 c9 e7 | .........q.m..t........e........ |
| 0120 | b9 cb dc af 4c 96 8c d8 ef da 98 dd 6b 66 b9 9a 94 ce 88 86 c8 c8 de f7 db a5 ce dd a8 db c8 3f | ....L.......kf.................? |
| 0140 | b6 d1 fe d4 cb 54 5a 5f 87 d6 6b 48 b5 95 e7 b7 54 85 c8 9b b6 db dc d7 b4 73 69 8d 8f 37 a7 a9 | .....TZ_..kH....T........si..7.. |
| 0160 | 9a d6 c7 bc e4 b5 98 d6 7b ea ef d8 7d ae 76 e0 cb 7a f5 eb 94 95 ce cc ee ac 52 f7 a9 45 eb f7 | ........{...}.v..z........R..E.. |
| 0180 | cc fe ec e9 d9 d7 7d f8 f7 db 37 68 79 97 cd 98 74 6f 59 10 8c 86 9a d6 9d 91 b1 87 f7 8a 71 18 | ......}...7hy...toY...........q. |
| 01a0 | 97 9c fb ed d7 17 7b 9f f8 e8 c7 37 85 9f b6 de c4 af b3 8c 51 89 79 cc 93 4e e7 b6 4a 74 bd 9a | ......{....7........Q.y..N..Jt.. |
| 01c0 | a5 de 6b e7 ef f6 b8 e7 90 6f 9a a8 9c 9d a0 f7 b5 4a 9b d8 87 3a 81 87 de ef f6 58 a5 88 cb d8 | ..k......o.......J...:.....X.... |
| 01e0 | db c6 ef f7 b8 c8 68 8c d6 7b c4 b7 5e 67 a9 82 15 97 7f 8b c8 d8 d6 d6 60 fd f7 c5 ba c6 c4 a7 | ......h..{..^g..........`....... |
| 0200 | cb 85 c5 a9 59 f7 bd 50 de ad 4a a8 c7 ca 28 86 8f a7 c2 6b cd cb 7c 27 7f a2 b9 cb 79 ca da c7 | ....Y..P..J...(....k..|'....y... |
| 0220 | b4 92 89 64 a7 96 48 a8 8b 8a d6 87 ce ce d0 db db c8 de f7 b8 b7 cd d7 8c d6 9b 36 95 91 f8 a8 | pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */using Google.Protobuf;
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Tango.PMR.Stubs;
namespace Tango.MachineService
{
/// <summary>
/// Represents a protobuf web request/response formatter capable of formatting messages using protobuf.
/// </summary>
/// <seealso cref="System.Net.Http.Formatting.MediaTypeFormatter" />
public class ProtoBufFormatter : MediaTypeFormatter
{
private static readonly MediaTypeHeaderValue mediaType = new MediaTypeHeaderValue("application/x-protobuf");
/// <summary>
/// Initializes a new instance of the <see cref="ProtoBufFormatter"/> class.
/// </summary>
public ProtoBufFormatter()
{
SupportedMediaTypes.Add(mediaType);
}
/// <summary>
/// Gets the default type of the media.
/// </summary>
/// <value>
/// The default type of the media.
/// </value>
public static MediaTypeHeaderValue DefaultMediaType
{
get { return mediaType; }
}
/// <summary>
/// Queries whether this <see cref="T:System.Net.Http.Formatting.MediaTypeFormatter" /> can deserializean object of the specified type.
/// </summary>
/// <param name="type">The type to deserialize.</param>
/// <returns>
/// true if the <see cref="T:System.Net.Http.Formatting.MediaTypeFormatter" /> can deserialize the type; otherwise, false.
/// </returns>
public override bool CanReadType(Type type)
{
return true;
}
/// <summary>
/// Queries whether this <see cref="T:System.Net.Http.Formatting.MediaTypeFormatter" /> can serializean object of the specified type.
/// </summary>
/// <param name="type">The type to serialize.</param>
/// <returns>
/// true if the <see cref="T:System.Net.Http.Formatting.MediaTypeFormatter" /> can serialize the type; otherwise, false.
/// </returns>
public override bool CanWriteType(Type type)
{
return true;
}
/// <summary>
/// Reads from stream asynchronous.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="stream">The stream.</param>
/// <param name="content">The content.</param>
/// <param name="formatterLogger">The formatter logger.</param>
/// <returns></returns>
public override Task<object> ReadFromStreamAsync(Type type, Stream stream, HttpContent content, IFormatterLogger formatterLogger)
{
var tcs = new TaskCompletionSource<object>();
try
{
MessageParser parser = type.GetProperty("Parser").GetValue(null, null) as MessageParser;
IMessage req = parser.ParseFrom(stream);
tcs.SetResult(req);
}
catch (Exception ex)
{
tcs.SetException(ex);
}
return tcs.Task;
}
/// <summary>
/// Writes to stream asynchronous.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="value">The value.</param>
/// <param name="stream">The stream.</param>
/// <param name="content">The content.</param>
/// <param name="transportContext">The transport context.</param>
/// <returns></returns>
public override Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContent content, TransportContext transportContext)
{
if (value is IMessage)
{
var tcs = new TaskCompletionSource<object>();
try
{
(value as IMessage).WriteTo(stream);
tcs.SetResult(null);
}
catch (Exception ex)
{
tcs.SetException(ex);
}
return tcs.Task;
}
return base.WriteToStreamAsync(type, value, stream, content, transportContext);
}
}
}