Skip to content

Commit

Permalink
Merge pull request #12 from Nike-Inc/deal-with-leading-a
Browse files Browse the repository at this point in the history
Hacky fix for dealing with leading A's
  • Loading branch information
gregghz authored Apr 15, 2019
2 parents 4b2fa5a + af8e6f8 commit 5a6122b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions epc-core/src/main/java/com/nike/epc/model/xndt/Xndt.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public static Xndt fromBits(RawBits bits, int size) {

// [12, 54) - 42 bits
String style = bits.getBase64Decoded(12, 42);
// This is an ugly hack to deal with styles with leading As that
// are 6 digits. No style will be less than 6 digits. If a style
// is 7 digits and starts with A it will still be broken. Encoding
// of these will need to be modified to fully resolve this issue.
while (style.length() < 6) {
style = 'A' + style;
}

// [54, 72) - 18 bits
String color = bits.getBase64Decoded(54, 18);
Expand Down
11 changes: 11 additions & 0 deletions epc-core/src/test/java/com/nike/epc/model/xndt/XndtTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@ public void parseXndt() {
assertEquals("Z9Z9Z9-ZZZ", xndt.styleColor());
assertEquals(10, xndt.serialNumber());
}

@Test
public void praseWithoutDroppingLeadingA() {
// Q4312-600
RawBits bits = RawBits.fromHex("E31000438DF5DBAD3400001E");
Xndt xndt = Xndt.fromBits(bits, 96);

assertEquals("AQ4312", xndt.style());
assertEquals("600", xndt.color());
assertEquals("AQ4312-600", xndt.styleColor());
}
}

0 comments on commit 5a6122b

Please sign in to comment.