proto: consistently use non-nil, zero-length []bytes for empty bytes strings
The fast-path decoder decodes zero-length repeated bytes values as
non-nil, zero-length []bytes. Do the same in the reflection decoder.
This isn't really a correctness issue, since there's no ambiguity about what a
nil entry in a [][]byte means. Still a good idea for consistency, and
retains v1 behavior.
Change-Id: Icd2cb726d14ff1f2b9f142e65756777a359971f3
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/210257
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/internal/impl/codec_gen.go b/internal/impl/codec_gen.go
index 7d089f6..bc7e414 100644
--- a/internal/impl/codec_gen.go
+++ b/internal/impl/codec_gen.go
@@ -4711,7 +4711,7 @@
if n < 0 {
return protoreflect.Value{}, 0, wire.ParseError(n)
}
- return protoreflect.ValueOfBytes(append(([]byte)(nil), v...)), n, nil
+ return protoreflect.ValueOfBytes(append(emptyBuf[:], v...)), n, nil
}
var coderBytesValue = valueCoderFuncs{
@@ -4751,7 +4751,7 @@
if n < 0 {
return protoreflect.Value{}, 0, wire.ParseError(n)
}
- list.Append(protoreflect.ValueOfBytes(append(([]byte)(nil), v...)))
+ list.Append(protoreflect.ValueOfBytes(append(emptyBuf[:], v...)))
return listv, n, nil
}