public override bool Parse(byte[] chars, int offset, out ControlFunctionParserResult result, out int funcEndIdx) { result.ControlFunction = chars[offset]; result.FeChar = 0; if (!FunctionContentMap.TryGetValue(chars[offset], out result.FunctionContent)) { result.FunctionContent = new byte[] { chars[offset] }; FunctionContentMap[chars[offset]] = new byte[] { chars[offset] }; } funcEndIdx = offset; return(true); }
public override bool Parse(byte[] chars, int offset, out ControlFunctionParserResult result, out int funcEndIdx) { result.FeChar = 0; result.FunctionContent = null; result.ControlFunction = 0; funcEndIdx = 0; int length = chars.Length; byte fe = chars[offset + 1]; if (!Fe.Is7bitFe(fe)) { return(false); } if (fe == Fe.CSI_7BIT) { #region 解析CSI命令 if (fe == Fe.CSI_7BIT) { int charsSize = 0; bool privateUse = false; bool withIntermediateByte0200 = false; for (int idx = offset + 1; idx < length; idx++) { charsSize++; if (FinalByte.IsFinalByte(chars[idx], out privateUse, out withIntermediateByte0200)) { result.FeChar = fe; result.FunctionContent = new byte[charsSize]; Array.Copy(chars, offset + 1, result.FunctionContent, 0, result.FunctionContent.Length); funcEndIdx = idx; return(true); } } } #endregion } else if (fe == Fe.OSC_7BIT) { #region 解析OSC命令 int charsSize = 0; for (int idx = offset + 1; idx < length; idx++) { charsSize++; if (OSC.IsTerminatedChar(chars[idx])) { result.FeChar = fe; result.FunctionContent = new byte[charsSize]; Array.Copy(chars, offset + 1, result.FunctionContent, 0, result.FunctionContent.Length); funcEndIdx = idx; return(true); } } #endregion } logger.ErrorFormat("解析7位编码Fe'{0}'失败", fe); return(false); }
/// <summary> /// 从一串字符中解析出ControlFunction的所有内容 /// </summary> /// <param name="chars"></param> /// <param name="offset">要解析的数据的偏移位置,从offset处开始解析,第offset位是ControlFunction</param> /// <param name="result"></param> /// <param name="funcEndIdx">ControlFunction在chars里的最后一个字符的索引</param> /// <returns></returns> public abstract bool Parse(byte[] chars, int offset, out ControlFunctionParserResult result, out int funcEndIdx);