示例#1
0
        public static ICodeyShareable Generate(CodeyPacket packet)
        {
            ICodeyShareable ret = null;

            switch ((CodeyPacketType)packet.Body[0])
            {
            case CodeyPacketType.Variable:
                ret = new SharedVariable();
                break;

            case CodeyPacketType.Message:
                ret = new BroadcastMessage();
                break;

            case CodeyPacketType.Heartbeat:
                ret = new Heartbeat();
                break;

            default:
                Debug.Assert(false);
                break;
            }

            ret.Parse(packet);

            return(ret);
        }
示例#2
0
        /// <summary>
        /// 发送变量/消息统一接口
        /// </summary>
        /// <param name="var"></param>
        public void Send(ICodeyShareable var)
        {
            CodeyPacket packet = new CodeyPacket {
                Body = var.ToArray()
            };

            WriteDataAsync(CodeyProtocolSerializer.Serialize(packet));
        }