moved checksum function to its own interface
its not needed that all barcodes have an integer checksum so it should not be needed in every implementation.
This commit is contained in:
1 parent
fe0f26ff6d
commit
b066487b3e
11 files changed
+57
-34
No files matched your search
+4
-3
@@ -103,7 +103,7 @@ func getCodeIndexList(content []rune) *utils.BitList {
|
||||
}
|
||||
|
||||
// Encode creates a Code 128 barcode for the given content
|
||||
func Encode(content string) (barcode.Barcode, error) {
|
||||
func Encode(content string) (barcode.BarcodeIntCS, 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))
|
||||
@@ -124,7 +124,8 @@ func Encode(content string) (barcode.Barcode, error) {
|
||||
}
|
||||
result.AddBit(encodingTable[idx]...)
|
||||
}
|
||||
result.AddBit(encodingTable[sum%103]...)
|
||||
sum = sum % 103
|
||||
result.AddBit(encodingTable[sum]...)
|
||||
result.AddBit(encodingTable[stopSymbol]...)
|
||||
return utils.New1DCode("Code 128", content, result, sum%103), nil
|
||||
return utils.New1DCodeIntCheckSum("Code 128", content, result, sum), nil
|
||||
}
|
||||
Reference in new issue
Block a user