From 5bf90d1008a7d40558740a7c863d7094b423424a Mon Sep 17 00:00:00 2001 From: Manuel Amago Date: Sun, 8 Sep 2019 15:12:16 +0100 Subject: Convert to write to a "shared ring buffer". First steps, not actually fully functional yet (i.e. ring buffer is not actually a ring buffer, and there is no log printer polling the other side). --- src/main/java/org/mamago/util/Bits.java | 16 ++++++++++++++++ src/main/java/org/mamago/util/Cast.java | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/main/java/org/mamago/util/Bits.java create mode 100644 src/main/java/org/mamago/util/Cast.java (limited to 'src/main/java/org/mamago/util') diff --git a/src/main/java/org/mamago/util/Bits.java b/src/main/java/org/mamago/util/Bits.java new file mode 100644 index 0000000..4672ea9 --- /dev/null +++ b/src/main/java/org/mamago/util/Bits.java @@ -0,0 +1,16 @@ +package org.mamago.util; + +public class Bits { + // Prevent instantiation + private Bits() {} + + public static int roundUpToLongSize(int size) { + return roundUpToSize(size, 8); + } + + public static int roundUpToSize(int size, int width) { + // Formula: + // (size + w) / w * w; // Adding w rounds up to the next whole width + return ((size + width) / width) * width; + } +} diff --git a/src/main/java/org/mamago/util/Cast.java b/src/main/java/org/mamago/util/Cast.java new file mode 100644 index 0000000..4ed3d47 --- /dev/null +++ b/src/main/java/org/mamago/util/Cast.java @@ -0,0 +1,16 @@ +package org.mamago.util; + +public class Cast { + // Prevent instantiation + private Cast() {} + + public static byte asByte(int i) { + // @Fixme[MA]: check whether casting give out-of-bounds check, otherwise add in for safety + return (byte) i; + } + + public static short asShort(int i) { + // @Fixme[MA]: check whether casting give out-of-bounds check, otherwise add in for safety + return (byte) i; + } +} -- cgit v1.2.1