internal

package
v0.0.0-...-07e9d76 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChunkSize32   uint16 = 32
	ChunkSize64   uint16 = 64
	ChunkSize128  uint16 = 128
	ChunkSize256  uint16 = 256
	ChunkSize512  uint16 = 512
	ChunkSize1024 uint16 = 1024
)

Variables

This section is empty.

Functions

func GetData

func GetData(chunks []*QRChunk) []byte

GetData generates a byte slice containing the data from the given slice of QRChunk pointers.

It takes a slice of pointers to QRChunk objects as a parameter. If the slice is empty, it returns nil. Otherwise, it creates a new byte slice with an initial capacity equal to the estimated data size of the first chunk. It then iterates over each chunk in the slice and appends its data to the data slice. Finally, it returns the generated data slice.

Parameters: - chunks: a slice of pointers to QRChunk objects.

Returns:

  • []byte: a byte slice containing the data from the QRChunk pointers, or nil if the input slice is empty.

func NewImageWriter

func NewImageWriter(callback func(image.Image), opt *Option) qrcode.Writer

NewImageWriter creates a new instance of the imgWriter struct and returns it as a qrcode.Writer.

The function takes two parameters:

  • callback: a function that takes an image.Image as input and does not return anything.
  • opt: a pointer to an Option struct.

The function returns a qrcode.Writer.

Types

type Option

type Option struct {
	Padding   int
	BlockSize int
}

type QRChunk

type QRChunk struct {
	// contains filtered or unexported fields
}

func CreateChunks

func CreateChunks(data []byte, chunkSize uint16) []*QRChunk

CreateChunks generates a slice of QRChunk pointers based on the given data and chunk size.

Parameters: - data: a byte slice containing the data to be split into chunks. - chunkSize: an unsigned 16-bit integer specifying the size of each chunk.

Returns: - []*QRChunk: a slice of pointers to QRChunk objects.

func NewChunk

func NewChunk(data []byte) *QRChunk

NewChunk creates a new QRChunk from the given byte slice.

The function takes a byte slice as input and extracts the necessary information to create a new QRChunk. It first extracts the values for nr and tot from the first two bytes of the input data. Then, it reads the chunk size from the next two bytes and checks if it is a valid chunk size using the isValidChunkSize function. If the chunk size is invalid, the function returns nil. Otherwise, it creates a new QRChunk with the extracted values and the remaining data.

Parameters:

  • data: a byte slice containing the data for the QRChunk.

Returns:

  • *QRChunk: a pointer to the newly created QRChunk, or nil if the chunk size is invalid.

func NewChunkFromImage

func NewChunkFromImage(img image.Image) (*QRChunk, error)

NewChunkFromImage decodes an image into a QRChunk.

It takes an image.Image as a parameter and attempts to decode it into a QRChunk. It first creates a BinaryBitmap from the image using the gozxing.NewBinaryBitmapFromImage function. Then it creates a QRCodeReader and uses it to decode the BinaryBitmap into a QRCodeData object. The QRCodeData object contains the text of the QR code, which is then decoded from base64 to bytes using the base64.StdEncoding.DecodeString function. Finally, it creates a new QRChunk using the NewChunk function and returns it along with any error that occurred during the decoding process. If the decoded chunk is invalid, it returns an error.

Parameters: - img: an image.Image to be decoded into a QRChunk.

Returns:

  • *QRChunk: the decoded QRChunk.
  • error: an error if there was an issue decoding the image or if the decoded chunk is invalid.

func (QRChunk) Data

func (c QRChunk) Data() []byte

Data returns the payload data

func (QRChunk) Nr

func (c QRChunk) Nr() uint8

Nr returns sequence number of this qr chunk.

func (QRChunk) QRCode

func (c QRChunk) QRCode(blockSize int) (img image.Image, err error)

QRCode generates a QR code image based on the data of the QRChunk.

It takes an integer parameter `blockSize` which represents the size of the blocks in the QR code. The function returns two values: `img` of type `image.Image` which is the generated QR code image, and `err` of type `error` which indicates any error that occurred during the generation process.

If the `blockSize` parameter is less than 1, the function returns an error indicating an invalid block size. The function then creates a new QR code using the `qrcode.New` function, passing the base64-encoded data of the QRChunk. If there is an error creating the QR code, the function returns the error. The function creates a new `ImageWriter` with a callback function that assigns the generated image to the `img` variable. The `ImageWriter` is configured with the `Padding` and `BlockSize` options set to the `blockSize` parameter. The function saves the QR code using the `qr.Save` method, passing the `ImageWriter` as the writer. If there is an error saving the QR code, the function returns the error. The function returns the generated image and any error that occurred during the process.

func (QRChunk) Size

func (c QRChunk) Size() uint16

Size returns the chunksize

func (QRChunk) Tot

func (c QRChunk) Tot() uint8

Tot returns the total number of qr chunks in this sequence.

Jump to

Keyboard shortcuts

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