Data Matrix encoder and matrix decoder with DMRE, ECI and structured append
git clone https://github.com/gywcs101/MoonDataMatrix.git
cd MoonDataMatrix
moon update
moon run examples/basic --target nativemoon work init
moon work use MoonDataMatrix myappimport { "gywcs101/MoonDataMatrix" @datamatrix }fn main raise {
let text = @datamatrix.encode_text("样本编号:LAB-2026-001")
println(@datamatrix.render_svg(text))
let binary = @datamatrix.encode_bytes(b"\x00\xff\x01")
println(binary.width())
}| 形状选项 | 行为 |
|---|---|
| Square | 自动选择方形,默认选项 |
| Rectangle | 自动选择经典矩形 |
| Any | 从全部 30 种经典尺寸中选择 |
| Dmre | 自动选择 18 种 DMRE 尺寸 |
| WithDmre | 从经典与 DMRE 共 48 种尺寸中选择 |
| Fixed(width, height) | 指定尺寸,例如 Fixed(18, 8) |
let symbol = @datamatrix.encode_message([
Text("中文", 29),
Text("日本語", 20),
Text("🙂", 32),
])
let decoded = @datamatrix.decode_matrix(symbol.matrix())
println(decoded.text()) // 中文日本語🙂| ECI | 字符集 |
|---|---|
| 2、3 | CP437、ISO-8859-1 |
| 4~13、15~18 | ISO-8859-2~11、13~16 |
| 20 | Shift JIS |
| 21~24 | Windows-1250、1251、1252、1256 |
| 25、26、27 | UTF-16 BE、UTF-8、ASCII |
| 28、29、30 | Big5、GB2312、EUC-KR |
| 31、32 | GBK、GB18030 |
| 33~35 | UTF-16 LE、UTF-32 BE、UTF-32 LE |
moon run cmd/main --target native -- encode --text "Hello, World!" --output hello.svg
moon run cmd/main --target native -- encode --text-file examples/sample-label.txt --output sample.svg
moon run cmd/main --target native -- encode --hex 00010203fffe807f --output binary.svg
moon run cmd/main --target native -- encode --binary-file payload.bin --output payload.svg
moon run cmd/main --target native -- batch --input examples/assets.jsonl --output asset-labels| 退出码 | 含义 |
|---|---|
| 0 | 成功 |
| 2 | 参数错误 |
| 3 | 输入或编码错误 |
| 4 | 文件读写错误 |
moon run cmd/main --target native -- encode --message-file examples/gs1-message.json --output gs1.svg
moon run cmd/main --target native -- message --input examples/multilingual-message.json --output symbols.json
moon run cmd/main --target native -- encode --text "中文🙂" --format json --output matrix.json
moon run cmd/main --target native -- decode --input matrix.json
moon run cmd/main --target native -- message --input examples/append-message.json --output parts.json
moon run cmd/main --target native -- assemble --input parts.json{"id":"asset-0001","text":"ASSET-2026-0001"}
{"id":"asset-0002","hex":"00ff01"}moon run cmd/main --target native -- batch --input examples/gs1-batch.jsonl --output gs1-labels
moon run cmd/main --target native -- assemble --input gs1-labels/batch-a.jsonmoon run cmd/main --target native -- encode --message-file examples/dmre-message.json --format json --output device.json
moon run cmd/main --target native -- assemble --input device.json
moon run cmd/main --target native -- message --input examples/mixed-append.json --output exchange.json
moon run cmd/main --target native -- assemble --input exchange.jsonpython scripts/build-web.py
python -m http.server --directory _build/site 8080pub suberror DecodeError {
InvalidMatrix(String)
UnsupportedMatrixSize
CorrectionFailed
InvalidCodeword(String)
InvalidText
} derive(Debug)pub struct DecodedMessage {
gs1 : Bool
macro_kind : Int
reader_programming : Bool
append : AppendHeader?
corrected_codewords : Int
// private fields
}pub(all) struct MessageOptions {
symbol : EncodeOptions
gs1 : Bool
macro_kind : Int
reader_programming : Bool
append : AppendHeader?
}fn MessageOptions::new(symbol? : EncodeOptions, gs1? : Bool, macro_kind? : Int, reader_programming? : Bool, append? : AppendHeader?) -> MessageOptionspub struct Symbol {
// private fields
}fn encode_append_bytes(data : Bytes, file_id1 : Int, file_id2 : Int, options? : EncodeOptions, eci? : Int?) -> Array[Symbol] raise EncodeErrorfn encode_append_message(segments : Array[MessageSegment], file_id1 : Int, file_id2 : Int, options? : MessageOptions) -> Array[Symbol] raise EncodeErrorfn encode_append_text(text : String, file_id1 : Int, file_id2 : Int, options? : EncodeOptions) -> Array[Symbol] raise EncodeErrorfn encode_message(segments : Array[MessageSegment], options? : MessageOptions) -> Symbol raise EncodeErrorInstall
Download zipData Matrix encoder and matrix decoder with DMRE, ECI and structured append