change prafix to byte an encoding to char
This commit is contained in:
@@ -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))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user