/// <summary> /// It parses the information in the parser context and builds the field. /// </summary> /// <param name="parserContext"> /// It's the parser context. /// </param> /// <returns> /// The new field built with the information found in the parser context. /// </returns> public override Field Parse(ref ParserContext parserContext) { // If MinValue, at this moment the length hasn't been decoded. if (parserContext.DecodedLength == int.MinValue) { if (!_lengthManager.EnoughData(ref parserContext)) { // Insufficient data to parse length, return null. return(null); } // Save length in parser context just in case field value // can't be parsed at this time (more data needed). parserContext.DecodedLength = _lengthManager.ReadLength(ref parserContext); } if (parserContext.DataLength < _encoder.GetEncodedLength( parserContext.DecodedLength)) { // Insufficient data to parse field value, return null. return(null); } // Create the new messaging component with parsing context data. BinaryField field = new BinaryField(FieldNumber, _encoder.Decode(ref parserContext, parserContext.DecodedLength)); _lengthManager.ReadLengthTrailer(ref parserContext); return(field); }
/// <summary> /// It parses the information in the parser context and builds the field. /// </summary> /// <param name="parserContext"> /// It's the parser context. /// </param> /// <returns> /// The new field built with the information found in the parser context. /// </returns> public override Field Parse(ref ParserContext parserContext) { // If MinValue, at this moment the length hasn't been decoded. if (parserContext.DecodedLength == int.MinValue) { if (!_lengthManager.EnoughData(ref parserContext)) { // Insufficient data to parse length, return null. return(null); } // Save length in parser context just in case field value // can't be parsed at this time (more data needed). parserContext.DecodedLength = _lengthManager.ReadLength(ref parserContext); } if (parserContext.DataLength < _encoder.GetEncodedLength( parserContext.DecodedLength)) { // Insufficient data to parse field value, return null. return(null); } Message message = null; if (parserContext.DecodedLength > 0) { ParserContext innerMsgParserContext = new ParserContext(parserContext.DecodedLength); innerMsgParserContext.Write( _encoder.Decode(ref parserContext, parserContext.DecodedLength)); message = _messageFormatter.Parse(ref innerMsgParserContext); if (message == null) { throw new MessagingException(SR.CantParseInnerMessage); } } // Create the new messaging component with parsing context data. InnerMessageField field = new InnerMessageField(FieldNumber, message); _lengthManager.ReadLengthTrailer(ref parserContext); return(field); }
/// <summary> /// Analiza la información contenida en un contexto de analisis y /// construcción de mensajes, y construye en base a ella un nuevo /// cabezal para el que el formateador se ha construido. /// </summary> /// <param name="parserContext"> /// Es el contexto de analisis y construcción y construcción de mensajes. /// </param> /// <returns> /// El nuevo cabezal contruido a partir de la información contenida en /// el contexto de análisis y construcción de mensajes. /// </returns> public virtual MessageHeader Parse(ref ParserContext parserContext) { // If zero, at this moment the length hasn't been decoded. if (parserContext.DecodedLength == int.MinValue) { if (!_lengthManager.EnoughData(ref parserContext)) { // Insufficient data to parse length, return null. return(null); } // Save length in parser context just in case field value // can't be parsed at this time (more data needed). parserContext.DecodedLength = _lengthManager.ReadLength(ref parserContext); } if (parserContext.DataLength < _encoder.GetEncodedLength( parserContext.DecodedLength)) { // Insufficient data to parse field value, return null. return(null); } // Create the new messaging component with parsing context data. StringMessageHeader header; if (_padding == null) { header = new StringMessageHeader(_encoder.Decode( ref parserContext, parserContext.DecodedLength)); } else { header = new StringMessageHeader(_padding.RemovePad( _encoder.Decode(ref parserContext, parserContext.DecodedLength))); } _lengthManager.ReadLengthTrailer(ref parserContext); return(header); }