From 79796901ea8c81cc4dac9dc27f5b1efb1798f4de Mon Sep 17 00:00:00 2001
From: Project Nayuki The mid-level way to create a segment is to take the payload data and call a
+ * static factory function such as {@link QrSegment#makeNumeric(String)}. The low-level
+ * way to create a segment is to custom-make the bit buffer and call the {@link
+ * QrSegment#QrSegment(Mode,int,BitBuffer) constructor} with appropriate values. This segment class imposes no length restrictions, but QR Codes have restrictions.
* Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
- * Any segment longer than this is meaningless for the purpose of generating QR Codes.
Any text string can be converted to UTF-8 bytes ({@code + * s.getBytes(StandardCharsets.UTF_8)}) and encoded as a byte mode segment.
* @param data the binary data * @return a segment containing the data * @throws NullPointerException if the array is {@code null} @@ -171,7 +180,7 @@ public final class QrSegment { /*---- Constructor (low level) ----*/ /** - * Constructs a QR Code segment with the specified parameters and data. + * Constructs a QR Code segment with the specified attributes and data. * The character count (numCh) must agree with the mode and the bit buffer length, * but the constraint isn't checked. The specified bit buffer is cloned and stored. * @param md the mode, which is not {@code null} diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index e275cbd..c66dadf 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -695,12 +695,16 @@ var qrcodegen = new function() { /*---- Data segment class ----*/ /* - * Represents a segment of character data, binary data, or control data - * to be put into a QR Code symbol. Instances of this class are immutable. + * A segment of character/binary/control data in a QR Code symbol. + * Instances of this class are immutable. + * The mid-level way to create a segment is to take the payload data + * and call a static factory function such as QrSegment.makeNumeric(). + * The low-level way to create a segment is to custom-make the bit buffer + * and call the QrSegment() constructor with appropriate values. * This segment class imposes no length restrictions, but QR Codes have restrictions. * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. * Any segment longer than this is meaningless for the purpose of generating QR Codes. - * This constructor creates a QR Code segment with the given parameters and data. + * This constructor creates a QR Code segment with the given attributes and data. * The character count (numChars) must agree with the mode and the bit buffer length, * but the constraint isn't checked. The given bit buffer is cloned and stored. */ @@ -728,7 +732,9 @@ var qrcodegen = new function() { /*---- Static factory functions (mid level) for QrSegment ----*/ /* - * Returns a segment representing the given binary data encoded in byte mode. + * Returns a segment representing the given binary data encoded in + * byte mode. All input byte arrays are acceptable. Any text string + * can be converted to UTF-8 bytes and encoded as a byte mode segment. */ this.QrSegment.makeBytes = function(data) { var bb = new BitBuffer(); diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 55319cf..b1692d5 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -586,8 +586,12 @@ class QrCode(object): # ---- Data segment class ---- class QrSegment(object): - """Represents a segment of character data, binary data, or control data - to be put into a QR Code symbol. Instances of this class are immutable. + """A segment of character/binary/control data in a QR Code symbol. + Instances of this class are immutable. + The mid-level way to create a segment is to take the payload data + and call a static factory function such as QrSegment.make_numeric(). + The low-level way to create a segment is to custom-make the bit buffer + and call the QrSegment() constructor with appropriate values. This segment class imposes no length restrictions, but QR Codes have restrictions. Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. Any segment longer than this is meaningless for the purpose of generating QR Codes.""" @@ -596,7 +600,9 @@ class QrSegment(object): @staticmethod def make_bytes(data): - """Returns a segment representing the given binary data encoded in byte mode.""" + """Returns a segment representing the given binary data encoded in byte mode. + All input byte lists are acceptable. Any text string can be converted to + UTF-8 bytes (s.encode("UTF-8")) and encoded as a byte mode segment.""" py3 = sys.version_info.major >= 3 if (py3 and isinstance(data, str)) or (not py3 and isinstance(data, unicode)): raise TypeError("Byte string/list expected") @@ -680,7 +686,7 @@ class QrSegment(object): # ---- Constructor (low level) ---- def __init__(self, mode, numch, bitdata): - """Creates a new QR Code segment with the given parameters and data. + """Creates a new QR Code segment with the given attributes and data. The character count (numch) must agree with the mode and the bit buffer length, but the constraint isn't checked. The given bit buffer is cloned and stored.""" if not isinstance(mode, QrSegment.Mode): diff --git a/rust/src/lib.rs b/rust/src/lib.rs index de2fca8..a6f10d5 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -828,8 +828,17 @@ impl ReedSolomonGenerator { /*---- QrSegment functionality ----*/ -// Represents a segment of character data, binary data, or control data -// to be put into a QR Code symbol. Instances of this class are immutable. +/* + * A segment of character/binary/control data in a QR Code symbol. + * Instances of this struct are immutable. + * The mid-level way to create a segment is to take the payload data + * and call a static factory function such as QrSegment::make_numeric(). + * The low-level way to create a segment is to custom-make the bit buffer + * and call the QrSegment::new() constructor with appropriate values. + * This segment struct imposes no length restrictions, but QR Codes have restrictions. + * Even in the most favorable conditions, a QR Code can only hold 7089 characters of data. + * Any segment longer than this is meaningless for the purpose of generating QR Codes. + */ #[derive(Clone)] pub struct QrSegment { @@ -851,7 +860,9 @@ impl QrSegment { /*---- Static factory functions (mid level) ----*/ - // Returns a segment representing the given binary data encoded in byte mode. + // Returns a segment representing the given binary data encoded in + // byte mode. All input byte slices are acceptable. Any text string + // can be converted to UTF-8 bytes and encoded as a byte mode segment. pub fn make_bytes(data: &[u8]) -> Self { let mut bb = BitBuffer(Vec::with_capacity(data.len() * 8)); for b in data { @@ -948,7 +959,7 @@ impl QrSegment { /*---- Constructor (low level) ----*/ - // Creates a new QR Code segment with the given parameters and data. + // Creates a new QR Code segment with the given attributes and data. // The character count (numchars) must agree with the mode and // the bit buffer length, but the constraint isn't checked. pub fn new(mode: QrSegmentMode, numchars: usize, data: Vec