internal/cmd/generate-types: use ConsumeBytes instead of ConsumeString

The protowire.{ConsumeBytes,ConsumeString} funcs are identical except
that the latter allocates a string by implicitly converting the []byte.
Avoid using ConsumeString since we can do the conversion ourselves
at a latter point and sometimes avoid the allocation.

Change-Id: Idf31edc013b72ee5ee8461a68d10e57ad461d95c
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/263628
Trust: Joe Tsai <joetsai@digital-static.net>
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/internal/impl/codec_gen.go b/internal/impl/codec_gen.go
index 2da1029..1a509b6 100644
--- a/internal/impl/codec_gen.go
+++ b/internal/impl/codec_gen.go
@@ -4935,11 +4935,11 @@
 	if wtyp != protowire.BytesType {
 		return out, errUnknown
 	}
-	v, n := protowire.ConsumeString(b)
+	v, n := protowire.ConsumeBytes(b)
 	if n < 0 {
 		return out, errDecode
 	}
-	*p.String() = v
+	*p.String() = string(v)
 	out.n = n
 	return out, nil
 }
@@ -4967,14 +4967,14 @@
 	if wtyp != protowire.BytesType {
 		return out, errUnknown
 	}
-	v, n := protowire.ConsumeString(b)
+	v, n := protowire.ConsumeBytes(b)
 	if n < 0 {
 		return out, errDecode
 	}
-	if !utf8.ValidString(v) {
+	if !utf8.Valid(v) {
 		return out, errInvalidUTF8{}
 	}
-	*p.String() = v
+	*p.String() = string(v)
 	out.n = n
 	return out, nil
 }
@@ -5058,7 +5058,7 @@
 	if wtyp != protowire.BytesType {
 		return out, errUnknown
 	}
-	v, n := protowire.ConsumeString(b)
+	v, n := protowire.ConsumeBytes(b)
 	if n < 0 {
 		return out, errDecode
 	}
@@ -5066,7 +5066,7 @@
 	if *vp == nil {
 		*vp = new(string)
 	}
-	**vp = v
+	**vp = string(v)
 	out.n = n
 	return out, nil
 }
@@ -5095,18 +5095,18 @@
 	if wtyp != protowire.BytesType {
 		return out, errUnknown
 	}
-	v, n := protowire.ConsumeString(b)
+	v, n := protowire.ConsumeBytes(b)
 	if n < 0 {
 		return out, errDecode
 	}
-	if !utf8.ValidString(v) {
+	if !utf8.Valid(v) {
 		return out, errInvalidUTF8{}
 	}
 	vp := p.StringPtr()
 	if *vp == nil {
 		*vp = new(string)
 	}
-	**vp = v
+	**vp = string(v)
 	out.n = n
 	return out, nil
 }
@@ -5143,11 +5143,11 @@
 	if wtyp != protowire.BytesType {
 		return out, errUnknown
 	}
-	v, n := protowire.ConsumeString(b)
+	v, n := protowire.ConsumeBytes(b)
 	if n < 0 {
 		return out, errDecode
 	}
-	*sp = append(*sp, v)
+	*sp = append(*sp, string(v))
 	out.n = n
 	return out, nil
 }
@@ -5177,15 +5177,15 @@
 	if wtyp != protowire.BytesType {
 		return out, errUnknown
 	}
-	v, n := protowire.ConsumeString(b)
+	v, n := protowire.ConsumeBytes(b)
 	if n < 0 {
 		return out, errDecode
 	}
-	if !utf8.ValidString(v) {
+	if !utf8.Valid(v) {
 		return out, errInvalidUTF8{}
 	}
 	sp := p.StringSlice()
-	*sp = append(*sp, v)
+	*sp = append(*sp, string(v))
 	out.n = n
 	return out, nil
 }
@@ -5214,7 +5214,7 @@
 	if wtyp != protowire.BytesType {
 		return protoreflect.Value{}, out, errUnknown
 	}
-	v, n := protowire.ConsumeString(b)
+	v, n := protowire.ConsumeBytes(b)
 	if n < 0 {
 		return protoreflect.Value{}, out, errDecode
 	}
@@ -5244,11 +5244,11 @@
 	if wtyp != protowire.BytesType {
 		return protoreflect.Value{}, out, errUnknown
 	}
-	v, n := protowire.ConsumeString(b)
+	v, n := protowire.ConsumeBytes(b)
 	if n < 0 {
 		return protoreflect.Value{}, out, errDecode
 	}
-	if !utf8.ValidString(v) {
+	if !utf8.Valid(v) {
 		return protoreflect.Value{}, out, errInvalidUTF8{}
 	}
 	out.n = n
@@ -5289,7 +5289,7 @@
 	if wtyp != protowire.BytesType {
 		return protoreflect.Value{}, out, errUnknown
 	}
-	v, n := protowire.ConsumeString(b)
+	v, n := protowire.ConsumeBytes(b)
 	if n < 0 {
 		return protoreflect.Value{}, out, errDecode
 	}