internal/genid: remove WhichFile

It seems safer to explicitly mention exactly which messages
have special handling, rather than special casing the .profile
that they live in. This is safer because there is no guarantee
that new messages won't be added to each of these files.

The protojson implementation is modified to no longer rely
on a isCustomType helper and instead return a marshal or unmarshal
function pointer that is non-nil if specialized serialization
exists for that message type.

Change-Id: I5e3551d66f5a4b9024e583b627c0292cb7da6803
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/235657
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/internal/genid/detect.go b/internal/genid/detect.go
deleted file mode 100644
index 0e22783..0000000
--- a/internal/genid/detect.go
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2020 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package genid
-
-import "google.golang.org/protobuf/reflect/protoreflect"
-
-type ProtoFile int
-
-const (
-	Unknown_file ProtoFile = iota
-	Any_file
-	Timestamp_file
-	Duration_file
-	Wrappers_file
-	Struct_file
-	FieldMask_file
-	Api_file
-	Type_file
-	SourceContext_file
-	Empty_file
-)
-
-var wellKnownTypes = map[protoreflect.FullName]ProtoFile{
-	Any_message_fullname:            Any_file,
-	Timestamp_message_fullname:      Timestamp_file,
-	Duration_message_fullname:       Duration_file,
-	BoolValue_message_fullname:      Wrappers_file,
-	Int32Value_message_fullname:     Wrappers_file,
-	Int64Value_message_fullname:     Wrappers_file,
-	UInt32Value_message_fullname:    Wrappers_file,
-	UInt64Value_message_fullname:    Wrappers_file,
-	FloatValue_message_fullname:     Wrappers_file,
-	DoubleValue_message_fullname:    Wrappers_file,
-	BytesValue_message_fullname:     Wrappers_file,
-	StringValue_message_fullname:    Wrappers_file,
-	Struct_message_fullname:         Struct_file,
-	ListValue_message_fullname:      Struct_file,
-	Value_message_fullname:          Struct_file,
-	NullValue_enum_fullname:         Struct_file,
-	FieldMask_message_fullname:      FieldMask_file,
-	Api_message_fullname:            Api_file,
-	Method_message_fullname:         Api_file,
-	Mixin_message_fullname:          Api_file,
-	Syntax_enum_fullname:            Type_file,
-	Type_message_fullname:           Type_file,
-	Field_message_fullname:          Type_file,
-	Field_Kind_enum_fullname:        Type_file,
-	Field_Cardinality_enum_fullname: Type_file,
-	Enum_message_fullname:           Type_file,
-	EnumValue_message_fullname:      Type_file,
-	Option_message_fullname:         Type_file,
-	SourceContext_message_fullname:  SourceContext_file,
-	Empty_message_fullname:          Empty_file,
-}
-
-// WhichFile identifies the proto file that an enum or message belongs to.
-// It currently only identifies well-known types.
-func WhichFile(s protoreflect.FullName) ProtoFile {
-	return wellKnownTypes[s]
-}
diff --git a/internal/genid/detect_test.go b/internal/genid/detect_test.go
deleted file mode 100644
index e9f656c..0000000
--- a/internal/genid/detect_test.go
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2020 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package genid_test
-
-import (
-	"testing"
-
-	"google.golang.org/protobuf/internal/genid"
-	"google.golang.org/protobuf/reflect/protoreflect"
-
-	"google.golang.org/protobuf/types/descriptorpb"
-	"google.golang.org/protobuf/types/known/anypb"
-	"google.golang.org/protobuf/types/known/apipb"
-	"google.golang.org/protobuf/types/known/durationpb"
-	"google.golang.org/protobuf/types/known/emptypb"
-	"google.golang.org/protobuf/types/known/fieldmaskpb"
-	"google.golang.org/protobuf/types/known/sourcecontextpb"
-	"google.golang.org/protobuf/types/known/structpb"
-	"google.golang.org/protobuf/types/known/timestamppb"
-	"google.golang.org/protobuf/types/known/typepb"
-	"google.golang.org/protobuf/types/known/wrapperspb"
-	"google.golang.org/protobuf/types/pluginpb"
-)
-
-func TestWhich(t *testing.T) {
-	tests := []struct {
-		in   protoreflect.FileDescriptor
-		want genid.ProtoFile
-	}{
-		{descriptorpb.File_google_protobuf_descriptor_proto, genid.Unknown_file},
-		{pluginpb.File_google_protobuf_compiler_plugin_proto, genid.Unknown_file},
-		{anypb.File_google_protobuf_any_proto, genid.Any_file},
-		{timestamppb.File_google_protobuf_timestamp_proto, genid.Timestamp_file},
-		{durationpb.File_google_protobuf_duration_proto, genid.Duration_file},
-		{wrapperspb.File_google_protobuf_wrappers_proto, genid.Wrappers_file},
-		{structpb.File_google_protobuf_struct_proto, genid.Struct_file},
-		{fieldmaskpb.File_google_protobuf_field_mask_proto, genid.FieldMask_file},
-		{apipb.File_google_protobuf_api_proto, genid.Api_file},
-		{typepb.File_google_protobuf_type_proto, genid.Type_file},
-		{sourcecontextpb.File_google_protobuf_source_context_proto, genid.SourceContext_file},
-		{emptypb.File_google_protobuf_empty_proto, genid.Empty_file},
-	}
-
-	for _, tt := range tests {
-		rangeDescriptors(tt.in, func(d protoreflect.Descriptor) {
-			got := genid.WhichFile(d.FullName())
-			if got != tt.want {
-				t.Errorf("Which(%s) = %v, want %v", d.FullName(), got, tt.want)
-			}
-		})
-	}
-}
-
-func rangeDescriptors(d interface {
-	Enums() protoreflect.EnumDescriptors
-	Messages() protoreflect.MessageDescriptors
-}, f func(protoreflect.Descriptor)) {
-	for i := 0; i < d.Enums().Len(); i++ {
-		ed := d.Enums().Get(i)
-		f(ed)
-	}
-	for i := 0; i < d.Messages().Len(); i++ {
-		md := d.Messages().Get(i)
-		if md.IsMapEntry() {
-			continue
-		}
-		f(md)
-		rangeDescriptors(md, f)
-	}
-}
diff --git a/internal/genid/doc.go b/internal/genid/doc.go
index a6f63d9..45ccd01 100644
--- a/internal/genid/doc.go
+++ b/internal/genid/doc.go
@@ -5,3 +5,7 @@
 // Package genid contains constants for declarations in descriptor.proto
 // and the well-known types.
 package genid
+
+import protoreflect "google.golang.org/protobuf/reflect/protoreflect"
+
+const GoogleProtobuf_package protoreflect.FullName = "google.protobuf"
diff --git a/internal/msgfmt/format.go b/internal/msgfmt/format.go
index 7a7fe71..9547a53 100644
--- a/internal/msgfmt/format.go
+++ b/internal/msgfmt/format.go
@@ -161,9 +161,16 @@
 		x = strings.TrimSuffix(x, "000")
 		x = strings.TrimSuffix(x, ".000")
 		return append(b, x+"s"...)
-	}
 
-	if genid.WhichFile(md.FullName()) == genid.Wrappers_file {
+	case genid.BoolValue_message_fullname,
+		genid.Int32Value_message_fullname,
+		genid.Int64Value_message_fullname,
+		genid.UInt32Value_message_fullname,
+		genid.UInt64Value_message_fullname,
+		genid.FloatValue_message_fullname,
+		genid.DoubleValue_message_fullname,
+		genid.StringValue_message_fullname,
+		genid.BytesValue_message_fullname:
 		fd := fds.ByNumber(genid.WrapperValue_Value_field_number)
 		return appendValue(b, m.Get(fd), fd)
 	}