Пример #1
0
func (x *Imp) Encode() []byte {
	//
	b := make([]byte, x.Codelen())
	i, a := uint(0), uint(4)
	copy(b[i:i+a], Encode(x.num))
	i += a
	for k := uint(0); k < x.num; k++ {
		a = uint(4)
		n := uint(len(x.mask[k]))
		copy(b[i:i+a], Encode(n))
		i += a
		a = uint(n)
		copy(b[i:i+a], []byte(x.mask[k]))
		i += a
		a = uint(4)
		n = x.l[k] + 256*x.c[k]
		copy(b[i:i+a], Encode(n))
		i += a
		a = col.Codelen()
		copy(b[i:i+a], Encode(x.cF))
		i += a
		copy(b[i:i+a], Encode(x.cB))
		i += a
	}
	return b
}
Пример #2
0
func (x *Imp) Codelen() uint { // TODO cF, cB
	//
	c := uint(4)
	for k := uint(0); k < x.num; k++ {
		c += 4
		c += uint(len(x.mask[k]))
		c += 4
		c += 2 * col.Codelen()
	}
	return c
}
Пример #3
0
func (x *Imp) Decode(b []byte) {
	//
	x.class = Class(b[0])
	i, a := uint(1), cluint
	x.number = Decode(uint(0), b[i:i+a]).(uint)
	i += a
	a = col.Codelen()
	col.Decode(&x.colour, b[i:i+a])
	i += a
	a = x.vect.Codelen()
	x.vect.Decode(b[i : i+a])
	i += a
	x.norm.Decode(b[i : i+a])
}
Пример #4
0
func (f *Imp) Codelen() uint {
	//
	n := 1 + col.Codelen() + clz
	switch f.sort {
	case Text:
		n += 2*clz + 1 + uint(len(f.tx))
	case Image:
		n += 4*clz + 1 + uint(len(f.tx))
	default:
		n += 2 * uint(len(f.x)) * clz
	}
	n += 2 * clz // Reserve
	return n
}
Пример #5
0
func (x *Imp) Encode() []byte {
	//
	b := make([]byte, x.Codelen())
	b[0] = byte(x.class)
	i, a := uint(1), cluint
	copy(b[i:i+a], Encode(x.number))
	i += a
	a = col.Codelen()
	copy(b[i:i+a], Encode(x.colour))
	i += a
	a = x.vect.Codelen()
	copy(b[i:i+a], x.vect.Encode())
	i += a
	copy(b[i:i+a], x.norm.Encode())
	return b
}
Пример #6
0
func (x *Imp) Decode(b []byte) { // TODO cF, cB
	//
	i, a := uint(0), uint(4)
	x.num = Decode(uint(0), b[i:i+a]).(uint)
	i += a
	x.mask = make([]string, x.num)
	for k := uint(0); k < x.num; k++ {
		a = uint(4)
		n := Decode(uint(0), b[i:i+a]).(uint)
		i += a
		a = n
		x.mask[i] = Decode(str.Clr(n), b[i:i+a]).(string)
		i += a
		a = uint(4)
		n = Decode(uint(0), b[i:i+a]).(uint)
		x.l[i], x.c[i] = n%256, n/256
		i += a
		a = col.Codelen()
		x.cF = Decode(col.Black, b[i:i+a]).(col.Colour)
		i += a
		x.cB = Decode(col.Black, b[i:i+a]).(col.Colour)
		i += a
	}
}
Пример #7
0
func (x *Imp) Codelen() uint {
	//
	return 1 + cluint + col.Codelen() + 2*x.vect.Codelen()
}
Пример #8
0
func zl() uint {
	//
	return 4*v.Codelen() + col.Codelen()
}