示例#1
0
文件: qr.go 项目: mdp/rsc
func (b *Bits) AddCheckBytes(v Version, l Level) {
	nd := v.DataBytes(l)
	if b.nbit < nd*8 {
		b.Pad(nd*8 - b.nbit)
	}
	if b.nbit != nd*8 {
		panic("qr: too much data")
	}

	dat := b.Bytes()
	vt := &vtab[v]
	lev := &vt.level[l]
	db := nd / lev.nblock
	extra := nd % lev.nblock
	chk := make([]byte, lev.check)
	rs := gf256.NewRSEncoder(Field, lev.check)
	for i := 0; i < lev.nblock; i++ {
		if i == lev.nblock-extra {
			db++
		}
		rs.ECC(dat[:db], chk)
		b.Append(chk)
		dat = dat[db:]
	}

	if len(b.Bytes()) != vt.bytes {
		panic("qr: internal error")
	}
}
示例#2
0
文件: qr_test.go 项目: mdp/rsc
func TestEncode(t *testing.T) {
	data := []byte{0x10, 0x20, 0x0c, 0x56, 0x61, 0x80, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11, 0xec, 0x11}
	check := []byte{0xa5, 0x24, 0xd4, 0xc1, 0xed, 0x36, 0xc7, 0x87, 0x2c, 0x55}
	rs := gf256.NewRSEncoder(Field, len(check))
	out := make([]byte, len(check))
	rs.ECC(data, out)
	if !bytes.Equal(out, check) {
		t.Errorf("have %x want %x", out, check)
	}
}