diff --git a/src/ndefpclib/message/NDEFMessage.cs b/src/ndefpclib/message/NDEFMessage.cs index 2e90c8d..87b38f0 100644 --- a/src/ndefpclib/message/NDEFMessage.cs +++ b/src/ndefpclib/message/NDEFMessage.cs @@ -4,6 +4,7 @@ using ndefpclib.type; using System.Collections.Generic; using System.IO; + using System.Text; /// Ndef message. /// Stubbfel, 21.08.2013. @@ -57,14 +58,14 @@ /// Initializes a new instance of the NDEFMessage class. /// Stubbfel, 21.08.2013. /// The array. - public NDEFMessage(byte[] array) + public NDEFMessage(byte[] array, Encoding payLoadEncoding) { this.records = new List(); 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 @@ /// Converts this object to a byte array. /// Stubbfel, 21.08.2013. /// This object as a byte[]. - 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(); diff --git a/src/ndefpclib/record/NDEFRecord.cs b/src/ndefpclib/record/NDEFRecord.cs index 31a214d..1ccb0b5 100644 --- a/src/ndefpclib/record/NDEFRecord.cs +++ b/src/ndefpclib/record/NDEFRecord.cs @@ -145,7 +145,7 @@ /// Converts the record to a byte array. /// Stubbfel, 21.08.2013. /// This object as a byte[]. - public abstract byte[] ToByteArray(); + public abstract byte[] ToByteArray(Encoding payLoadEncoding); #endregion } diff --git a/src/ndefpclib/record/NDEFShortRecord.cs b/src/ndefpclib/record/NDEFShortRecord.cs index 4976461..8ddd268 100644 --- a/src/ndefpclib/record/NDEFShortRecord.cs +++ b/src/ndefpclib/record/NDEFShortRecord.cs @@ -22,22 +22,22 @@ /// Stubbfel, 21.08.2013. /// The array. /// (Optional) zero-based index of the. - 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); } /// Converts this NDEFShortRecord to a byte array. /// Stubbfel, 21.08.2013. /// This object as a byte[]. - 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;