simple9/encoding.go
func EncodeAll(src []uint32) ([]uint32, error) {
	i := 0
	dst := make([]uint32, len(src))
	j := 0

	for {
		if i >= len(src) {
			break
		}
		remaining := src[i:]

		if canPack(remaining, 1, 28) {
			dst[j] = pack28(src[i : i+28])
			i += 28
		} else if canPack(remaining, 2, 14) {
			dst[j] = pack14(src[i : i+14])
			i += 14
		} else if canPack(remaining, 3, 9) {
			dst[j] = pack9(src[i : i+9])
			i += 9
		} else if canPack(remaining, 4, 7) {
			dst[j] = pack7(src[i : i+7])
			i += 7
		} else if canPack(remaining, 5, 5) {
			dst[j] = pack5(src[i : i+5])
			i += 5
		} else if canPack(remaining, 7, 4) {
			dst[j] = pack4(src[i : i+4])
			i += 4
		} else if canPack(remaining, 9, 3) {
			dst[j] = pack3(src[i : i+3])
			i += 3
		} else if canPack(remaining, 14, 2) {
			dst[j] = pack2(src[i : i+2])
			i += 2
		} else if canPack(remaining, 28, 1) {
			dst[j] = pack1(src[i : i+1])
			i += 1
		} else {
			return nil, fmt.Errorf("value out of bounds")
		}
		j += 1
	}
	return dst[:j], nil
}
func EncodeAll(src []uint32) ([]uint32, error) {
	i := 0
	dst := make([]uint32, len(src))
	j := 0

	for {
		if i >= len(src) {
			break
		}
		remaining := src[i:]

		if canPack(remaining, 1, 28) {
			dst[j] = pack28(src[i : i+28])
			i += 28
		} else if canPack(remaining, 2, 14) {
			dst[j] = pack14(src[i : i+14])
			i += 14
		} else if canPack(remaining, 3, 9) {
			dst[j] = pack9(src[i : i+9])
			i += 9
		} else if canPack(remaining, 4, 7) {
			dst[j] = pack7(src[i : i+7])
			i += 7
		} else if canPack(remaining, 5, 5) {
			dst[j] = pack5(src[i : i+5])
			i += 5
		} else if canPack(remaining, 7, 4) {
			dst[j] = pack4(src[i : i+4])
			i += 4
		} else if canPack(remaining, 9, 3) {
			dst[j] = pack3(src[i : i+3])
			i += 3
		} else if canPack(remaining, 14, 2) {
			dst[j] = pack2(src[i : i+2])
			i += 2
		} else if canPack(remaining, 28, 1) {
			dst[j] = pack1(src[i : i+1])
			i += 1
		} else {
			return nil, fmt.Errorf("value out of bounds")
		}
		j += 1
	}
	return dst[:j], nil
}
func EncodeAll ( src [ ] uint32 ) ( [ ] uint32 , error ) { i := 0 dst := make ( [ ] uint32 , len ( src ) ) j := 0 for { if i >= len ( src ) { break } remaining := src [ i : ] if canPack ( remaining , 1 , 28 ) { dst [ j ] = pack28 ( src [ i : i + 28 ] ) i += 28 } else if canPack ( remaining , 2 , 14 ) { dst [ j ] = pack14 ( src [ i : i + 14 ] ) i += 14 } else if canPack ( remaining , 3 , 9 ) { dst [ j ] = pack9 ( src [ i : i + 9 ] ) i += 9 } else if canPack ( remaining , 4 , 7 ) { dst [ j ] = pack7 ( src [ i : i + 7 ] ) i += 7 } else if canPack ( remaining , 5 , 5 ) { dst [ j ] = pack5 ( src [ i : i + 5 ] ) i += 5 } else if canPack ( remaining , 7 , 4 ) { dst [ j ] = pack4 ( src [ i : i + 4 ] ) i += 4 } else if canPack ( remaining , 9 , 3 ) { dst [ j ] = pack3 ( src [ i : i + 3 ] ) i += 3 } else if canPack ( remaining , 14 , 2 ) { dst [ j ] = pack2 ( src [ i : i + 2 ] ) i += 2 } else if canPack ( remaining , 28 , 1 ) { dst [ j ] = pack1 ( src [ i : i + 1 ] ) i += 1 } else { return nil , fmt . Errorf ( " " ) } j += 1 } return dst [ : j ] , nil }
// EncodeAll returns a packed slice of the values from src.  It a value is over
// 1 << 28, an error is returned.
EncodeAll returns a packed slice of the values from src . It a value is over 1 << 28 an error is returned .