Exemplo n.º 1
0
        public void postMessage(UInt64 connID, BufferT msgBuff)
        {
            //auto f = connections.find(connID);
            //assert(f != connections.end());
            //auto & conn = f->second;
            ClientConnection conn = connections[connID];
            Debug.Assert(conn.ref_id_at_client == connID); // self-consistency
            BufferT buff = platform.makeBuffer();
            IPublishableComposer composer = platform.makePublishableComposer(buff);
            PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
            mh.type = PublishableStateMessageHeader.MsgType.connectionMessage;
            mh.priority = 0; // TODO: source
            mh.state_type_id_or_direction = (UInt64)PublishableStateMessageHeader.ConnMsgDirection.toServer;
            Debug.Assert(conn.ref_id_at_client == connID);
            mh.ref_id_at_subscriber = conn.ref_id_at_client;
            Debug.Assert(conn.ref_id_at_server != 0);
            mh.ref_id_at_publisher = conn.ref_id_at_server;
            GMQueue.helperComposePublishableStateMessageBegin(composer, mh);
            ReadIteratorT riter = msgBuff.getReadIterator();

            composer.appendRaw(riter);

            GMQueue.helperComposePublishableStateMessageEnd(composer);
            //assert(transport != nullptr);
            transport.postMessage(buff);
        }
 public void append(ReadIteratorT it, int size)
 {
     while (size > 0 && it.isData())
     {
         int    avail  = it.directlyAvailableSize();
         int    toRead = Math.Min(size, avail);
         byte[] sp     = it.read(toRead);
         append(sp);
         size -= sp.Length;
     }
 }
 public override void onMessage(ReadIteratorT riter)
 {
     basic_test.scope_test_exchange.handleMessage(riter,
                                                  basic_test.scope_test_exchange.makeMessageHandler(basic_test.scope_test_exchange.MsgId.srv_response,
                                                                                                    (JsonParser parser, ulong id) => {
         basic_test.scope_test_exchange.srv_response reply = basic_test.scope_test_exchange.parseMessage_srv_response(parser);
         //assert( node != nullptr );
         node.onServerReply(getConnID(), reply);
     }),
                                                  basic_test.scope_test_exchange.makeDefaultMessageHandler((JsonParser parser, ulong id) => { Console.Write("Unhandled message\n", id); })
                                                  );
 }
 public override void onMessage(ReadIteratorT riter)
 {
     basic_test.scope_test_exchange.handleMessage(riter,
                                                  basic_test.scope_test_exchange.makeMessageHandler(basic_test.scope_test_exchange.MsgId.cl_request,
                                                                                                    (JsonParser parser, ulong msgID) =>
     {
         var request = basic_test.scope_test_exchange.parseMessage_cl_request(parser);
         node.onClientRequest(getConnID(), request, this);
     }),
                                                  basic_test.scope_test_exchange.makeDefaultMessageHandler(
                                                      (JsonParser parser, ulong msgID) => { Console.Write("Unhandled message {0}\n", msgID); })
                                                  );
 }
        public static bool AreEqualIgnoreEol(BufferT left, BufferT right)
        {
            if (ReferenceEquals(left, right))
            {
                return(true);
            }
            else if (left == null)
            {
                return(false);
            }
            else if (right == null)
            {
                return(false);
            }

            ReadIteratorT l = left.getReadIterator();
            ReadIteratorT r = right.getReadIterator();

            while (l.isData() && r.isData())
            {
                // \r\n == \n
                if (l.getChar() == '\r' && r.getChar() == '\n')
                {
                    l.inc();
                    if (!l.isData() || l.getChar() != '\n')
                    {
                        return(false);
                    }
                }
                // \n == \r\n
                else if (l.getChar() == '\n' && r.getChar() == '\r')
                {
                    r.inc();
                    if (!r.isData() || r.getChar() != '\n')
                    {
                        return(false);
                    }
                }
                else if (l.getChar() != r.getChar())
                {
                    return(false);
                }

                l.inc();
                r.inc();
            }

            return(!l.isData() && !r.isData());
        }
 public static IPublishableParser makePublishableParser(Protocol proto, ReadIteratorT readIter)
 {
     if (proto == Protocol.Json)
     {
         return(new JsonPublishableParser(readIter));
     }
     else if (proto == Protocol.Gmq)
     {
         return(new GmqPublishableParser(readIter));
     }
     else
     {
         throw new Exception();
     }
 }
        public static UInt64 readVlqIntegral(ReadIteratorT riter)
        {
            UInt64 result = 0;
            bool   done   = false;

            while (!done && riter.isData())
            {
                byte current = riter.get();
                riter.inc();
                done = current < 128;
                UInt64 promoted = (UInt64)current & 0x7f;
                result <<= 7;
                result   = result | promoted;
            }
            return(result);
        }
Exemplo n.º 8
0
        void onMessage(IPublishableParser parser)
        {
            ReadIteratorT riter = parser.getIterator().shallowClone();

            IPublishableParser parser1 = platform.makePublishableParser(riter);
            PublishableStateMessageHeader mh = new PublishableStateMessageHeader();
            GMQueue.helperParsePublishableStateMessageBegin(parser1, ref mh);
            switch (mh.type)
            {
                case PublishableStateMessageHeader.MsgType.subscriptionResponse:
                case PublishableStateMessageHeader.MsgType.stateUpdate:
                    subPool.onMessage(parser);
                    break;
                case PublishableStateMessageHeader.MsgType.subscriptionRequest:
                    pubPool.onMessage(parser);
                    break;
                case PublishableStateMessageHeader.MsgType.connectionRequest:
                    srvPool.onMessage(parser);
                    break;
                case PublishableStateMessageHeader.MsgType.connectionAccepted:
                    cliPool.onMessage(parser);
                    break;
                case PublishableStateMessageHeader.MsgType.connectionMessage:
                    switch ((PublishableStateMessageHeader.ConnMsgDirection)mh.state_type_id_or_direction)
                    {
                        case PublishableStateMessageHeader.ConnMsgDirection.toClient:
                            cliPool.onMessage(parser);
                            break;
                        case PublishableStateMessageHeader.ConnMsgDirection.toServer:
                            srvPool.onMessage(parser);
                            break;
                        default:
                            throw new Exception(); // TODO: ... (unknown msg type)
                    }
                    break;
                default:
                    throw new Exception(); // TODO: ... (unknown msg type)
            }
        }
 public JsonParser(ReadIteratorT riter_)
 {
     riter = riter_; nfi.NumberDecimalSeparator = ".";
 }
 public GmqParser(ReadIteratorT riter_)
 {
     riter = riter_;
 }
Exemplo n.º 11
0
 public void onMessage(BufferT buffer)
 {
     ReadIteratorT riter = buffer.getReadIterator();
     IPublishableParser parser = platform.makePublishableParser(riter);
     onMessage(parser);
 }
Exemplo n.º 12
0
 public abstract void onMessage(ReadIteratorT parser);
 public void appendRaw(ReadIteratorT it, int size = int.MaxValue)
 {
     composer.getBuffer().append(it, size);
 }
 public JsonPublishableParser(ReadIteratorT riter)
 {
     p = new JsonParser(riter);
 }
 public GmqPublishableParser(ReadIteratorT riter)
 {
     p = new GmqParser(riter);
 }