Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: awslabs/aws-eventstream-java
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: tao1/aws-eventstream-java
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Feb 20, 2020

  1. No Java 8 API

    tao1 committed Feb 20, 2020
    Copy the full SHA
    fd7c39b View commit details
Showing with 13 additions and 5 deletions.
  1. +1 −1 pom.xml
  2. +5 −1 src/main/java/software/amazon/eventstream/Message.java
  3. +7 −3 src/main/java/software/amazon/eventstream/Prelude.java
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

<groupId>software.amazon.eventstream</groupId>
<artifactId>eventstream</artifactId>
<version>1.0.1</version>
<version>1.0.2-SNAPSHOT</version>

<name>AWS Event Stream</name>
<description>The AWS Event Stream decoder library.</description>
6 changes: 5 additions & 1 deletion src/main/java/software/amazon/eventstream/Message.java
Original file line number Diff line number Diff line change
@@ -108,14 +108,18 @@ private static void validateMessageCrc(ByteBuffer buf, int totalLength) {
Checksums.update(crc, (ByteBuffer) buf.duplicate().limit(buf.position() + totalLength - 4));
long computedMessageCrc = crc.getValue();

long wireMessageCrc = Integer.toUnsignedLong(buf.getInt(buf.position() + totalLength - 4));
long wireMessageCrc = toUnsignedLong(buf.getInt(buf.position() + totalLength - 4));

if (wireMessageCrc != computedMessageCrc) {
throw new IllegalArgumentException(format("Message checksum failure: expected 0x%x, computed 0x%x",
wireMessageCrc, computedMessageCrc));
}
}

public static long toUnsignedLong(int x) {
return (long)x & 4294967295L;
}

static Map<String, HeaderValue> decodeHeaders(ByteBuffer buf) {
Map<String, HeaderValue> headers = new LinkedHashMap<>();

10 changes: 7 additions & 3 deletions src/main/java/software/amazon/eventstream/Prelude.java
Original file line number Diff line number Diff line change
@@ -37,9 +37,9 @@ static Prelude decode(ByteBuffer buf) {

long computedPreludeCrc = computePreludeCrc(buf);

long totalLength = Integer.toUnsignedLong(buf.getInt());
long headersLength = Integer.toUnsignedLong(buf.getInt());
long wirePreludeCrc = Integer.toUnsignedLong(buf.getInt());
long totalLength = toUnsignedLong(buf.getInt());
long headersLength = toUnsignedLong(buf.getInt());
long wirePreludeCrc = toUnsignedLong(buf.getInt());
if (computedPreludeCrc != wirePreludeCrc) {
throw new IllegalArgumentException(format("Prelude checksum failure: expected 0x%x, computed 0x%x",
wirePreludeCrc, computedPreludeCrc));
@@ -58,6 +58,10 @@ static Prelude decode(ByteBuffer buf) {
return new Prelude(Math.toIntExact(totalLength), headersLength);
}

public static long toUnsignedLong(int x) {
return (long)x & 4294967295L;
}

private static long computePreludeCrc(ByteBuffer buf) {
byte[] prelude = new byte[Prelude.LENGTH];
buf.duplicate().get(prelude);