MCPcopy Index your code
hub / github.com/divan/txqr / Encode

Method Encode

encode.go:26–44  ·  view source on GitHub ↗

Encode encodes data from reader and splits it into chunks to be futher converted to QR code frames.

(str string)

Source from the content-addressed store, hash-verified

24// Encode encodes data from reader and splits it into chunks to be
25// futher converted to QR code frames.
26func (e *Encoder) Encode(str string) ([]string, error) {
27 if len(str) < e.chunkLen {
28 return []string{e.frame(0, len(str), []byte(str))}, nil
29 }
30
31 numChunks := numberOfChunks(len(str), e.chunkLen)
32 codec := fountain.NewLubyCodec(numChunks, rand.New(fountain.NewMersenneTwister(200)), solitonDistribution(numChunks))
33
34 var msg = []byte(str) // copy of str, as EncodeLTBlock is destructive to msg
35 idsToEncode := ids(int(float64(numChunks) * e.redundancyFactor))
36 lubyBlocks := fountain.EncodeLTBlocks(msg, idsToEncode, codec)
37
38 // TODO(divan): use sync.Pool as this probably will be used many times
39 ret := make([]string, len(lubyBlocks))
40 for i, block := range lubyBlocks {
41 ret[i] = e.frame(block.BlockCode, len(str), block.Data)
42 }
43 return ret, nil
44}
45
46// SetRedundancyFactor changes the value of redundancy factor.
47func (e *Encoder) SetRedundancyFactor(rf float64) {

Callers 10

TestTXQRFunction · 0.95
TestTXQRErasuresFunction · 0.95
BenchmarkTXQREncodeFunction · 0.95
BenchmarkTXQRDecodeFunction · 0.95
BenchmarkTXQRErasuresFunction · 0.95
AnimatedGifFunction · 0.80
mainFunction · 0.80
renderPNGFunction · 0.80
app.jsFile · 0.80
AnimatedGifFunction · 0.80

Calls 4

frameMethod · 0.95
numberOfChunksFunction · 0.85
solitonDistributionFunction · 0.85
idsFunction · 0.85

Tested by 5

TestTXQRFunction · 0.76
TestTXQRErasuresFunction · 0.76
BenchmarkTXQREncodeFunction · 0.76
BenchmarkTXQRDecodeFunction · 0.76
BenchmarkTXQRErasuresFunction · 0.76