Crate code128

Source
Expand description

This crate implements encoding and decoding of Code 128 linear barcodes as defined in ISO/IEC 15417:2007.

To achieve a minimal encoding size a dynamic programming approach is used. The full 256 bit range can be encoded. For compatibility it is recommended to stay within printable ASCII though.

§Example

use code128::{Code128, bars_to_blocks};

let code = Code128::encode(b"Hello!");
println!("{}", bars_to_blocks(code.bars()));

To create other outputs check out the Code128 documentation.

§Charsets

For best compatibility it is recommended to only encode printable ASCII characters, i.e. 0x20 (space) to 0x7E (tilde).

Code 128 interprets the range 0x00 to 0x7F as ASCII, and 0xA0 to 0xFF as ISO/IEC 8859-1 (Latin 1). The remaining range from 0x80 to 0x9F can also be encoded but has no visual representation.

In the real world most implementations only handle 0x00 to 0x7F, or interpret results as UTF-8, although that is not covered by the standard. However, if you are in control of encoding and decoding this is technically possible and maybe even a contemporary choice.

Structs§

Bar
Representation of a “black line” in the code.
BarCoordinate
A coordinate of a bar in a barcode.
Code128
A Code 128.

Enums§

DecodingError
Errors that can occur during decoding.

Functions§

bars_to_blocks
Create a string representation of the bars using Unicode block characters.
decode
Decode a sequence of bars.
decode_str
Decode the bars and interpret the data as Latin 1.