Exemplo n.º 1
0
        public void ParseBSON(Kernys.Bson.BSONObject bsonObj)
        {
            try {
            if (bsonObj["ipad"]["type"].stringValue == "up") {
                if (lastMessage == messageType.down) {
                    //its a tap!
                    if (lastFingers == 1) {
                        messageQueue.Enqueue(new iPadTapInput());
                    } else {
                        //double tap here
                    }

                }
                lastMessage = messageType.up;
                this.lastFingers = 0;
            } else if (bsonObj["ipad"]["type"].stringValue == "down") {

                this.lastFingers = bsonObj["ipad"]["n"].int32Value;
                lastMessage = messageType.down;
            } else {
                this.lastMessage = messageType.move;
            }
            } catch (KeyNotFoundException) {
            //unhandled keynotfoundexception. e.g. recieving letter inputs.
            }
            //TODO: Parse other types of messages, e.g. swipe, fingerdown, finger up...
        }
Exemplo n.º 2
0
        /*
        * Turns BSONObj into an array of bytes ready to transport.
        * -------------------------------------------------
        * | a |   b   |         c                         |
        * -------------------------------------------------
        * c => compressed data
        * b => length of uncompressed data
        * a => 1 byte header
        *
        */
        public void SendUncompressed(Kernys.Bson.BSONObject bsonObj)
        {
            byte[] raw = Kernys.Bson.SimpleBSON.Dump(bsonObj);
            //byte[] compressed = ZlibStream.CompressBuffer(raw);

            List<byte> b = intToByteString(raw.Length);
            b.AddRange(raw);

            List<byte> a = new List<byte>();
            a.Add(2);
            a.AddRange(b);

            //		string deb = "";
            //		foreach (byte oneB in a) {
            //			deb += oneB + " ";
            //		}
            //		Debug.Log (deb);

            tcpSender.AddMessage(a.ToArray());
        }
 public void Send(Kernys.Bson.BSONObject bsonObj)
 {
     byte[] raw = Kernys.Bson.SimpleBSON.Dump(bsonObj);
     messageSender.SendBytes(raw);
 }
	public void addData(string key, Kernys.Bson.BSONValue value)
	{
		//Debug.Log ("BSON Comms add msg " + remotePort);
		bsonObj.Add (key, value);
		dataAdded = true;
	}