| OLD | NEW |
| 1 #region Copyright notice and license | 1 #region Copyright notice and license |
| 2 // Protocol Buffers - Google's data interchange format | 2 // Protocol Buffers - Google's data interchange format |
| 3 // Copyright 2015 Google Inc. All rights reserved. | 3 // Copyright 2015 Google Inc. All rights reserved. |
| 4 // https://developers.google.com/protocol-buffers/ | 4 // https://developers.google.com/protocol-buffers/ |
| 5 // | 5 // |
| 6 // Redistribution and use in source and binary forms, with or without | 6 // Redistribution and use in source and binary forms, with or without |
| 7 // modification, are permitted provided that the following conditions are | 7 // modification, are permitted provided that the following conditions are |
| 8 // met: | 8 // met: |
| 9 // | 9 // |
| 10 // * Redistributions of source code must retain the above copyright | 10 // * Redistributions of source code must retain the above copyright |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 /// Conformance tests. The test runner will provide JSON or proto data on st
din, | 41 /// Conformance tests. The test runner will provide JSON or proto data on st
din, |
| 42 /// and this program will produce its output on stdout. | 42 /// and this program will produce its output on stdout. |
| 43 /// </summary> | 43 /// </summary> |
| 44 class Program | 44 class Program |
| 45 { | 45 { |
| 46 private static void Main(string[] args) | 46 private static void Main(string[] args) |
| 47 { | 47 { |
| 48 // This way we get the binary streams instead of readers/writers. | 48 // This way we get the binary streams instead of readers/writers. |
| 49 var input = new BinaryReader(Console.OpenStandardInput()); | 49 var input = new BinaryReader(Console.OpenStandardInput()); |
| 50 var output = new BinaryWriter(Console.OpenStandardOutput()); | 50 var output = new BinaryWriter(Console.OpenStandardOutput()); |
| 51 var typeRegistry = TypeRegistry.FromMessages(TestAllTypes.Descriptor
); | 51 var typeRegistry = TypeRegistry.FromMessages(ProtobufTestMessages.Pr
oto3.TestAllTypes.Descriptor); |
| 52 | 52 |
| 53 int count = 0; | 53 int count = 0; |
| 54 while (RunTest(input, output, typeRegistry)) | 54 while (RunTest(input, output, typeRegistry)) |
| 55 { | 55 { |
| 56 count++; | 56 count++; |
| 57 } | 57 } |
| 58 Console.Error.WriteLine("Received EOF after {0} tests", count); | 58 Console.Error.WriteLine("Received EOF after {0} tests", count); |
| 59 } | 59 } |
| 60 | 60 |
| 61 private static bool RunTest(BinaryReader input, BinaryWriter output, Typ
eRegistry typeRegistry) | 61 private static bool RunTest(BinaryReader input, BinaryWriter output, Typ
eRegistry typeRegistry) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 74 ConformanceResponse response = PerformRequest(request, typeRegistry)
; | 74 ConformanceResponse response = PerformRequest(request, typeRegistry)
; |
| 75 byte[] outputData = response.ToByteArray(); | 75 byte[] outputData = response.ToByteArray(); |
| 76 output.Write(outputData.Length); | 76 output.Write(outputData.Length); |
| 77 output.Write(outputData); | 77 output.Write(outputData); |
| 78 // Ready for another test... | 78 // Ready for another test... |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 | 81 |
| 82 private static ConformanceResponse PerformRequest(ConformanceRequest req
uest, TypeRegistry typeRegistry) | 82 private static ConformanceResponse PerformRequest(ConformanceRequest req
uest, TypeRegistry typeRegistry) |
| 83 { | 83 { |
| 84 TestAllTypes message; | 84 ProtobufTestMessages.Proto3.TestAllTypes message; |
| 85 try | 85 try |
| 86 { | 86 { |
| 87 switch (request.PayloadCase) | 87 switch (request.PayloadCase) |
| 88 { | 88 { |
| 89 case ConformanceRequest.PayloadOneofCase.JsonPayload: | 89 case ConformanceRequest.PayloadOneofCase.JsonPayload: |
| 90 var parser = new JsonParser(new JsonParser.Settings(20,
typeRegistry)); | 90 var parser = new JsonParser(new JsonParser.Settings(20,
typeRegistry)); |
| 91 message = parser.Parse<TestAllTypes>(request.JsonPayload
); | 91 message = parser.Parse<ProtobufTestMessages.Proto3.TestA
llTypes>(request.JsonPayload); |
| 92 break; | 92 break; |
| 93 case ConformanceRequest.PayloadOneofCase.ProtobufPayload: | 93 case ConformanceRequest.PayloadOneofCase.ProtobufPayload: |
| 94 message = TestAllTypes.Parser.ParseFrom(request.Protobuf
Payload); | 94 message = ProtobufTestMessages.Proto3.TestAllTypes.Parse
r.ParseFrom(request.ProtobufPayload); |
| 95 break; | 95 break; |
| 96 default: | 96 default: |
| 97 throw new Exception("Unsupported request payload: " + re
quest.PayloadCase); | 97 throw new Exception("Unsupported request payload: " + re
quest.PayloadCase); |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 catch (InvalidProtocolBufferException e) | 100 catch (InvalidProtocolBufferException e) |
| 101 { | 101 { |
| 102 return new ConformanceResponse { ParseError = e.Message }; | 102 return new ConformanceResponse { ParseError = e.Message }; |
| 103 } | 103 } |
| 104 catch (InvalidJsonException e) | 104 catch (InvalidJsonException e) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 133 return null; | 133 return null; |
| 134 } | 134 } |
| 135 if (bytes.Length != 4) | 135 if (bytes.Length != 4) |
| 136 { | 136 { |
| 137 throw new EndOfStreamException("Read " + bytes.Length + " bytes
of size when expecting 4"); | 137 throw new EndOfStreamException("Read " + bytes.Length + " bytes
of size when expecting 4"); |
| 138 } | 138 } |
| 139 return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] <<
24); | 139 return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] <<
24); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 } | 142 } |
| OLD | NEW |