public static TextDataOrder Factory(InputByteArray InputArray) { byte? attrByte = null; string displayText = null; // scan forward in the input array for a non text character. int ix = ScanNonTextDataByte(InputArray); int remLx = ix - InputArray.Index; // first byte is the attribute byte. { var b1 = InputArray.PeekByte(0); if ((b1 >= 0x20) && (b1 <= 0x2f)) { attrByte = b1; InputArray.AdvanceIndex(1); remLx -= 1; } } // remaining bytes are text characters in ebcdic. if (remLx > 0) { System.Text.Encoding encoding = System.Text.Encoding.GetEncoding(37); // 37 = ebcdic displayText = InputArray.GetEbcdicBytes(remLx); } TextDataOrder tdOrder = new TextDataOrder(attrByte, displayText); return(tdOrder); }
public static TelnetSubject?PeekTelnetSubject(this InputByteArray InputArray, int Offset) { var b1 = InputArray.PeekByte(Offset); var subject = b1.ToTelnetSubject(); return(subject); }
public WriteToDisplayCommand(InputByteArray InputArray) : base(InputArray, WorkstationCode.WTD) { this.OrderList = new List <WtdOrderBase>(); if (InputArray.RemainingLength < 4) { this.Errmsg = "Byte stream too short. Missing control chars."; } if (this.Errmsg == null) { var buf = InputArray.PeekBytes(4); this.ControlChars = buf.SubArray(2, 2); InputArray.AdvanceIndex(4); this.BytesLength = 4; // gather WTD orders and display characters. while (true) { WtdOrderBase orderBase = null; if (InputArray.RemainingLength == 0) { break; } orderBase = WtdOrderBase.Factory(InputArray); // not an explicit WTD order. Check that is a text data order. if (orderBase == null) { var b1 = InputArray.PeekByte(0); if (Common5250.IsTextDataChar(b1) == true) { orderBase = new TextDataOrder(InputArray); } } // current input stream bytes are not WTD order. End of WTD command. if (orderBase == null) { break; } // got an order but some sort of form error. if (orderBase.Errmsg != null) { throw new Exception("invalid WTD order"); } // Append to list of orders of the WTD command. this.OrderList.Add(orderBase); this.BytesLength += orderBase.GetDataStreamLength(); } } }
public TextDataOrder(InputByteArray InputArray) : base(InputArray, "TextData") { var b1 = InputArray.PeekByte(0); if (Common5250.IsTextDataChar(b1) == false) { this.Errmsg = "Invalid text data order. Order must begin with data character."; } if (this.Errmsg == null) { // scan forward in the input array for a non text character. var rv = Common5250.ScanNonTextDataByte(InputArray); this.DataStreamLength = rv.Item2; // the actual data stream bytes. var rawBytes = InputArray.PeekBytes(this.DataStreamLength); int rawLx = rawBytes.Length; // first byte is the attribute byte. if (Common5250.IsAttributeByte(b1)) { this.AttrByte = b1; } // last text byte is an attribute byte. if ((rawLx > 1) && (rawBytes[rawLx - 1].IsAttributeByte( ) == true)) { this.TailAttrByte = rawBytes[rawLx - 1]; } // bytes the attrByte and tailAttrByte are textBytes. { int fx = 0; int lx = rawLx; if (this.AttrByte != null) { fx += 1; lx -= 1; } if (this.TailAttrByte != null) { lx -= 1; } if (lx > 0) { this.TextBytes = rawBytes.SubArray(fx, lx); } } this.RawBytes = rawBytes; this.BytesLength = rawLx; InputArray.AdvanceIndex(rawLx); } }
public static WtdOrderBase Factory(InputByteArray InputArray) { WtdOrderBase orderBase = null; var b1 = InputArray.PeekByte(0); var wtdOrder = b1.ToWtdOrder(); if (wtdOrder == null) { return(null); } if (wtdOrder.Value == WtdOrder.StartHeader) { orderBase = new StartHeaderOrder(InputArray); } else if (wtdOrder.Value == WtdOrder.SetBufferAddress) { orderBase = new SetBufferAddressOrder(InputArray); } else if (wtdOrder.Value == WtdOrder.RepeatToAddress) { orderBase = new RepeatToAddressOrder(InputArray); } else if (wtdOrder.Value == WtdOrder.TransparentData) { orderBase = new TransparentDataOrder(InputArray); } else if (wtdOrder.Value == WtdOrder.StartField) { orderBase = new StartFieldOrder(InputArray); } else if (wtdOrder.Value == WtdOrder.InsertCursor) { orderBase = new InsertCursorOrder(InputArray); } else if (wtdOrder.Value == WtdOrder.WriteStructuredField) { orderBase = WriteStructuredFieldOrder.Factory(InputArray); } else if (wtdOrder.Value == WtdOrder.EraseToAddress) { orderBase = new EraseToAddressOrder(InputArray); } return(orderBase); }
public static WtdOrderBase Factory(InputByteArray InputArray) { WtdOrderBase orderBase = null; var b1 = InputArray.PeekByte(0); var wtdOrder = b1.ToWtdOrder(); if (wtdOrder == null) { return(null); } else if (wtdOrder.Value == WtdOrder.StartHeader) { orderBase = new StartHeaderOrder(); } return(orderBase); }
public static WriteToDisplayCommand Factory(InputByteArray InputArray) { WriteToDisplayCommand wtdCmd = null; if (InputArray.RemainingLength >= 4) { var buf = InputArray.PeekBytes(4); if ((buf[0] == 0x04) && (buf[1] == 0x11)) { byte[] controlChars = new byte[2]; Array.Copy(buf, 3, controlChars, 0, 2); wtdCmd = new WriteToDisplayCommand(InputArray, controlChars); InputArray.AdvanceIndex(4); // gather WTD orders and display characters. while (true) { if (InputArray.RemainingLength == 0) { break; } var b1 = InputArray.PeekByte(0); var wtdOrder = b1.ToWtdOrder(); if (wtdOrder != null) { } else if (TextDataOrder.IsTextDataChar(b1)) { var tdOrder = TextDataOrder.Factory(InputArray); wtdCmd.OrderList.Add(tdOrder); } else { break; } } } } return(wtdCmd); }
/// <summary> /// scan the InputArray buffer until a char which is not a valid text data byte. /// </summary> /// <param name="InputArray"></param> /// <returns></returns> public static int ScanNonTextDataByte(InputByteArray InputArray) { int lx = InputArray.RemainingLength; int ix = 0; while (ix < lx) { var b1 = InputArray.PeekByte(ix); if (IsTextDataChar(b1) == true) { ix += 1; } else { break; } } return(ix); }
public NullControlFunction(InputByteArray InputArray) : base(InputArray, ControlFunctionCode.Null) { var ba = new ByteArrayBuilder(); // isolate the series of null bytes. while (InputArray.IsEof() == false) { var b1 = InputArray.PeekByte(0); if (b1 != 0x00) { break; } // accum to array of null bytes. ba.Append(b1); InputArray.AdvanceIndex(1); } this.NullBytes = ba.ToByteArray(); }
public TextControlFunction(InputByteArray InputArray) : base(InputArray, ControlFunctionCode.Text) { var ba = new ByteArrayBuilder(); // isolate the series of printable bytes. while (InputArray.IsEof() == false) { var b1 = InputArray.PeekByte(0); if (Array.IndexOf(ControlFunctionCodeExt.TextBytes, b1) == -1) { break; } // is a printable byte. accum to array of text bytes. ba.Append(b1); InputArray.AdvanceIndex(1); } this.TextBytes = ba.ToByteArray(); }
/// <summary> /// scan the InputArray buffer until a char which is not a valid text data byte. /// Returns absolute index location of the non text byte. /// If non text char is not found, returns index one past last byte of the array. /// Also returns the length of text data that was scanned past. /// </summary> /// <param name="InputArray"></param> /// <returns></returns> public static Tuple <int, int> ScanNonTextDataByte(InputByteArray InputArray) { int remLx = InputArray.RemainingLength; int ix = 0; while (ix < remLx) { var b1 = InputArray.PeekByte(ix); if (IsTextDataChar(b1) == true) { ix += 1; } else { break; } } int fx = InputArray.Index + ix; int lx = fx - InputArray.Index; return(new Tuple <int, int>(fx, lx)); }
/// <summary> /// working from InputArray positioned at the start of data stream header, /// peek ahead and calc the header length. /// </summary> /// <param name="InputArray"></param> /// <returns></returns> public static int PeekDataStreamHeaderLength(this InputByteArray InputArray) { byte varLgth = InputArray.PeekByte(6); return(6 + varLgth); }