diff --git a/src/ndefpclib/message/Text/TextMessages.cs b/src/ndefpclib/message/Text/TextMessages.cs index 445b104..b457bf0 100644 --- a/src/ndefpclib/message/Text/TextMessages.cs +++ b/src/ndefpclib/message/Text/TextMessages.cs @@ -15,7 +15,7 @@ namespace ndefpclib.message.Text /// The content. /// The encoding. /// The language. - public TextMessage(string content, string encoding, string lang) + public TextMessage(string content, char encoding, string lang) : base(content, new TextType(encoding,lang)) { } diff --git a/src/ndefpclib/record/NDEFRecord.cs b/src/ndefpclib/record/NDEFRecord.cs index 4f20db1..074c86e 100644 --- a/src/ndefpclib/record/NDEFRecord.cs +++ b/src/ndefpclib/record/NDEFRecord.cs @@ -151,7 +151,7 @@ namespace ndefpclib.records /// Gets or sets the payload praefix. /// The payload praefix. - 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; } } /// Gets or sets the size of the header. /// The size of the header. diff --git a/src/ndefpclib/record/NDEFShortRecord.cs b/src/ndefpclib/record/NDEFShortRecord.cs index 88b1e35..30f3f48 100644 --- a/src/ndefpclib/record/NDEFShortRecord.cs +++ b/src/ndefpclib/record/NDEFShortRecord.cs @@ -37,7 +37,8 @@ namespace ndefpclib.records /// Initializes a new instance of the NDEFShortRecord class. /// Stubbfel, 23.10.2013. /// The type. - 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 /// 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; diff --git a/src/ndefpclib/type/Const/TextEncoding.cs b/src/ndefpclib/type/Const/TextEncoding.cs index fb3a797..8c6fff6 100644 --- a/src/ndefpclib/type/Const/TextEncoding.cs +++ b/src/ndefpclib/type/Const/TextEncoding.cs @@ -11,16 +11,16 @@ namespace ndefpclib.type.Const public class TextEncoding { /// The UTF 8. - public const string UTF8 = "\x02"; + public const char UTF8 = '\x02'; /// The UTF 16. - public const string UTF16 = "\x82"; + public const char UTF16 = '\x82'; /// Gets an encoding. /// Stubbfel, 23.10.2013. /// The input. /// The encoding. - public static Encoding GetEncoding(string input) + public static Encoding GetEncoding(char input) { switch (input) { diff --git a/src/ndefpclib/type/TextType.cs b/src/ndefpclib/type/TextType.cs index fdc0b68..705e3d0 100644 --- a/src/ndefpclib/type/TextType.cs +++ b/src/ndefpclib/type/TextType.cs @@ -16,12 +16,16 @@ namespace ndefpclib.type /// Stubbfel, 23.10.2013. /// (Optional) the encoding. /// (Optional) the language. - 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]; } /// Gets text type. @@ -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); } } diff --git a/src/ndefpclib/type/msgType.cs b/src/ndefpclib/type/msgType.cs index 3226653..22b2cfe 100644 --- a/src/ndefpclib/type/msgType.cs +++ b/src/ndefpclib/type/msgType.cs @@ -65,7 +65,7 @@ namespace ndefpclib.type /// Gets or sets the payload prefix. /// The payload prefix. - public string PayloadPrefix { get; set; } + public byte[] PayloadPrefix { get; set; } /// Gets or sets the tnf value. /// The tnf value. @@ -80,29 +80,6 @@ namespace ndefpclib.type #region methods - /// Gets a praefix. - /// Stubbfel, 21.08.2013. - /// The type. - /// The praefix. - 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; - } - /// Gets a type. /// Stubbfel, 23.10.2013. /// The array.