From 35e368c24168e75c9a4ab2122b1a96e11e09294c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 9 Dec 2019 18:39:30 +0300 Subject: [PATCH] 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. --- pkg/io/binaryWriter.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/io/binaryWriter.go b/pkg/io/binaryWriter.go index d9ea336e2..457f7f846 100644 --- a/pkg/io/binaryWriter.go +++ b/pkg/io/binaryWriter.go @@ -35,7 +35,9 @@ func (w *BinWriter) WriteBE(v interface{}) { 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{}) { switch val := reflect.ValueOf(arr); val.Kind() { case reflect.Slice, reflect.Array: