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/irregular/test.pb.go b/internal/testprotos/irregular/test.pb.go
index c8ef2c4..5ea3cb0 100644
--- a/internal/testprotos/irregular/test.pb.go
+++ b/internal/testprotos/irregular/test.pb.go
@@ -24,10 +24,9 @@
 	MapMessage      map[string]*IrregularMessage `protobuf:"bytes,4,rep,name=map_message,json=mapMessage" json:"map_message,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"`
 	// Types that are valid to be assigned to Union:
 	//	*Message_OneofMessage
-	Union                isMessage_Union         `protobuf_oneof:"union"`
-	XXX_NoUnkeyedLiteral struct{}                `json:"-"`
-	XXX_unrecognized     protoimpl.UnknownFields `json:"-"`
-	XXX_sizecache        protoimpl.SizeCache     `json:"-"`
+	Union         isMessage_Union `protobuf_oneof:"union"`
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
 }
 
 func (x *Message) Reset() {
@@ -191,6 +190,18 @@
 		return
 	}
 	file_irregular_irregular_proto_init()
+	if !protoimpl.UnsafeEnabled {
+		file_irregular_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*Message); i {
+			case 5:
+				return &v.sizeCache
+			case 6:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+	}
 	file_irregular_test_proto_msgTypes[0].OneofWrappers = []interface{}{
 		(*Message_OneofMessage)(nil),
 	}