private object DecodeScalar(byte[] content) { DictNode rootNode = (DictNode)BEncode.Decode(content); IntNode codeNode = (IntNode)rootNode["code"]; switch (codeNode.Value) { case 1: case 2: throw new DbProxyException("数据集收到的数据包出错!"); case 3: DictNode itemNode = (DictNode)rootNode["item"]; string typeName = ((BytesNode)itemNode["type"]).StringText; string value = ((BytesNode)itemNode["value"]).StringText; if (rootNode.ContainsKey("parmlist")) { HandleParmsNode((rootNode)["parmlist"]); } return(NodeEncoder.GetObject(typeName, value)); case 4: BytesNode messageNode = (BytesNode)rootNode["message"]; throw new DbProxyException(messageNode.StringText); case 5: throw new DbProxyException("校验出错!"); default: throw new DbProxyException(string.Format("无效消息代码:{0}!", codeNode.Value)); } }
private void HandleParmsNode(BEncodedNode parmlistNode) { ListNode parmsNode = (ListNode)parmlistNode; foreach (BEncodedNode node in parmsNode) { DictNode parmNode = (DictNode)node; string name = ((BytesNode)parmNode["name"]).StringText; string typeName = ((BytesNode)parmNode["type"]).StringText; parameters[name].Value = NodeEncoder.GetObject(typeName, (BytesNode)parmNode["value"]); } }