Skip to content

Commit

Permalink
The definition of insanity is writing the same code twice and expecti…
Browse files Browse the repository at this point in the history
…ng different results

Same bug with implicit cast bullshit
  • Loading branch information
mcm001 committed Oct 8, 2023
1 parent 63279ef commit 5ee7fdf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ public void encode(byte src) {
packetData[writePos++] = src;
}

/**
* Encodes the short into the packet.
*
* @param src The short to encode.
*/
public void encode(short src) {
packetData[writePos++] = (byte) (src >>> 8);
packetData[writePos++] = (byte) src;
}

/**
* Encodes the integer into the packet.
*
Expand Down Expand Up @@ -196,4 +206,11 @@ public double[] decodeDoubleArray(int len) {
}
return ret;
}

public short decodeShort() {
if (packetData.length < readPos + 1) {
return 0;
}
return (short) ((0xff & packetData[readPos++]) << 8 | (0xff & packetData[readPos++]));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static MultiTargetPNPResults createFromPacket(Packet packet) {
var results = PNPResults.createFromPacket(packet);
var ids = new ArrayList<Integer>(MAX_IDS);
for (int i = 0; i < MAX_IDS; i++) {
int targetId = (int) packet.decodeByte();
int targetId = (int) packet.decodeShort();
if (targetId > -1) ids.add(targetId);
}
return new MultiTargetPNPResults(results, ids);
Expand All @@ -51,9 +51,9 @@ public void populatePacket(Packet packet) {
estimatedPose.populatePacket(packet);
for (int i = 0; i < MAX_IDS; i++) {
if (i < fiducialIDsUsed.size()) {
packet.encode(fiducialIDsUsed.get(i).byteValue());
packet.encode((short) fiducialIDsUsed.get(i).byteValue());
} else {
packet.encode(-1);
packet.encode((short) -1);
}
}
}
Expand Down

0 comments on commit 5ee7fdf

Please sign in to comment.