Files
NDEFPCLib/import/NDEF/NDEFShortRecord.cs
stubbfel 503d79a89f import
2013-08-27 23:18:39 +02:00

64 lines
2.4 KiB
C#

//-----------------------------------------------------------------------
// <copyright file="NDEFShortRecord.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
// <sience>21.08.2013</sience>
//----------------------------------------------------------------------
namespace CampusAppWP8.Utility.NDEF
{
using System.Text;
/// <summary>Ndef short record.</summary>
/// <remarks>Stubbfel, 21.08.2013.</remarks>
public class NDEFShortRecord : NDEFRecord
{
/// <summary>Initializes a new instance of the NDEFShortRecord class.</summary>
/// <remarks>Stubbfel, 21.08.2013.</remarks>
public NDEFShortRecord()
{
this.HeaderSize = 4;
this.SR = NDEFFlags.SRSET;
this.IL = NDEFFlags.UNSET;
this.CF = NDEFFlags.UNSET;
}
/// <summary>Initializes a new instance of the NDEFShortRecord class.</summary>
/// <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)
: base(array)
{
this.HeaderSize = 4;
this.Type = (NDEFMessage.TYPEVAL)array[index + 3];
this.PayloadPraefix = NDEFMessage.GetPraefix(this.Type);
int payLoadSize = array[index + 2] - this.PayloadPraefix.Length;
this.Payload = Encoding.UTF8.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()
{
byte[] payloadAr = Encoding.UTF8.GetBytes(this.PayloadPraefix + this.Payload);
byte[] array = new byte[payloadAr.Length + this.HeaderSize];
array[0] = this.FormatFlags;
array[1] = NDEFRecord.TypeSize;
array[2] = (byte)(Payload.Length + this.PayloadPraefix.Length);
array[3] = (byte)this.Type;
int i = this.HeaderSize;
foreach (byte b in payloadAr)
{
array[i] = b;
i++;
}
return array;
}
}
}