public void Add( OpcodeKind kind, byte number, string name, OpcodeFlags flags = OpcodeFlags.None) { opcodes[((int)kind * 32) + number] = new Opcode(kind, number, name, flags); }
public async Task SendBinary( byte[] data, OpcodeKind opcode, FragmentKind fragment, CancellationToken ct) => await ComposeFrameAndSendAsync( data, opcode, fragment, ct);
public async Task SendText( string message, OpcodeKind opcode, FragmentKind fragment, CancellationToken ct = default) => await ComposeFrameAndSendAsync( message, opcode, fragment, ct);
private static void AddOpcode( OpcodeKind kind, byte number, string name, OpcodeFlags flags = OpcodeFlags.None, byte fromVersion = 1, byte toVersion = 8) { for (byte v = fromVersion; v <= toVersion; v++) { opcodeTables[v - 1].Add(kind, number, name, flags); } }
public Opcode this[OpcodeKind kind, byte number] { get { var opcode = opcodes[((int)kind * 32) + number]; if (opcode == null) { throw new OpcodeException( string.Format("Could not find opcode (Kind = {0}, Number = {1:x2}, Version = {2})", kind, number, version)); } return(opcode); } }
internal Opcode(OpcodeKind kind, byte number, string name, OpcodeFlags flags) { this.Kind = kind; this.Number = number; this.Name = name; this.HasStoreVariable = (flags & OpcodeFlags.Store) != 0; this.HasBranch = (flags & OpcodeFlags.Branch) != 0; this.HasZText = (flags & OpcodeFlags.ZText) != 0; this.IsCall = (flags & OpcodeFlags.Call) != 0; this.IsDoubleVariable = (flags & OpcodeFlags.DoubleVar) != 0; this.IsFirstOpByRef = (flags & OpcodeFlags.FirstOpByRef) != 0; this.IsJump = kind == OpcodeKind.OneOp && number == 0x0c; this.IsQuit = kind == OpcodeKind.ZeroOp && number == 0x0a; this.IsReturn = (flags & OpcodeFlags.Return) != 0; }
private async Task SendList <T>( IEnumerable <T> list, OpcodeKind opcode, Func <T, FragmentKind, OpcodeKind, Task> sendTask) { if (!list?.Any() ?? true) { return; } if (list.Count() == 1) { await sendTask(list.FirstOrDefault(), FragmentKind.None, opcode); return; } await foreach (var(item, index) in list.Select((item, index) => (item, index)).ToAsyncEnumerable()) { if (IsFirstPosition(index)) { await sendTask(item, FragmentKind.First, opcode); } else if (IsLastPosition(index)) { await sendTask(item, FragmentKind.Last, opcode); } else { await sendTask(item, FragmentKind.None, OpcodeKind.Continuation); } } bool IsLastPosition(int i) => i == list.Count() - 1; bool IsFirstPosition(int i) => i == 0; }
private static bool Is(this Opcode op, OpcodeKind kind, int number) { return(op.Kind == kind && op.Number == number); }
private async Task ComposeFrameAndSendAsync( string?message, OpcodeKind opcode, FragmentKind fragment, CancellationToken ct) => await ComposeFrameAndSendAsync(