diff --git a/src/OpenLR/Codecs/Binary/Codecs/PointAlongLineLocationCodec.cs b/src/OpenLR/Codecs/Binary/Codecs/PointAlongLineLocationCodec.cs
index 5fdb68e..bf5d355 100644
--- a/src/OpenLR/Codecs/Binary/Codecs/PointAlongLineLocationCodec.cs
+++ b/src/OpenLR/Codecs/Binary/Codecs/PointAlongLineLocationCodec.cs
@@ -57,7 +57,7 @@ public static PointAlongLineLocation Decode(byte[] data)
pointAlongLine.First = first;
pointAlongLine.Orientation = OrientationConverter.Decode(data, 7, 0);
pointAlongLine.SideOfRoad = SideOfRoadConverter.Decode(data, 14, 0);
- pointAlongLine.PositiveOffsetPercentage = OffsetConvertor.Decode(data, 16);
+ pointAlongLine.PositiveOffsetPercentage = data.Length > 16 ? OffsetConvertor.Decode(data, 16) : null;
pointAlongLine.Last = last;
return pointAlongLine;
diff --git a/test/OpenLR.Test/Binary/PointAlongLineLocationTests.cs b/test/OpenLR.Test/Binary/PointAlongLineLocationTests.cs
index 6efe69e..b20a3cb 100644
--- a/test/OpenLR.Test/Binary/PointAlongLineLocationTests.cs
+++ b/test/OpenLR.Test/Binary/PointAlongLineLocationTests.cs
@@ -6,6 +6,8 @@
namespace OpenLR.Test.Binary
{
+ using NuGet.Frameworks;
+
///
/// Contains tests for decoding/encoding a point along location to/from OpenLR binary representation.
///
@@ -53,6 +55,19 @@ public void DecodeBase64Test()
Assert.AreEqual(SideOfRoad.Left, pointAlongLineLocation.SideOfRoad);
Assert.AreEqual(30.19, pointAlongLineLocation.PositiveOffsetPercentage, 0.5); // binary encode loses accuracy.
}
+
+ ///
+ /// Decode a message with only 16 bytes, i.e. no positive offset byte
+ ///
+ [Test]
+ public void DecodeBase64WithNoOffset()
+ {
+ // Message with 16 bytes.
+ var stringData = Convert.FromBase64String("Kwhv2ikWNjPZAP/XAAUzCA==");
+
+ Assert.IsTrue(PointAlongLineLocationCodec.CanDecode(stringData));
+ Assert.DoesNotThrow(() => PointAlongLineLocationCodec.Decode(stringData));
+ }
///
/// A simple test encoding from a base64 string.