Add Support for string and []byte Inputs in QRCode Constructors
#138
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey @yeqown,
I would like to propose this PR that updates the QRCode constructors to accept both
stringand[]byteinputs.While the library itself already supports handling data in byte-mode encoding (EncModeByte), the existing constructors required callers to pass a string, leading to unnecessary conversions when working with raw byte data.
The new constructors use a simple generic constraint
(~string | ~[]byte)in order to stay backwards-compatible with downstream consumers of this library and a helper function to normalize inputs to[]bytedata. Internally,buildnow operates solely on raw bytes. ThesourceTextfield appeared to be unused except for tests and thus has been removed in favor of thesourceRawBytesfield that is consumed everywhere in the code internally in order to avoid duplication.Test code has been updated accordingly, and a minor formatting change was made to the debugging logging I couldn't avoid because my code editor just kept reformatting that file, sorry for that.
Hope you like it!