Example #1
0
        public void MsgPackRpcDispatcherTest()
        {
            var dispatcher = new RpcDispatcher <MsgPackValue>();
            var f          = new MsgPackFormatter();

            {
                f.GetStore().Clear();
                dispatcher.Register("add", (int a, int b) => a + b);
                f.Request("add", 1, 2);

                var request = MsgPackParser.Parse(f.GetStoreBytes());
                Assert.AreEqual(4, request.GetArrayCount());
                Assert.AreEqual(MsgPackFormatter.REQUEST_TYPE, request[0].GetInt32());

                f.GetStore().Clear();
                dispatcher.Call(f, request[1].GetInt32(), request[2].GetString(), request[3]);
                var response = MsgPackParser.Parse(f.GetStoreBytes());
                Assert.AreEqual(4, response.GetArrayCount());
                Assert.AreEqual(MsgPackFormatter.RESPONSE_TYPE, response[0].GetInt32());
                Assert.True(response[2].IsNull());
                Assert.AreEqual(3, response[3].GetInt32());
            }
        }
Example #2
0
 public static ListTreeNode <MsgPackValue> ParseAsMsgPack(this ArraySegment <byte> bytes)
 {
     return(MsgPackParser.Parse(bytes));
 }
Example #3
0
 public static ListTreeNode <MsgPackValue> ParseAsMsgPack(this byte[] bytes)
 {
     return(MsgPackParser.Parse(bytes));
 }