public void Wrap(ICodeSet codeSet, ICollection <Symbol> buffer, IEnumerable <Action> emits) { foreach (var emit in emits) { emit(); } }
private void Apply(Symbol symbol, CodeSetType type) { _current = symbol; _activeType = type; _tempSet = null; _activeCodeSet = _mapping.GetCodeSet(_activeType); Consume(); }
public void Wrap(ICodeSet codeSet, ICollection <Symbol> buffer, IEnumerable <Action> emits) { var symbol = codeSet.GetSymbolForCode(SpecialCodes.Func4); foreach (var item in emits) { buffer.Add(symbol); item(); } }
public static int FlushCodeSet(ICodeSet set, byte[] input, ICollection <Symbol> buffer, int startIndex, int count) { while (count > 0) { buffer.Add(set.GetSymbolForCode(input[startIndex])); ++startIndex; --count; } return(startIndex); }
public static IEnumerable <Action> CreateFlushEmits(ICodeSet set, byte[] input, ICollection <Symbol> buffer, int startIndex, int count) { while (count > 0) { var readIndex = startIndex; yield return(() => buffer.Add(set.GetSymbolForCode(input[readIndex]))); ++startIndex; --count; } }
private int CodeSetRun(byte[] input, ICodeSet set, int startIndex, out bool highSet) { bool?high = null; var index = startIndex; while (index < input.Length) { var current = input[index]; var currentIsHigh = current >= 128; if (currentIsHigh) { current -= 128; } if (high.HasValue) { if (currentIsHigh != high.Value) { // break on first change break; } } else { high = currentIsHigh; } if (!set.Supports(current)) { break; } var digitRun = DigitRun(input, index); if (digitRun > 0) { var terminalDigitRun = digitRun + index == input.Length; if (digitRun >= (terminalDigitRun ? 4 : 6)) { break; } } ++index; } highSet = high.GetValueOrDefault(); return(index - startIndex); }
private void HandleShift(CodeSetType expectedCurrentSet, CodeSetType targetSet) { if (_tempSet.HasValue) { throw new CodeError("Already in a shifting state."); } if (_activeType != expectedCurrentSet) { throw new CodeError($"Cannot shift to {targetSet} from current code set {_activeType}"); } _tempSet = targetSet; _activeCodeSet = _mapping.GetCodeSet(_tempSet.Value); Consume(); }
private void HandleCodeSetSwitch(CodeSetType target) { if (_tempSet.HasValue) { throw new CodeError("Cannot switch code set after shift."); } if (_activeType == target) { throw new CodeError("Redundant code set switch."); } _activeType = target; _activeCodeSet = _mapping.GetCodeSet(_activeType); Consume(); }
public CodeSet() { base.Init(base.GetType().FullName, Assembly.GetExecutingAssembly().GetName().Name); this.icodeset_0 = base.baseDal as ICodeSet; }
private void Handle() { var next = Peek(1); if (next != null && next.Code == SpecialCodes.Stop) { // this is the checksum, consume without interpreting Consume(); return; } switch (_current.Code) { case SpecialCodes.Func1: case SpecialCodes.Func2: case SpecialCodes.Func3: // TODO determine what to do Consume(); break; case SpecialCodes.Func4: if (_tempSet.HasValue) { throw new CodeError("Unexpected Func4 after code set shift."); } Consume(); _high += 128; var peek = Peek(0); if (peek == null || peek.Code != SpecialCodes.Func4) { _highShift = true; } else { Consume(); } break; case SpecialCodes.SwitchToCodeA: HandleCodeSetSwitch(CodeSetType.CodeA); break; case SpecialCodes.SwitchToCodeB: HandleCodeSetSwitch(CodeSetType.CodeB); break; case SpecialCodes.SwitchToCodeC: HandleCodeSetSwitch(CodeSetType.CodeC); break; case SpecialCodes.ShiftToA: HandleShift(CodeSetType.CodeB, CodeSetType.CodeA); break; case SpecialCodes.ShiftToB: HandleShift(CodeSetType.CodeA, CodeSetType.CodeB); break; case SpecialCodes.StartA: case SpecialCodes.StartB: case SpecialCodes.StartC: throw new CodeError("Unexpected start token"); case SpecialCodes.Stop: Consume(); return; default: switch (_tempSet ?? _activeType) { case CodeSetType.CodeC: var value = _current.Code; _output.AddRange(_encoding.GetBytes(value.ToString("00"))); break; default: _output.Add((byte)(_current.Code + _high)); break; } if (_highShift) { _high += 128; _highShift = false; } if (_tempSet.HasValue) { _tempSet = null; _activeCodeSet = _mapping.GetCodeSet(_activeType); } Consume(); break; } }