MCPcopy Create free account
hub / github.com/divan/txqr / Decode

Method Decode

mobile/decode.go:31–62  ·  view source on GitHub ↗

Decode takes a single chunk of data and decodes it.

(data string)

Source from the content-addressed store, hash-verified

29
30// Decode takes a single chunk of data and decodes it.
31func (d *Decoder) Decode(data string) error {
32 // mobile app can still try to decode any detected QR codes,
33 // so we're ignoring them here
34 if d.IsCompleted() {
35 return nil
36 }
37
38 if err := d.Validate(data); err != nil {
39 return err
40 }
41
42 // mark start of first txqr frame
43 if d.start.IsZero() {
44 d.start = time.Now()
45 }
46
47 // mark last chunk timestamp
48 if !d.lastChunk.IsZero() {
49 d.readInterval = time.Now().Sub(d.lastChunk)
50 }
51 d.lastChunk = time.Now()
52
53 // decode
54 err := d.Decoder.Decode(data)
55 if err != nil {
56 return err
57 }
58
59 d.updateProgress()
60
61 return nil
62}
63
64// Speed returns avg reading speed.
65func (d *Decoder) Speed() string {

Callers 3

TestDecodeFunction · 0.95
TestInvalidDecodeFunction · 0.95
TestProgressFunction · 0.95

Calls 3

IsCompletedMethod · 0.95
ValidateMethod · 0.95
updateProgressMethod · 0.95

Tested by 3

TestDecodeFunction · 0.76
TestInvalidDecodeFunction · 0.76
TestProgressFunction · 0.76