/// <summary> /// Convierte los datos formateados en datos válidos del componente /// de mensajería. /// </summary> /// <param name="parserContext"> /// Es el contexto de análisis y construcción de mensajes donde /// reside la información a decodificar. /// </param> /// <param name="length"> /// Es la cantidad de información que se desea obtener. /// </param> /// <returns> /// Una cadena de caracteres con los datos del componente de mensajería. /// </returns> public string Decode(ref ParserContext parserContext, int length) { if (parserContext.DataLength < (length << 1)) { throw new ArgumentException(SR.InsufficientData, "length"); } byte[] result = new byte[length]; byte[] buffer = parserContext.GetBuffer(); int offset = parserContext.LowerDataBound; for (int i = offset + (length << 1) - 1; i >= offset; i--) { int right = buffer[i] > 0x40 ? 10 + (buffer[i] > 0x60 ? buffer[i] - 0x61 : buffer[i] - 0x41) : buffer[i] - 0x30; int left = buffer[--i] > 0x40 ? 10 + (buffer[i] > 0x60 ? buffer[i] - 0x61 : buffer[i] - 0x41) : buffer[i] - 0x30; result[(i - offset) >> 1] = ( byte)((left << 4) | right); } parserContext.Consumed(length << 1); return(FrameworkEncoding.GetInstance().Encoding.GetString(result)); }
/// <summary> /// Convierte a un array de bytes el valor del campo. /// </summary> /// <returns> /// Un array de bytes. /// </returns> public override byte[] GetBytes() { if (_value == null) { return(null); } return(FrameworkEncoding.GetInstance().Encoding.GetBytes(_value)); }
/// <summary> /// Devuelve una cadena de caracteres conteniendo una copia de /// los datos almacenados en el buffer. /// </summary> /// <returns> /// Una copia de los datos almacenados en el buffer. /// </returns> /// <remarks> /// Si el buffer no contiene datos, esta función retorna /// <see langref="null"/>. /// </remarks> public string GetDataAsString() { if (_upperDataBound == 0) { return(null); } return(FrameworkEncoding.GetInstance().Encoding.GetString(_buffer, 0, _upperDataBound)); }
/// <summary> /// It returns a string representation of the field value. /// </summary> /// <returns> /// A string representing the field value. /// </returns> /// <remarks> /// If the value is null, this function returns an empty string. /// </remarks> public override string ToString() { if (_value == null) { return(string.Empty); } else { return(FrameworkEncoding.GetInstance().Encoding.GetString(_value)); } }
public void GetBytes() { Message value = new Message(); InnerMessageField field = new InnerMessageField(19, value); Assert.IsNull(field.GetBytes()); value.Formatter = GetFormatter(_fixedMessageFormatter); value.Fields.Add(1, "HE"); value.Fields.Add(2, "LLO"); Assert.IsTrue( FrameworkEncoding.GetInstance().Encoding.GetString(field.GetBytes()) == "HELLO"); }
/// <summary> /// Devuelve una cadena de caracteres con una copia de los datos /// almacenados en el buffer. /// </summary> /// <param name="consume"> /// Indica en <see langref="true"/> que los datos deben ser eliminados /// del buffer. /// </param> /// <param name="count"> /// Indica la cantidad de caracteres a extraer del buffer. /// </param> /// <returns> /// Una copia de los datos almacenados en el buffer. /// </returns> /// <remarks> /// Si <paramref name="count"/> es igual a cero esta función retorna /// <see langref="null"/>. /// </remarks> /// <exception cref="ArgumentException"> /// En caso de que no exista en el buffer la cantidad de caracteres /// especificados en el parámetro <paramref name="count"/>. /// </exception> public string GetDataAsString(bool consume, int count) { if (count == 0) { return(null); } if (DataLength < count) { throw new ArgumentException(SR.InsufficientData, "count"); } string data = FrameworkEncoding.GetInstance().Encoding.GetString( _buffer, _lowerDataBound, count); if (consume) { Consumed(count); } return(data); }
/// <summary> /// It sets the value of the field. /// </summary> public void SetFieldValue(string value) { _value = FrameworkEncoding.GetInstance().Encoding.GetBytes(( string )value); }