change prafix to byte an encoding to char

This commit is contained in:
stubbfel
2013-10-23 16:45:15 +02:00
parent 1d85089e85
commit 7e6a25af8e
6 changed files with 23 additions and 36 deletions

View File

@@ -15,7 +15,7 @@ namespace ndefpclib.message.Text
/// <param name="content"> The content. </param>
/// <param name="encoding"> The encoding. </param>
/// <param name="lang"> The language. </param>
public TextMessage(string content, string encoding, string lang)
public TextMessage(string content, char encoding, string lang)
: base(content, new TextType(encoding,lang))
{
}

View File

@@ -151,7 +151,7 @@ namespace ndefpclib.records
/// <summary> Gets or sets the payload praefix. </summary>
/// <value> The payload praefix. </value>
public string PayloadPraefix { get { return this.MsgType.PayloadPrefix; } set { this.MsgType.PayloadPrefix = value; } }
public byte[] PayloadPraefix { get { return this.MsgType.PayloadPrefix; } set { this.MsgType.PayloadPrefix = value; } }
/// <summary> Gets or sets the size of the header. </summary>
/// <value> The size of the header. </value>

View File

@@ -37,7 +37,8 @@ namespace ndefpclib.records
/// <summary> Initializes a new instance of the NDEFShortRecord class. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="type"> The type. </param>
public NDEFShortRecord(MsgType type) : base(type)
public NDEFShortRecord(MsgType type)
: base(type)
{
this.HeaderSize = 4;
this.SR = NDEFFlags.SRSET;
@@ -50,8 +51,8 @@ namespace ndefpclib.records
/// <seealso cref="M:ndefpclib.records.NDEFRecord.ToByteArray()"/>
public override byte[] ToByteArray()
{
byte[] payloadAr = this.MsgType.Encoder.GetBytes(this.PayloadPraefix + this.Payload);
byte[] array = new byte[payloadAr.Length + this.HeaderSize];
byte[] payloadAr = this.MsgType.Encoder.GetBytes(this.Payload);
byte[] array = new byte[payloadAr.Length + this.HeaderSize + this.PayloadPraefix.Length];
array[0] = this.FormatFlags;
array[1] = NDEFRecord.TypeSize;
@@ -59,6 +60,11 @@ namespace ndefpclib.records
array[3] = (byte)this.Type;
int i = this.HeaderSize;
foreach (byte b in this.PayloadPraefix)
{
array[i] = b;
i++;
}
foreach (byte b in payloadAr)
{
array[i] = b;

View File

@@ -11,16 +11,16 @@ namespace ndefpclib.type.Const
public class TextEncoding
{
/// <summary> The UTF 8. </summary>
public const string UTF8 = "\x02";
public const char UTF8 = '\x02';
/// <summary> The UTF 16. </summary>
public const string UTF16 = "\x82";
public const char UTF16 = '\x82';
/// <summary> Gets an encoding. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="input"> The input. </param>
/// <returns> The encoding. </returns>
public static Encoding GetEncoding(string input)
public static Encoding GetEncoding(char input)
{
switch (input)
{

View File

@@ -16,12 +16,16 @@ namespace ndefpclib.type
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="encoding"> (Optional) the encoding. </param>
/// <param name="lang"> (Optional) the language. </param>
public TextType(string encoding = TextEncoding.UTF8, string lang = Language.DE)
public TextType(char encoding = TextEncoding.UTF8, string lang = Language.DE)
{
this.TNFValue = TNFVAL.WKT;
this.TypeValue = TYPEVAL.TEXT;
this.Encoder = TextEncoding.GetEncoding(encoding);
this.PayloadPrefix = encoding + lang;
this.PayloadPrefix = new byte[3];
this.PayloadPrefix[0] = (byte)encoding;
this.PayloadPrefix[1] = (byte)lang[0];
this.PayloadPrefix[2] = (byte)lang[1];
}
/// <summary> Gets text type. </summary>
@@ -36,7 +40,7 @@ namespace ndefpclib.type
return null;
}
string encoding = string.Format("{0}", (char)array[index + 4]);
char encoding = (char)array[index + 4];
Encoding encoder = TextEncoding.GetEncoding(encoding);
if (encoder == null)
@@ -44,7 +48,7 @@ namespace ndefpclib.type
return null;
}
string lang = encoder.GetString(array, 5, 2);
string lang = Encoding.UTF8.GetString(array, 5, 2);
return new TextType(encoding, lang);
}
}

View File

@@ -65,7 +65,7 @@ namespace ndefpclib.type
/// <summary> Gets or sets the payload prefix. </summary>
/// <value> The payload prefix. </value>
public string PayloadPrefix { get; set; }
public byte[] PayloadPrefix { get; set; }
/// <summary> Gets or sets the tnf value. </summary>
/// <value> The tnf value. </value>
@@ -80,29 +80,6 @@ namespace ndefpclib.type
#region methods
/// <summary> Gets a praefix. </summary>
/// <remarks> Stubbfel, 21.08.2013. </remarks>
/// <param name="type"> The type. </param>
/// <returns> The praefix. </returns>
public static string GetPraefix(MsgType.TYPEVAL type)
{
string praefix = string.Empty;
switch (type)
{
case MsgType.TYPEVAL.TEXT:
praefix = "\x02" + "de";
break;
case MsgType.TYPEVAL.URL:
praefix = "\x01";
break;
default:
break;
}
return praefix;
}
/// <summary> Gets a type. </summary>
/// <remarks> Stubbfel, 23.10.2013. </remarks>
/// <param name="array"> The array. </param>