Exemple #1
0
 private static ConformanceResponse PerformRequest(ConformanceRequest request, TypeRegistry typeRegistry)
 {
     TestAllTypes message;
     try
     {
         switch (request.PayloadCase)
         {
             case ConformanceRequest.PayloadOneofCase.JsonPayload:
                 var parser = new JsonParser(new JsonParser.Settings(20, typeRegistry));
                 message = parser.Parse<TestAllTypes>(request.JsonPayload);
                 break;
             case ConformanceRequest.PayloadOneofCase.ProtobufPayload:
                 message = TestAllTypes.Parser.ParseFrom(request.ProtobufPayload);
                 break;
             default:
                 throw new Exception("Unsupported request payload: " + request.PayloadCase);
         }
     }
     catch (InvalidProtocolBufferException e)
     {
         return new ConformanceResponse { ParseError = e.Message };
     }
     switch (request.RequestedOutputFormat)
     {
         case global::Conformance.WireFormat.JSON:
             var formatter = new JsonFormatter(new JsonFormatter.Settings(false, typeRegistry));
             return new ConformanceResponse { JsonPayload = formatter.Format(message) };
         case global::Conformance.WireFormat.PROTOBUF:
             return new ConformanceResponse { ProtobufPayload = message.ToByteString() };
         default:
             throw new Exception("Unsupported request output format: " + request.PayloadCase);
     }
 }
Exemple #2
0
 private static bool RunTest(BinaryReader input, BinaryWriter output, TypeRegistry typeRegistry)
 {
     int? size = ReadInt32(input);
     if (size == null)
     {
         return false;
     }
     byte[] inputData = input.ReadBytes(size.Value);
     if (inputData.Length != size.Value)
     {
         throw new EndOfStreamException("Read " + inputData.Length + " bytes of data when expecting " + size);
     }
     ConformanceRequest request = ConformanceRequest.Parser.ParseFrom(inputData);
     ConformanceResponse response = PerformRequest(request, typeRegistry);
     byte[] outputData = response.ToByteArray();
     output.Write(outputData.Length);
     output.Write(outputData);
     // Ready for another test...
     return true;
 }
 /// <summary>
 /// Creates a new <see cref="Settings"/> object with the specified formatting of default values
 /// and type registry.
 /// </summary>
 /// <param name="formatDefaultValues"><c>true</c> if default values (0, empty strings etc) should be formatted; <c>false</c> otherwise.</param>
 /// <param name="typeRegistry">The <see cref="TypeRegistry"/> to use when formatting <see cref="Any"/> messages.</param>
 public Settings(bool formatDefaultValues, TypeRegistry typeRegistry)
 {
     FormatDefaultValues = formatDefaultValues;
     TypeRegistry = ProtoPreconditions.CheckNotNull(typeRegistry, nameof(typeRegistry));
 }
Exemple #4
0
 private static void AssertDescriptorAbsent(TypeRegistry registry, MessageDescriptor descriptor)
 {
     Assert.IsNull(registry.Find(descriptor.FullName));
 }
Exemple #5
0
 private static void AssertDescriptorPresent(TypeRegistry registry, MessageDescriptor descriptor)
 {
     Assert.AreSame(descriptor, registry.Find(descriptor.FullName));
 }
Exemple #6
0
 private static void AssertDescriptorAbsent(TypeRegistry registry, MessageDescriptor descriptor)
 {
     Assert.IsNull(registry.Find(descriptor.FullName));
 }
Exemple #7
0
 private static void AssertDescriptorPresent(TypeRegistry registry, MessageDescriptor descriptor)
 {
     Assert.AreSame(descriptor, registry.Find(descriptor.FullName));
 }