示例#1
0
func Test(t *testing.T) {

	if n := len(value100); n != 100 {
		t.Fatal(n)
	}

	c, err := zappy.Encode(nil, value100)
	if err != nil {
		t.Fatal(err)
	}

	if n := len(c); n != 50 {
		t.Fatal(n)
	}
}
示例#2
0
func (a *Allocator) makeUsedBlock(dst []byte, b []byte) (w []byte, rqAtoms int, cc byte, err error) {
	cc = tagNotCompressed
	w = b

	var n int
	if n = len(b); n > maxRq {
		return nil, 0, 0, &ErrINVAL{"Allocator.makeUsedBlock: content size out of limits", n}
	}

	rqAtoms = n2atoms(n)
	if a.Compress && n > 14 { // attempt compression
		if dst, err = zappy.Encode(dst, b); err != nil {
			return
		}

		n2 := len(dst)
		if rqAtoms2 := n2atoms(n2); rqAtoms2 < rqAtoms { // compression saved at least a single atom
			w, n, rqAtoms, cc = dst, n2, rqAtoms2, tagCompressed
		}
	}
	return
}