Example #1
0
func writeList(w io.Writer, l *reflect.ArrayValue) {
	write1(w, ListTag)
	size := l.Len()
	write4(w, uint32(size))

	for i := 0; i < size; i++ {
		writeTag(w, l.Elem(i))
	}

	writeNil(w)
}
Example #2
0
func PackArray(writer io.Writer, value *reflect.ArrayValue) (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
}