mirror of
https://github.com/status-im/QR-Code-generator.git
synced 2026-08-31 01:31:10 +00:00
Inlined BitBuffer.getBytes() into its single usage (with simplification because the bit length is a multiple of 8) in most language versions, synchronized comment and variable name in Rust version.
This commit is contained in:
@@ -77,21 +77,6 @@ public final class BitBuffer implements Cloneable {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
for (int i = 0; i < bitLength; i++) {
|
||||
if (data.get(i))
|
||||
result[i >>> 3] |= 1 << (7 - (i & 7));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Appends the specified number of low-order bits of the specified value to this
|
||||
* buffer. Requires 0 ≤ len ≤ 31 and 0 ≤ val < 2<sup>len</sup>.
|
||||
|
||||
@@ -184,8 +184,13 @@ public final class QrCode {
|
||||
for (int padByte = 0xEC; bb.bitLength() < dataCapacityBits; padByte ^= 0xEC ^ 0x11)
|
||||
bb.appendBits(padByte, 8);
|
||||
|
||||
// Pack bits into bytes in big endian
|
||||
byte[] dataCodewords = new byte[bb.bitLength() / 8];
|
||||
for (int i = 0; i < bb.bitLength(); i++)
|
||||
dataCodewords[i >>> 3] |= bb.getBit(i) << (7 - (i & 7));
|
||||
|
||||
// Create the QR Code object
|
||||
return new QrCode(version, ecl, bb.getBytes(), mask);
|
||||
return new QrCode(version, ecl, dataCodewords, mask);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user