diff --git a/src/ndefpclib/record/NDEFRecord.cs b/src/ndefpclib/record/NDEFRecord.cs
index 074c86e..3f214a1 100644
--- a/src/ndefpclib/record/NDEFRecord.cs
+++ b/src/ndefpclib/record/NDEFRecord.cs
@@ -20,6 +20,10 @@ namespace ndefpclib.records
/// Type of the message.
private MsgType msgType;
+
+ /// Size of the encoded payload.
+ private int encodedPayloadSize = -1;
+
#endregion
#region Constructors
@@ -35,7 +39,7 @@ namespace ndefpclib.records
/// The array.
/// The size of the header.
/// (Optional) zero-based index of the.
- public NDEFRecord(byte[] array, int headerSize,int index = 0)
+ public NDEFRecord(byte[] array, int headerSize, int index = 0)
{
this.msgType = MsgType.GetType(array, index);
this.HeaderSize = headerSize;
@@ -145,7 +149,29 @@ namespace ndefpclib.records
{
get
{
- return this.HeaderSize + this.Payload.Length + this.PayloadPraefix.Length;
+ return this.HeaderSize + this.EncodedPayloadSize + this.PayloadPraefix.Length;
+ }
+ }
+
+ /// Gets the size of the encoded payload.
+ /// The size of the encoded payload.
+ public int EncodedPayloadSize
+ {
+ get
+ {
+ if (this.encodedPayloadSize >= 0)
+ {
+ return this.encodedPayloadSize;
+ }
+ else if (this.msgType != null && this.encodedPayloadSize < 0)
+ {
+ this.encodedPayloadSize = this.msgType.Encoder.GetByteCount(this.Payload);
+ return this.encodedPayloadSize;
+ }
+ else
+ {
+ return this.Payload.Length;
+ }
}
}
diff --git a/src/ndefpclib/record/NDEFShortRecord.cs b/src/ndefpclib/record/NDEFShortRecord.cs
index 30f3f48..e675d61 100644
--- a/src/ndefpclib/record/NDEFShortRecord.cs
+++ b/src/ndefpclib/record/NDEFShortRecord.cs
@@ -56,7 +56,7 @@ namespace ndefpclib.records
array[0] = this.FormatFlags;
array[1] = NDEFRecord.TypeSize;
- array[2] = (byte)(Payload.Length + this.PayloadPraefix.Length);
+ array[2] = (byte)(this.EncodedPayloadSize + this.PayloadPraefix.Length);
array[3] = (byte)this.Type;
int i = this.HeaderSize;