aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/src/Google.Protobuf/JsonFormatter.cs
diff options
context:
space:
mode:
authorGravatar Jon Skeet <jonskeet@google.com>2016-04-29 10:10:40 +0100
committerGravatar Jon Skeet <jonskeet@google.com>2016-04-29 10:20:03 +0100
commit61307b86f561721ac47ecd74d9fd1dffa0acad53 (patch)
treebda7a9541f0639d05bfb9b1c0acde474e8e14133 /csharp/src/Google.Protobuf/JsonFormatter.cs
parentb53417c7356deab70f44b60bd7e6270023ddc3b6 (diff)
Allow custom type URL prefixes in Any.Pack
(And likewise ignore the prefix in unpack.) Fixes issue #1459.
Diffstat (limited to 'csharp/src/Google.Protobuf/JsonFormatter.cs')
-rw-r--r--csharp/src/Google.Protobuf/JsonFormatter.cs14
1 files changed, 2 insertions, 12 deletions
diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs
index 73a4f64b..83772473 100644
--- a/csharp/src/Google.Protobuf/JsonFormatter.cs
+++ b/csharp/src/Google.Protobuf/JsonFormatter.cs
@@ -567,7 +567,7 @@ namespace Google.Protobuf
string typeUrl = (string) value.Descriptor.Fields[Any.TypeUrlFieldNumber].Accessor.GetValue(value);
ByteString data = (ByteString) value.Descriptor.Fields[Any.ValueFieldNumber].Accessor.GetValue(value);
- string typeName = GetTypeName(typeUrl);
+ string typeName = Any.GetTypeName(typeUrl);
MessageDescriptor descriptor = settings.TypeRegistry.Find(typeName);
if (descriptor == null)
{
@@ -608,17 +608,7 @@ namespace Google.Protobuf
writer.Write(data.ToBase64());
writer.Write('"');
writer.Write(" }");
- }
-
- internal static string GetTypeName(String typeUrl)
- {
- string[] parts = typeUrl.Split('/');
- if (parts.Length != 2 || parts[0] != TypeUrlPrefix)
- {
- throw new InvalidProtocolBufferException($"Invalid type url: {typeUrl}");
- }
- return parts[1];
- }
+ }
private void WriteStruct(TextWriter writer, IMessage message)
{