diff --git a/c/qrcodegen.c b/c/qrcodegen.c index f197442..de13309 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -176,8 +176,8 @@ bool qrcodegen_encodeBinary(uint8_t dataAndTemp[], size_t dataLen, uint8_t qrcod } -// Appends the given sequence of bits to the given byte-based bit buffer, increasing the bit length. -// Requires 0 <= numBits <= 16 and 0 <= val < 2^numBits. +// Appends the given number of low-order bits of the given value to the given byte-based +// bit buffer, increasing the bit length. Requires 0 <= numBits <= 16 and val < 2^numBits. testable void appendBitsToBuffer(unsigned int val, int numBits, uint8_t buffer[], int *bitLen) { assert(0 <= numBits && numBits <= 16 && (unsigned long)val >> numBits == 0); for (int i = numBits - 1; i >= 0; i--, (*bitLen)++) diff --git a/cpp/BitBuffer.hpp b/cpp/BitBuffer.hpp index cd31bb4..bccabf1 100644 --- a/cpp/BitBuffer.hpp +++ b/cpp/BitBuffer.hpp @@ -30,7 +30,7 @@ namespace qrcodegen { /* - * An appendable sequence of bits (0s and 1s). + * An appendable sequence of bits (0s and 1s). Mainly used by QrSegment. */ class BitBuffer final : public std::vector { @@ -43,13 +43,13 @@ class BitBuffer final : public std::vector { /*---- Methods ----*/ - // Packs this buffer's bits into bytes in big endian, - // padding with '0' bit values, and returns the new vector. + // Returns a vector representing this buffer's bits packed into bytes in big endian. If the + // bit length isn't a multiple of 8, then the remaining bits of the final byte are all '0'. public: std::vector getBytes() const; - // Appends the given number of low bits of the given value to - // this sequence. Requires 0 <= len <= 31 and 0 <= val < 2^len. + // Appends the given number of low-order bits of the given value + // to this buffer. Requires 0 <= len <= 31 and val < 2^len. public: void appendBits(std::uint32_t val, int len); }; diff --git a/java/io/nayuki/qrcodegen/BitBuffer.java b/java/io/nayuki/qrcodegen/BitBuffer.java index f0f7ecb..4ede5cd 100644 --- a/java/io/nayuki/qrcodegen/BitBuffer.java +++ b/java/io/nayuki/qrcodegen/BitBuffer.java @@ -28,7 +28,7 @@ import java.util.Objects; /** - * An appendable sequence of bits (0s and 1s). + * An appendable sequence of bits (0s and 1s). Mainly used by {@link QrSegment}. */ public final class BitBuffer implements Cloneable { @@ -78,9 +78,9 @@ public final class BitBuffer implements Cloneable { /** - * Packs this buffer's bits into bytes in big endian, - * padding with '0' bit values, and returns the new array. - * @return this sequence as a new array of bytes (not {@code null}) + * Returns an array representing this buffer's bits packed into bytes in big endian. If the + * bit length isn't a multiple of 8, then the remaining bits of the final byte are all '0'. + * @return a new byte array (not {@code null}) representing this bit sequence */ public byte[] getBytes() { byte[] result = new byte[(bitLength + 7) >>> 3]; // Round up to whole byte, won't overflow @@ -93,10 +93,10 @@ public final class BitBuffer implements Cloneable { /** - * Appends the specified number of low bits of the specified value to this - * sequence. Requires 0 ≤ len ≤ 31 and 0 ≤ val < 2len. + * Appends the specified number of low-order bits of the specified value to this + * buffer. Requires 0 ≤ len ≤ 31 and 0 ≤ val < 2len. * @param val the value to append - * @param len the number of low bits in the value to take + * @param len the number of low-order bits in the value to take * @throws IllegalArgumentException if the value or number of bits is out of range * @throws IllegalStateException if appending the data * would make bitLength exceed Integer.MAX_VALUE @@ -112,7 +112,7 @@ public final class BitBuffer implements Cloneable { /** - * Appends the specified bit buffer to this bit buffer. + * Appends the content of the specified bit buffer to this buffer. * @param bb the bit buffer whose data to append (not {@code null}) * @throws NullPointerException if the bit buffer is {@code null} * @throws IllegalStateException if appending the data @@ -128,8 +128,8 @@ public final class BitBuffer implements Cloneable { /** - * Returns a copy of this bit buffer object. - * @return a copy of this bit buffer object + * Returns a new copy of this buffer. + * @return a new copy of this buffer (not {@code null}) */ public BitBuffer clone() { try { diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index b3010e3..db6a72c 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -962,13 +962,13 @@ var qrcodegen = new function() { /* * A private helper class that represents an appendable sequence of bits (0s and 1s). - * This constructor creates an empty bit buffer (length 0). + * Mainly used by QrSegment. This constructor creates an empty bit buffer (length 0). */ function BitBuffer() { Array.call(this); - // Packs this buffer's bits into bytes in big endian, - // padding with '0' bit values, and returns the new array. + // Returns a new array representing this buffer's bits packed into bytes in big endian. If the + // bit length isn't a multiple of 8, then the remaining bits of the final byte are all '0'. this.getBytes = function() { var result = []; while (result.length * 8 < this.length) @@ -979,8 +979,8 @@ var qrcodegen = new function() { return result; }; - // Appends the given number of low bits of the given value to - // this sequence. Requires 0 <= len <= 31 and 0 <= val < 2^len. + // Appends the given number of low-order bits of the given value + // to this buffer. Requires 0 <= len <= 31 and 0 <= val < 2^len. this.appendBits = function(val, len) { if (len < 0 || len > 31 || val >>> len != 0) throw "Value out of range"; diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 748072b..3ab89db 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -829,19 +829,19 @@ class _ReedSolomonGenerator(object): class _BitBuffer(list): - """An appendable sequence of bits (0s and 1s).""" + """An appendable sequence of bits (0s and 1s). Mainly used by QrSegment.""" def get_bytes(self): - """Packs this buffer's bits into bytes in big endian, - padding with '0' bit values, and returns the new list.""" + """Returns a new list representing this buffer's bits packed into bytes in big endian. If the + bit length isn't a multiple of 8, then the remaining bits of the final byte are all '0'.""" result = [0] * ((len(self) + 7) // 8) for (i, bit) in enumerate(self): result[i >> 3] |= bit << (7 - (i & 7)) return result def append_bits(self, val, n): - """Appends the given number of low bits of the given value - to this sequence. Requires n >= 0 and 0 <= val < 2^n.""" + """Appends the given number of low-order bits of the given + value to this buffer. Requires n >= 0 and 0 <= val < 2^n.""" if n < 0 or val >> n != 0: raise ValueError("Value out of range") self.extend(((val >> i) & 1) for i in reversed(range(n))) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index baa0ac9..3cf2bcd 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1070,13 +1070,13 @@ impl QrSegmentMode { /*---- Bit buffer functionality ----*/ -// An appendable sequence of bits (0s and 1s). +// An appendable sequence of bits (0s and 1s). Mainly used by QrSegment. pub struct BitBuffer(pub Vec); impl BitBuffer { - // Appends the given number of low bits of the given value - // to this sequence. Requires len <= 31 and 0 <= val < 2^len. + // Appends the given number of low-order bits of the given value + // to this buffer. Requires len <= 31 and val < 2^len. pub fn append_bits(&mut self, val: u32, len: u8) { assert!(len <= 31 && (val >> len) == 0, "Value out of range"); self.0.extend((0 .. len as i32).rev().map(|i| get_bit(val, i))); // Append bit by bit diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index 82a42e6..46d0222 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -890,12 +890,13 @@ namespace qrcodegen { /* - * An appendable sequence of bits (0s and 1s). The implicit constructor creates an empty bit buffer (length 0). + * An appendable sequence of bits (0s and 1s). Mainly used by QrSegment. + * The implicit constructor creates an empty bit buffer (length 0). */ class BitBuffer extends Array { - // Packs this buffer's bits into bytes in big endian, - // padding with '0' bit values, and returns the new array. + // Returns a new array representing this buffer's bits packed into bytes in big endian. If the + // bit length isn't a multiple of 8, then the remaining bits of the final byte are all '0'. public getBytes(): Array { let result: Array = []; while (result.length * 8 < this.length) @@ -906,8 +907,8 @@ namespace qrcodegen { } - // Appends the given number of low bits of the given value to - // this sequence. Requires 0 <= len <= 31 and 0 <= val < 2^len. + // Appends the given number of low-order bits of the given value + // to this buffer. Requires 0 <= len <= 31 and 0 <= val < 2^len. public appendBits(val: int, len: int): void { if (len < 0 || len > 31 || val >>> len != 0) throw "Value out of range";