From 0dc17c9053c4956f07a6db58b2863924fe03b643 Mon Sep 17 00:00:00 2001 From: boombuler Date: Mon, 3 Apr 2017 20:34:37 +0200 Subject: [PATCH] added EncodeWithoutChecksum for code 128 as mentioned in #16 --- code128/encode.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/code128/encode.go b/code128/encode.go index 24981b7..c058d71 100644 --- a/code128/encode.go +++ b/code128/encode.go @@ -182,3 +182,22 @@ func Encode(content string) (barcode.BarcodeIntCS, error) { result.AddBit(encodingTable[stopSymbol]...) return utils.New1DCodeIntCheckSum("Code 128", content, result, sum), nil } + +func EncodeWithoutChecksum(content string) (barcode.Barcode, error) { + contentRunes := strToRunes(content) + if len(contentRunes) <= 0 || len(contentRunes) > 80 { + return nil, fmt.Errorf("content length should be between 1 and 80 runes but got %d", len(contentRunes)) + } + idxList := getCodeIndexList(contentRunes) + + if idxList == nil { + return nil, fmt.Errorf("\"%s\" could not be encoded", content) + } + + result := new(utils.BitList) + for _, idx := range idxList.GetBytes() { + result.AddBit(encodingTable[idx]...) + } + result.AddBit(encodingTable[stopSymbol]...) + return utils.New1DCode("Code 128", content, result), nil +}