add encodinf parmetr
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
using ndefpclib.type;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
/// <summary>Ndef message.</summary>
|
||||
/// <remarks>Stubbfel, 21.08.2013.</remarks>
|
||||
@@ -57,14 +58,14 @@
|
||||
/// <summary>Initializes a new instance of the NDEFMessage class.</summary>
|
||||
/// <remarks>Stubbfel, 21.08.2013.</remarks>
|
||||
/// <param name="array">The array.</param>
|
||||
public NDEFMessage(byte[] array)
|
||||
public NDEFMessage(byte[] array, Encoding payLoadEncoding)
|
||||
{
|
||||
this.records = new List<NDEFRecord>();
|
||||
|
||||
NDEFRecord tmpRecord = null;
|
||||
for (int i = 0; i < array.Length; i += tmpRecord.RecordSize)
|
||||
{
|
||||
tmpRecord = new NDEFShortRecord(array, i);
|
||||
tmpRecord = new NDEFShortRecord(array, payLoadEncoding, i);
|
||||
|
||||
this.records.Add(tmpRecord);
|
||||
}
|
||||
@@ -92,12 +93,12 @@
|
||||
/// <summary>Converts this object to a byte array.</summary>
|
||||
/// <remarks>Stubbfel, 21.08.2013.</remarks>
|
||||
/// <returns>This object as a byte[].</returns>
|
||||
public byte[] ToByteArray()
|
||||
public virtual byte[] ToByteArray(Encoding payLoadEncoding)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
foreach (NDEFRecord record in this.records)
|
||||
{
|
||||
ms.Write(record.ToByteArray(), 0, record.RecordSize);
|
||||
ms.Write(record.ToByteArray(payLoadEncoding), 0, record.RecordSize);
|
||||
}
|
||||
|
||||
return ms.ToArray();
|
||||
|
||||
@@ -145,7 +145,7 @@
|
||||
/// <summary>Converts the record to a byte array.</summary>
|
||||
/// <remarks>Stubbfel, 21.08.2013.</remarks>
|
||||
/// <returns>This object as a byte[].</returns>
|
||||
public abstract byte[] ToByteArray();
|
||||
public abstract byte[] ToByteArray(Encoding payLoadEncoding);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -22,22 +22,22 @@
|
||||
/// <remarks>Stubbfel, 21.08.2013.</remarks>
|
||||
/// <param name="array">The array.</param>
|
||||
/// <param name="index">(Optional) zero-based index of the.</param>
|
||||
public NDEFShortRecord(byte[] array, int index = 0)
|
||||
public NDEFShortRecord(byte[] array, Encoding payLoadEncoding, int index = 0)
|
||||
: base(array)
|
||||
{
|
||||
this.HeaderSize = 4;
|
||||
this.Type = (MsgType.TYPEVAL)array[index + 3];
|
||||
this.PayloadPraefix = MsgType.GetPraefix(this.Type);
|
||||
int payLoadSize = array[index + 2] - this.PayloadPraefix.Length;
|
||||
this.Payload = Encoding.UTF8.GetString(array, index + this.HeaderSize + this.PayloadPraefix.Length, payLoadSize);
|
||||
this.Payload = payLoadEncoding.GetString(array, index + this.HeaderSize + this.PayloadPraefix.Length, payLoadSize);
|
||||
}
|
||||
|
||||
/// <summary>Converts this NDEFShortRecord to a byte array.</summary>
|
||||
/// <remarks>Stubbfel, 21.08.2013.</remarks>
|
||||
/// <returns>This object as a byte[].</returns>
|
||||
public override byte[] ToByteArray()
|
||||
public override byte[] ToByteArray(Encoding payLoadEncoding)
|
||||
{
|
||||
byte[] payloadAr = Encoding.UTF8.GetBytes(this.PayloadPraefix + this.Payload);
|
||||
byte[] payloadAr = payLoadEncoding.GetBytes(this.PayloadPraefix + this.Payload);
|
||||
byte[] array = new byte[payloadAr.Length + this.HeaderSize];
|
||||
|
||||
array[0] = this.FormatFlags;
|
||||
|
||||
Reference in New Issue
Block a user