Browse Source

descriptor: deprecate the package

The descriptor package is an inferior way to access the descriptor protos
compared to the new v2 Message interface which provides direct support for the
same information and more.

We remove the tests since:
* It is a source of failures inside Google since the proto package for the
descriptors is not at "google.protobuf" for historical reasons.
* To avoid showing an example usage to further discourage usage.

Change-Id: I6d34287b258e2905de99207e486b842eb9152e35
Reviewed-on: https://go-review.googlesource.com/c/151407
Reviewed-by: Herbie Ong <herbie@google.com>
Joe Tsai 7 years ago
parent
commit
4c13d30a98
2 changed files with 6 additions and 38 deletions
  1. 6 6
      descriptor/descriptor.go
  2. 0 32
      descriptor/descriptor_test.go

+ 6 - 6
descriptor/descriptor.go

@@ -32,8 +32,8 @@
 // Package descriptor provides functions for obtaining protocol buffer
 // descriptors for generated Go types.
 //
-// These functions cannot go in package proto because they depend on the
-// generated protobuf descriptor messages, which themselves depend on proto.
+// Deprecated: Do not use. The new v2 Message interface provides direct support
+// for programmatically interacting with the descriptor information.
 package descriptor
 
 import (
@@ -43,11 +43,11 @@ import (
 	"io/ioutil"
 
 	"github.com/golang/protobuf/proto"
-	protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor"
+	descriptorpb "github.com/golang/protobuf/protoc-gen-go/descriptor"
 )
 
 // extractFile extracts a FileDescriptorProto from a gzip'd buffer.
-func extractFile(gz []byte) (*protobuf.FileDescriptorProto, error) {
+func extractFile(gz []byte) (*descriptorpb.FileDescriptorProto, error) {
 	r, err := gzip.NewReader(bytes.NewReader(gz))
 	if err != nil {
 		return nil, fmt.Errorf("failed to open gzip reader: %v", err)
@@ -59,7 +59,7 @@ func extractFile(gz []byte) (*protobuf.FileDescriptorProto, error) {
 		return nil, fmt.Errorf("failed to uncompress descriptor: %v", err)
 	}
 
-	fd := new(protobuf.FileDescriptorProto)
+	fd := new(descriptorpb.FileDescriptorProto)
 	if err := proto.Unmarshal(b, fd); err != nil {
 		return nil, fmt.Errorf("malformed FileDescriptorProto: %v", err)
 	}
@@ -78,7 +78,7 @@ type Message interface {
 
 // ForMessage returns a FileDescriptorProto and a DescriptorProto from within it
 // describing the given message.
-func ForMessage(msg Message) (fd *protobuf.FileDescriptorProto, md *protobuf.DescriptorProto) {
+func ForMessage(msg Message) (fd *descriptorpb.FileDescriptorProto, md *descriptorpb.DescriptorProto) {
 	gz, path := msg.Descriptor()
 	fd, err := extractFile(gz)
 	if err != nil {

+ 0 - 32
descriptor/descriptor_test.go

@@ -1,32 +0,0 @@
-package descriptor_test
-
-import (
-	"fmt"
-	"testing"
-
-	"github.com/golang/protobuf/descriptor"
-	tpb "github.com/golang/protobuf/proto/test_proto"
-	protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor"
-)
-
-func TestMessage(t *testing.T) {
-	var msg *protobuf.DescriptorProto
-	fd, md := descriptor.ForMessage(msg)
-	if pkg, want := fd.GetPackage(), "google.protobuf"; pkg != want {
-		t.Errorf("descriptor.ForMessage(%T).GetPackage() = %q; want %q", msg, pkg, want)
-	}
-	if name, want := md.GetName(), "DescriptorProto"; name != want {
-		t.Fatalf("descriptor.ForMessage(%T).GetName() = %q; want %q", msg, name, want)
-	}
-}
-
-func Example_options() {
-	var msg *tpb.MyMessageSet
-	_, md := descriptor.ForMessage(msg)
-	if md.GetOptions().GetMessageSetWireFormat() {
-		fmt.Printf("%v uses option message_set_wire_format.\n", md.GetName())
-	}
-
-	// Output:
-	// MyMessageSet uses option message_set_wire_format.
-}