Skip to content

Commit

Permalink
Merge pull request #97 from civspan/hotfix/decode-point-along-line-no…
Browse files Browse the repository at this point in the history
…-positive-offset

Fix decoding of PointAlongLine messages with no positive offset byte
  • Loading branch information
xivk authored Apr 25, 2024
2 parents 91baf8a + 26c42ee commit 480946b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions test/OpenLR.Test/Binary/PointAlongLineLocationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace OpenLR.Test.Binary
{
using NuGet.Frameworks;

Check failure on line 9 in test/OpenLR.Test/Binary/PointAlongLineLocationTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The type or namespace name 'NuGet' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 9 in test/OpenLR.Test/Binary/PointAlongLineLocationTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

The type or namespace name 'NuGet' could not be found (are you missing a using directive or an assembly reference?)

/// <summary>
/// Contains tests for decoding/encoding a point along location to/from OpenLR binary representation.
/// </summary>
Expand Down Expand Up @@ -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.
}

/// <summary>
/// Decode a message with only 16 bytes, i.e. no positive offset byte
/// </summary>
[Test]
public void DecodeBase64WithNoOffset()
{
// Message with 16 bytes.
var stringData = Convert.FromBase64String("Kwhv2ikWNjPZAP/XAAUzCA==");

Assert.IsTrue(PointAlongLineLocationCodec.CanDecode(stringData));
Assert.DoesNotThrow(() => PointAlongLineLocationCodec.Decode(stringData));
}

/// <summary>
/// A simple test encoding from a base64 string.
Expand Down

0 comments on commit 480946b

Please sign in to comment.