public byte[] ToMsg() { try { var msg = new byte[PackedLength]; lenFormatter.Pack(msg, PackedLength - 4, 0); msg[4] = (byte)0xf0; msg[5] = 0x00; msg[6] = 0x21; int offset = 7; byte[] bitmap = GenerateBitmap(); Array.Copy(bitmap, 0, msg, offset, bitmap.Length); offset += bitmap.Length; foreach (var kvp in this) { IFieldDescriptor fieldDesc = GetFieldDescriptor(kvp.Key); byte[] fieldData = fieldDesc.Pack((int)kvp.Key, kvp.Value); Array.Copy(fieldData, 0, msg, offset, fieldData.Length); offset += fieldData.Length; } return(msg); } catch (FieldFormatException ffe) { throw new FieldFormatException("48.", ffe.FieldNumber, ffe.Message); } }
/// <summary> /// Packs the field into a byte[] /// </summary> /// <param name = "fieldNumber">number of the field</param> /// <param name = "value">Value of the field to pack</param> /// <returns>field data packed into a byte[]</returns> public byte[] Pack(int fieldNumber, string value) { return(_decoratedFieldDescriptor.Pack(fieldNumber, value)); }
/// <summary> /// Returns a byte[] representation of the field /// </summary> /// <returns>byte[] representing the field</returns> public byte[] ToMsg() { return(_fieldDescriptor.Pack(FieldNumber, Value)); }