io: add a note for WriteArray, fix #519

It can't be really solved in many cases (it's used in P2P protocol and we have
to follow the usual conventions there) and in most of the cases we don't care
about the difference between nil slice and zero-length slice.
This commit is contained in:
Roman Khimov 2019-12-09 18:39:30 +03:00
parent f1856bfa8b
commit 35e368c241

View file

@ -35,7 +35,9 @@ func (w *BinWriter) WriteBE(v interface{}) {
w.Err = binary.Write(w.w, binary.BigEndian, v) w.Err = binary.Write(w.w, binary.BigEndian, v)
} }
// WriteArray writes a slice or an array arr into w. // WriteArray writes a slice or an array arr into w. Note that nil slices and
// empty slices are gonna be treated the same resulting in equal zero-length
// array encoded.
func (w *BinWriter) WriteArray(arr interface{}) { func (w *BinWriter) WriteArray(arr interface{}) {
switch val := reflect.ValueOf(arr); val.Kind() { switch val := reflect.ValueOf(arr); val.Kind() {
case reflect.Slice, reflect.Array: case reflect.Slice, reflect.Array: