qr

package
v1.85.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package qr encodes bytes as a QR code symbol: the modules, not an image, so that whatever draws it -- an SVG path, a terminal, a PNG -- decides how.

It writes byte mode only, versions 1 to MaxVersion, at any of the four error correction levels, and chooses the mask the standard's penalty rules prefer. That covers what it was written for, a BankID payload of about a hundred bytes, and anything else of that size; it refuses rather than truncates what does not fit.

The module layout follows ISO/IEC 18004. The tests hold it to libqrencode's output for the same data, level and mask, module for module.

Index

Constants

View Source
const MaxVersion = 10

MaxVersion is the largest symbol this package draws: 57 modules a side, enough for 213 bytes at LevelM and well past a BankID payload's 108. The larger versions differ only in their tables, which are left out until something needs them.

Variables

View Source
var ErrDataTooLong = errors.New("data too long")

ErrDataTooLong is returned for data that no version up to MaxVersion holds at the level asked for.

Functions

This section is empty.

Types

type Code

type Code struct {
	Version int
	Level   Level
	// Mask is the mask pattern applied, 0 to 7.
	Mask int
	// Size is the number of modules a side.
	Size int
	// contains filtered or unexported fields
}

Code is an encoded symbol.

func Encode

func Encode(data []byte, level Level) (*Code, error)

Encode encodes data in the smallest version that holds it at the level.

func (*Code) Dark

func (code *Code) Dark(x int, y int) bool

Dark says whether the module at column x and row y is dark. Anything outside the symbol is light, as the quiet zone around it is.

func (*Code) Rows

func (code *Code) Rows() []string

Rows renders the symbol as one string a row, '#' for a dark module and '.' for a light one, without a quiet zone.

type Level

type Level int

Level is how much of a symbol may be damaged and still read: about 7, 15, 25 and 30 percent for L, M, Q and H, at the cost of room for data.

const (
	LevelL Level = iota
	LevelM
	LevelQ
	LevelH
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL