-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Improvements to encoding ranges (int vs long) (#439)
Integers were still used in a lot of places when dealing with Offsets. This moves everything to use Long, and do exact casts and arithmetic when encoding into integers or shorts or bytes, for the encoders that do so.
- Loading branch information
Showing
23 changed files
with
419 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
parallel-consumer-core/src/main/java/io/confluent/csid/utils/MathUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.confluent.csid.utils; | ||
|
||
/*- | ||
* Copyright (C) 2020-2022 Confluent, Inc. | ||
*/ | ||
|
||
import lombok.experimental.UtilityClass; | ||
|
||
/** | ||
* @author Antony Stubbs | ||
*/ | ||
@UtilityClass | ||
public class MathUtils { | ||
|
||
/** | ||
* Ensures exact conversion from a Long to a Short. | ||
* <p> | ||
* {@link Math} doesn't have an exact conversion from Long to Short. | ||
* | ||
* @see Math#toIntExact | ||
*/ | ||
public static short toShortExact(long value) { | ||
final short shortCast = (short) value; | ||
if (shortCast != value) { | ||
throw new ArithmeticException("short overflow"); | ||
} | ||
return shortCast; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.