/// <summary> /// 收到队列消息 /// </summary> /// <param name="client"></param> /// <param name="result"></param> public abstract void Message(WebSocketClient client, QueueServerActionResult result);
/// <summary> /// 解释一个操作结果 /// </summary> /// <param name="data"></param> /// <exception cref="Adf.QueueServerDecodeException"></exception> /// <returns></returns> public static QueueServerActionResult Decode(byte[] data) { byte action = 0; var id = ""; var queue = ""; var result = ""; // QueueServerActionResult ar = null; // try { int position = 0; int length = 0; //action action = data[position]; position = 1; //id length = Adf.BaseDataConverter.ToUInt16(data, position); position += 2; id = System.Text.Encoding.ASCII.GetString(data, position, length); position += length; //queue length = Adf.BaseDataConverter.ToUInt16(data, position); position += 2; queue = System.Text.Encoding.ASCII.GetString(data, position, length); position += length; //result length = Adf.BaseDataConverter.ToUInt16(data, position); position += 2; result = System.Text.Encoding.ASCII.GetString(data, position, length); position += length; // ar = new QueueServerActionResult(action , id , queue , result); // if (result == QueueServerAction.OK) { if (action == QueueServerAction.PULL) { //body length = Adf.BaseDataConverter.ToUInt16(data, position); position += 2; var body = new byte[length]; Array.Copy(data, position, body, 0, length); position += length; //duplications var duplications = Adf.BaseDataConverter.ToUInt16(data, position); position += 2; //message id var messageId = Adf.BaseDataConverter.ToUInt64(data, position); //position += 8; ar.SetBody(body, duplications, messageId); } else if (action == QueueServerAction.RPUSH) { //message id var messageId = Adf.BaseDataConverter.ToUInt64(data, position); //position += 8; ar.SetMessageId(messageId); } else if (action == QueueServerAction.LPUSH) { //message id var messageId = Adf.BaseDataConverter.ToUInt64(data, position); //position += 8; ar.SetMessageId(messageId); } else if (action == QueueServerAction.COUNT) { //count var count = Adf.BaseDataConverter.ToInt32(data, position); //position += 4; ar.SetCount(count); } else if (action == QueueServerAction.CLEAR) { //count var count = Adf.BaseDataConverter.ToInt32(data, position); //position += 4; ar.SetCount(count); } } // return(ar); } catch (Exception exception) { throw new QueueServerDecodeException("data length invalid.", exception); } }