internal/fileinit: add FileDescriptor.ProtoLegacyRawDesc method

Add a ProtoLegacyRawDesc method for v1 registration support.

Change-Id: I4f03d022854c8d79da776610cb7d75ba9976334f
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/172241
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/internal/fileinit/desc.go b/internal/fileinit/desc.go
index 199e38d..120b7b9 100644
--- a/internal/fileinit/desc.go
+++ b/internal/fileinit/desc.go
@@ -218,12 +218,12 @@
 	// fileInit contains a copy of certain fields in FileBuilder for use during
 	// lazy initialization upon first use.
 	fileInit struct {
-		RawDescriptor     []byte
 		GoTypes           []interface{}
 		DependencyIndexes []int32
 	}
 	fileDesc struct {
 		fileInit
+		rawDesc []byte
 
 		path         string
 		protoPackage pref.FullName
@@ -270,6 +270,15 @@
 func (fd *fileDesc) ProtoType(pref.FileDescriptor)         {}
 func (fd *fileDesc) ProtoInternal(pragma.DoNotImplement)   {}
 
+// ProtoLegacyRawDesc is a pseudo-internal API for allowing the v1 code
+// to be able to retrieve the raw descriptor.
+//
+// WARNING: This method is exempt from the compatibility promise and may be
+// removed in the future without warning.
+func (fd *fileDesc) ProtoLegacyRawDesc() []byte {
+	return fd.rawDesc
+}
+
 type (
 	enumDesc struct {
 		baseDesc
diff --git a/internal/fileinit/desc_init.go b/internal/fileinit/desc_init.go
index f339b0d..29d0531 100644
--- a/internal/fileinit/desc_init.go
+++ b/internal/fileinit/desc_init.go
@@ -12,10 +12,9 @@
 
 func newFileDesc(fb FileBuilder) *fileDesc {
 	file := &fileDesc{fileInit: fileInit{
-		RawDescriptor:     fb.RawDescriptor,
 		GoTypes:           fb.GoTypes,
 		DependencyIndexes: fb.DependencyIndexes,
-	}}
+	}, rawDesc: fb.RawDescriptor}
 	file.initDecls(len(fb.EnumOutputTypes), len(fb.MessageOutputTypes), len(fb.ExtensionOutputTypes))
 	file.unmarshalSeed(fb.RawDescriptor)
 
diff --git a/internal/fileinit/desc_lazy.go b/internal/fileinit/desc_lazy.go
index bbcc9d9..62ee81b 100644
--- a/internal/fileinit/desc_lazy.go
+++ b/internal/fileinit/desc_lazy.go
@@ -20,7 +20,7 @@
 
 func (file *fileDesc) lazyInit() *fileLazy {
 	file.once.Do(func() {
-		file.unmarshalFull(file.RawDescriptor)
+		file.unmarshalFull(file.rawDesc)
 		file.resolveImports()
 		file.resolveEnums()
 		file.resolveMessages()