Skip to content

Report the Code39 checksum value - #99

Merged
danielwhite merged 2 commits into
boombuler:masterfrom
SashaMIT:codered-code39-checksum
Oct 13, 2026
Merged

danielwhite merged 2 commits into
boombuler:masterfrom
SashaMIT:codered-code39-checksum

Conversation

@SashaMIT

Copy link
Copy Markdown
Contributor

Summary

CheckSum parsed the mod-43 character with strconv.ParseInt. Digits survived. A letter or symbol failed the parse and was stored as 0.

Encode("A") reported checksum 0. A is value 10. Encode("1") still reports 1. The bars are unchanged.

Test plan

  • On master, Test_ChecksumValue fails: Encode("A") checksum is 0
  • After the lookup, go test ./code39/ passes

Made with Cursor

Encode("A") reported checksum 0. The mod-43 value of A is 10.
@danielwhite
danielwhite self-requested a review October 10, 2026 05:11

@danielwhite danielwhite left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SashaMIT, thanks for the spot. If you can simplify this for clarity, I think this is good to ship.

Comment thread code39/encoder.go Outdated
Comment on lines +146 to +150
checkSum := 0
if cs := []rune(getChecksum(content)); len(cs) == 1 {
if info, ok := encodeTable[cs[0]]; ok && info.value >= 0 {
checkSum = info.value
}

@danielwhite danielwhite Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with a minor change to have getChecksum return a rune, it would eliminate the conditional checks and avoid computing the checksum twice.

For example:

checkChar := getChecksum(content)
if includeChecksum {
	data += string(checkChar)
 }

[ ... ]

checkSum := encodeTable[checkChar].value
return utils.New1DCodeIntCheckSumWithColor(..., checkSum, color), nil

The encoder looked the character up twice and parsed it back to a value.
@SashaMIT

Copy link
Copy Markdown
Contributor Author

Thanks for the review. getChecksum now returns the rune, and the encoder reads that value from the table once.

@danielwhite danielwhite left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks!

@danielwhite
danielwhite merged commit c4ca3f4 into boombuler:master Oct 13, 2026
3 checks passed
@SashaMIT

Copy link
Copy Markdown
Contributor Author

Thanks for merging this. Glad the rune return was the right shape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants