encode

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CP437             = 0 // also have a value of 2
	ISO8859_1         = 1 // also have a value of 3
	ISO8859_2         = 4
	ISO8859_3         = 5
	ISO8859_4         = 6
	ISO8859_5         = 7
	ISO8859_6         = 8
	ISO8859_7         = 9
	ISO8859_8         = 10
	ISO8859_9         = 11
	ISO8859_10        = 12
	ISO8859_11        = 13 // ISO8859-11, but Windows-874 is a superset
	REVERSED_14       = 14 // does not support
	ISO8859_13        = 15
	ISO8859_14        = 16
	ISO8859_15        = 17
	ISO8859_16        = 18
	REVERSED_19       = 19 // does not support
	ShiftJIS          = 20
	Windows1250       = 21
	Windows1251       = 22
	Windows1252       = 23
	Windows1256       = 24
	UTF16BigEndian    = 25
	UTF8              = 26
	ASCII             = 27
	Big5              = 28
	GBT2312           = 29
	KSX1001           = 30
	GBK               = 31
	GB18030           = 32
	UTF16LittleEndian = 33
	UTF32BigEndian    = 34
	UTF32LittleEndian = 35
)

Variables

View Source
var ErrCannotDeterminEncodingMode = errors.New("cannot determine encoding mode")
View Source
var ErrCannotEncodeToAlphaNumeric = errors.New("cannot encode to alphanumeric")
View Source
var ErrUnknownAssignmentNumber = fmt.Errorf("unknown assignment number")
View Source
var ErrUnknownEncodingMode = errors.New("unknown encoding mode")
View Source
var ErrVersionDoesNotSupportEncodingMode = errors.New("version does not support encoding mode")

Functions

func GenerateData

func GenerateData(queue chan ValueBlock, result chan []byte)

GenerateData is a helper function to pack a sequence of ValueBlocks into a byte array.

Types

type EncodeBlock

type EncodeBlock struct {
	Mode EncodingMode
	Data string

	// Only for ECI mode
	SubMode          EncodingMode
	AssignmentNumber uint
}

EncodeBlock is a block of data for encoding, representing a part (or whole) of the content.

func (*EncodeBlock) CalculateDataBitsCount

func (b *EncodeBlock) CalculateDataBitsCount() (int, error)

CalculateDataBitsCount returns the number of data bits for the block.

func (*EncodeBlock) Encode

func (b *EncodeBlock) Encode(version int, queue chan ValueBlock) (int, error)

Encode encodes the block data to bytes.

func (*EncodeBlock) EncodeData

func (b *EncodeBlock) EncodeData(queue chan ValueBlock) error

EncodeData transforms the content to the byte array according to the encoding mode.

func (*EncodeBlock) GetBytesPrefix

func (b *EncodeBlock) GetBytesPrefix(
	version,
	lengthBits,
	itemsCount int,
	queue chan ValueBlock,
)

GetBytesPrefix returns the prefix of the block in bytes. The prefix consists of the mode and the count of items.

func (*EncodeBlock) GetLengthBits

func (b *EncodeBlock) GetLengthBits(version int) (int, error)

GetLengthBits returns the number of length bits for the block.

func (*EncodeBlock) GetModeBits

func (b *EncodeBlock) GetModeBits(version int) int

GetModeBits returns the number of mode bits for the block.

func (*EncodeBlock) GetSymbolsCount

func (b *EncodeBlock) GetSymbolsCount() int

GetSymbolsCount returns the number of symbols in the block. The number of symbols is the number of characters for all modes except ECI (it's the number of bytes).

type EncodingMode

type EncodingMode int

EncodingMode is a type for encoding mode (numeric, alphanumeric, etc).

const (
	EncodingModeNumeric      EncodingMode = 1
	EncodingModeAlphaNumeric EncodingMode = 2
	EncodingModeByte         EncodingMode = 4
	EncodingModeKanji        EncodingMode = 8
	EncodingModeECI          EncodingMode = 7
)

func GetEncodingMode

func GetEncodingMode(s string) (EncodingMode, error)

GetEncodingMode returns the encoding mode for the given string.

type ErrVersionInvalid

type ErrVersionInvalid struct {
	Version int
}

func (ErrVersionInvalid) Error

func (e ErrVersionInvalid) Error() string

type QREncoder

type QREncoder interface {
	// Mode returns the encoding mode.
	Mode() EncodingMode

	// Encode encodes the string to the byte array.
	Encode(s string, queue chan ValueBlock) error

	// CanEncode returns true if the string can be encoded with the encoder.
	CanEncode(content string) bool

	// Size returns the number of bits for the string.
	Size(content string) int
}

QREncoder is an interface for all encoders.

type ValueBlock

type ValueBlock struct {
	Value int
	Bits  int
}

ValueBlock is a block of data with a number of bits.

Jump to

Keyboard shortcuts

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