/// <summary> /// return the datastreamcode from the input stream. /// </summary> /// <param name="InputArray"></param> /// <returns></returns> public static DataStreamCode?PeekDataStreamCode(this InputByteArray InputArray) { DataStreamCode?code = null; var buf = InputArray.PeekBytesLenient(7); if ((buf[2] == 0x12) && (buf[3] == 0xa0)) { code = buf.SubArray(4, 2).ToDataStreamCode(); } return(code); }
/// <summary> /// peek at current location in input array for a 5250 data stream header. If is /// a valid header, return a DataStreamHeader. Otherwise, return null. /// </summary> /// <param name="InputArray"></param> /// <returns></returns> public static DataStreamHeader PeekDataStreamHeader(this InputByteArray InputArray) { DataStreamHeader dsh = null; if (InputArray.IsDataStreamHeader( ) == true) { var buf = new InputByteArray(InputArray.PeekBytesLenient(100)); var rv = DataStreamHeader.Factory(buf); dsh = rv.Item1; } return(dsh); }
protected DataStreamHeader(InputByteArray InputArray, string ItemName) : base(InputArray, ItemName) { byte[] buf = null; // must be at least 7 bytes in the input stream. if (InputArray.RemainingLength < 7) { this.Errmsg = "Not enough bytes for data stream header"; } // isolate the next 7 bytes. if (this.Errmsg == null) { buf = InputArray.PeekBytesLenient(7); // the first 6 bytes are logical record length, 2 byte marker and 2 bytes // DataStreamCode. this.DataStreamLength = buf.BigEndianBytesToShort(0); this.Marker = buf.SubArray(2, 2); this.StreamCodeBytes = buf.SubArray(4, 2); this.StreamCode = StreamCodeBytes.ToDataStreamCode(); this.VariableLength = buf[6]; if ((this.Marker[0] != 0x12) || (this.Marker[1] != 0xa0)) { this.Errmsg = "Invalid record type"; } else if (this.DataStreamLength < 7) { this.Errmsg = "Invalid record length"; } else if (this.VariableLength == 0) { this.Errmsg = "Invalid variable length"; } } if (this.Errmsg == null) { this.RawBytes = InputArray.GetBytes(this.HeaderLength); this.BytesLength = this.HeaderLength; } }
public StartPrinterFileDataStreamHeader(InputByteArray InputArray) : base(InputArray, "StartPrinterFileDataStreamHeader") { byte[] buf = null; buf = InputArray.PeekBytesLenient(20); if (InputArray.RemainingLength < 3) { this.Errmsg = "Not enough bytes for data stream header"; } // a start printer file message. if ((this.Errmsg == null) && (buf.SubArray(0, 3).CompareEqual(StartPrinterFileMarkerBytes) == true)) { // buf = InputArray.GetBytes(this.PayloadLength); } else if (this.Errmsg == null) { this.Errmsg = "Bytes do not contain StartPrinterFile data stream header"; } }
public static Tuple <DataStreamHeader, string> Factory(InputByteArray InputArray) { DataStreamHeader dsh = null; string errmsg = null; int rcdLgth = 0; byte[] buf = null; DataStreamCode dataStreamCode = DataStreamCode.Terminal; if (InputArray.RemainingLength < 10) { errmsg = "Not enough bytes for data stream header"; } if (errmsg == null) { buf = InputArray.PeekBytesLenient(20); // the first 6 bytes are logical record length, 2 byte marker and 2 bytes // DataStreamCode. rcdLgth = buf.BigEndianBytesToShort(0); var rcdType = buf.SubArray(2, 2); if ((rcdType[0] != 0x12) || (rcdType[1] != 0xa0)) { errmsg = "Invalid record type"; } else if (rcdLgth < 10) { errmsg = "Invalid record length"; } } // isolate the data stream code. if (errmsg == null) { var nullableCode = buf.SubArray(4, 2).ToDataStreamCode(); if (nullableCode == null) { errmsg = "not valid data stream code"; } else { dataStreamCode = nullableCode.Value; } } if (errmsg == null) { if (dataStreamCode == DataStreamCode.Terminal) { dsh = new TerminalDataStreamHeader(InputArray); } else if (dataStreamCode == DataStreamCode.PrinterStartup) { dsh = new PrinterStartupDataStreamHeader(InputArray); } else if (dataStreamCode == DataStreamCode.PrinterPrint) { var payloadBx = InputArray.PeekDataStreamHeaderLength(); var payloadBuf = InputArray.PeekBytesLenient(payloadBx, 3); if (payloadBuf.CompareEqual(StartPrinterFileMarkerBytes) == true) { dsh = new StartPrinterFileDataStreamHeader(InputArray); } else { dsh = new PrinterDataStreamHeader(InputArray, "Printer"); } } else if (dataStreamCode == DataStreamCode.PrinterResponse) { dsh = new PrinterDataStreamHeader(InputArray, "PrintResponse"); } } return(new Tuple <DataStreamHeader, string>(dsh, errmsg)); }
public static ControlFunction Factory(InputByteArray InputArray) { ControlFunction func = null; // isolate the function code. ControlFunctionCode?nullableFuncCode = null; int length = 0; { var buf = InputArray.PeekBytesLenient(5); var rv = buf.ToControlFunctionCode(); nullableFuncCode = rv.Item1; length = rv.Item2; } if (nullableFuncCode != null) { var funcCode = nullableFuncCode.Value; if (funcCode == ControlFunctionCode.Null) { func = new NullControlFunction(InputArray); } else if (Array.IndexOf(SimpleFunctionCodes, funcCode) != -1) { func = new SingleByteControlFunction(InputArray, funcCode); } else if (funcCode == ControlFunctionCode.Text) { func = new TextControlFunction(InputArray); } else if (funcCode == ControlFunctionCode.PresentationPosition) { func = new PresentationPositionControlFunction(InputArray); } else if (funcCode == ControlFunctionCode.SetPrint) { func = new SetPrintControlFunction(InputArray); } else if (funcCode == ControlFunctionCode.SetUndocumented) { func = new SetUndocumentedControlFunction(InputArray); } else if (funcCode == ControlFunctionCode.SetTranslation) { func = new SetTranslationControlFunction(InputArray); } else if (funcCode == ControlFunctionCode.SetGraphicError) { func = new SetGraphicErrorControlFunction(InputArray); } else if (funcCode == ControlFunctionCode.Undocumented1) { func = new UndocumentedControlFunction( InputArray, ControlFunctionCode.Undocumented1, 1); } else if (funcCode == ControlFunctionCode.Undocumented2) { func = new UndocumentedControlFunction( InputArray, ControlFunctionCode.Undocumented2, 0); } else if (funcCode == ControlFunctionCode.Undocumented3) { func = new UndocumentedControlFunction( InputArray, ControlFunctionCode.Undocumented3, 0); } } return(func); }