cmd/protoc-gen-go: unexport implementation-specific XXX fields

We modify protoc-gen-go to stop generating exported XXX fields.
The unsafe implementation is unaffected by this change since unsafe
can access fields regardless of visibility. However, for the purego
implementation, we need to respect Go visibility rules as enforced
by the reflect package.

We work around this by generating a exporter function that given
a reference to the message and the field to export, returns a reference
to the unexported field value. This exporter function is protected by
a constant such that it is not linked into the final binary in non-purego
build environment.

Updates golang/protobuf#276

Change-Id: Idf5c1f158973fa1c61187ff41440acb21c5dac94
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/185141
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/internal/testprotos/benchmarks/benchmarks.pb.go b/internal/testprotos/benchmarks/benchmarks.pb.go
index 62b706e..2545f7d 100644
--- a/internal/testprotos/benchmarks/benchmarks.pb.go
+++ b/internal/testprotos/benchmarks/benchmarks.pb.go
@@ -42,10 +42,9 @@
 	// potentially more realistic results than just parsing the same message
 	// over and over.  A single message parsed repeatedly could yield unusually
 	// good branch prediction performance.
-	Payload              [][]byte                `protobuf:"bytes,3,rep,name=payload,proto3" json:"payload,omitempty"`
-	XXX_NoUnkeyedLiteral struct{}                `json:"-"`
-	XXX_unrecognized     protoimpl.UnknownFields `json:"-"`
-	XXX_sizecache        protoimpl.SizeCache     `json:"-"`
+	Payload       [][]byte `protobuf:"bytes,3,rep,name=payload,proto3" json:"payload,omitempty"`
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
 }
 
 func (x *BenchmarkDataset) Reset() {
@@ -141,6 +140,18 @@
 	if File_benchmarks_proto != nil {
 		return
 	}
+	if !protoimpl.UnsafeEnabled {
+		file_benchmarks_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*BenchmarkDataset); i {
+			case 3:
+				return &v.sizeCache
+			case 4:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+	}
 	out := protoimpl.TypeBuilder{
 		File: protoimpl.DescBuilder{
 			RawDescriptor: file_benchmarks_proto_rawDesc,