From 61307b86f561721ac47ecd74d9fd1dffa0acad53 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Fri, 29 Apr 2016 10:10:40 +0100 Subject: Allow custom type URL prefixes in Any.Pack (And likewise ignore the prefix in unpack.) Fixes issue #1459. --- csharp/src/Google.Protobuf/JsonFormatter.cs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'csharp/src/Google.Protobuf/JsonFormatter.cs') 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) { -- cgit v1.2.3