From 886c24cdfd173d05701f97ff07ca7419f5caf070 Mon Sep 17 00:00:00 2001 From: Collin Smith Date: Fri, 14 Aug 2020 00:08:07 -0700 Subject: [PATCH] Improved API writing 0 bits with _writeUnsigned is a no-op write unsigned methods changed from byte and short to int types added writeString(CharSequence,int,boolean) to write an optional null char --- core/src/com/riiablo/io/BitOutput.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/com/riiablo/io/BitOutput.java b/core/src/com/riiablo/io/BitOutput.java index f1f9c13d..60060018 100644 --- a/core/src/com/riiablo/io/BitOutput.java +++ b/core/src/com/riiablo/io/BitOutput.java @@ -91,7 +91,7 @@ public class BitOutput { void _writeUnsigned(long value, int bits) { assert bits >= 0 : "bits(" + bits + ") < " + 0; assert bits < Long.SIZE : "bits(" + bits + ") > " + (Long.SIZE - 1); - assert (value & ~MASKS[bits]) == 0 : "value(" + value + ") is larger than bits(" + bits + ")"; + assert bits == 0 || (value & ~MASKS[bits]) == 0 : "value(" + value + ") is larger than bits(" + bits + ")"; _writeRaw(value, bits); } @@ -139,13 +139,13 @@ public class BitOutput { return this; } - public BitOutput write7u(byte value, int bits) { + public BitOutput write7u(int value, int bits) { BitConstraints.validate7u(bits); _writeUnsigned(value, bits); return this; } - public BitOutput write15u(short value, int bits) { + public BitOutput write15u(int value, int bits) { BitConstraints.validate15u(bits); _writeUnsigned(value, bits); return this; @@ -217,6 +217,10 @@ public class BitOutput { } public BitOutput writeString(CharSequence chars, int bits) { + return writeString(chars, bits, false); + } + + public BitOutput writeString(CharSequence chars, int bits, boolean nullTerminated) { BitConstraints.validateAscii(bits); final int length = chars.length(); @@ -226,6 +230,7 @@ public class BitOutput { _writeRaw(c, bits); } + if (nullTerminated) _writeRaw('\0', bits); return this; } }