Esempio n. 1
0
func writeSmallTuple(w io.Writer, t *reflect.SliceValue) {
	write1(w, SmallTupleTag)
	size := t.Len()
	write1(w, uint8(size))

	for i := 0; i < size; i++ {
		writeTag(w, t.Elem(i))
	}
}
Esempio n. 2
0
func PackSlice(writer io.Writer, value *reflect.SliceValue) (n int, err os.Error) {
	l := value.Len()
	if l < 16 {
		n, err := writer.Write([]byte{0x90 | byte(l)})
		if err != nil {
			return n, err
		}
		for i := 0; i < l; i++ {
			_n, err := PackValue(writer, value.Elem(i))
			if err != nil {
				return n, err
			}
			n += _n
		}
	} else if l < 65536 {
		n, err := writer.Write([]byte{0xdc, byte(l >> 8), byte(l)})
		if err != nil {
			return n, err
		}
		for i := 0; i < l; i++ {
			_n, err := PackValue(writer, value.Elem(i))
			if err != nil {
				return n, err
			}
			n += _n
		}
	} else {
		n, err := writer.Write([]byte{0xdd, byte(l >> 24), byte(l >> 16), byte(l >> 8), byte(l)})
		if err != nil {
			return n, err
		}
		for i := 0; i < l; i++ {
			_n, err := PackValue(writer, value.Elem(i))
			if err != nil {
				return n, err
			}
			n += _n
		}
	}
	return n, nil
}