Decode takes a single chunk of data and decodes it.
(data string)
| 29 | |
| 30 | // Decode takes a single chunk of data and decodes it. |
| 31 | func (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. |
| 65 | func (d *Decoder) Speed() string { |