MCPcopy
hub / github.com/skip2/go-qrcode / addPadding

Method addPadding

qrcode.go:525–552  ·  view source on GitHub ↗

addPadding pads the encoded data upto the full length required.

()

Source from the content-addressed store, hash-verified

523
524// addPadding pads the encoded data upto the full length required.
525func (q *QRCode) addPadding() {
526 numDataBits := q.version.numDataBits()
527
528 if q.data.Len() == numDataBits {
529 return
530 }
531
532 // Pad to the nearest codeword boundary.
533 q.data.AppendNumBools(q.version.numBitsToPadToCodeword(q.data.Len()), false)
534
535 // Pad codewords 0b11101100 and 0b00010001.
536 padding := [2]*bitset.Bitset{
537 bitset.New(true, true, true, false, true, true, false, false),
538 bitset.New(false, false, false, true, false, false, false, true),
539 }
540
541 // Insert pad codewords alternately.
542 i := 0
543 for numDataBits-q.data.Len() >= 8 {
544 q.data.Append(padding[i])
545
546 i = 1 - i // Alternate between 0 and 1.
547 }
548
549 if q.data.Len() != numDataBits {
550 log.Panicf("BUG: got len %d, expected %d", q.data.Len(), numDataBits)
551 }
552}
553
554// ToString produces a multi-line string that forms a QR-code image.
555func (q *QRCode) ToString(inverseColor bool) string {

Callers 1

encodeMethod · 0.95

Calls 6

NewFunction · 0.92
numDataBitsMethod · 0.80
LenMethod · 0.80
AppendNumBoolsMethod · 0.80
AppendMethod · 0.80

Tested by

no test coverage detected