| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 message = TestAllTypes.Parser.ParseFrom(request.Protobuf
Payload); | 94 message = TestAllTypes.Parser.ParseFrom(request.Protobuf
Payload); |
| 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 switch (request.RequestedOutputFormat) | 104 catch (InvalidJsonException e) |
| 105 { | 105 { |
| 106 case global::Conformance.WireFormat.JSON: | 106 return new ConformanceResponse { ParseError = e.Message }; |
| 107 var formatter = new JsonFormatter(new JsonFormatter.Settings
(false, typeRegistry)); | 107 } |
| 108 return new ConformanceResponse { JsonPayload = formatter.For
mat(message) }; | 108 try |
| 109 case global::Conformance.WireFormat.PROTOBUF: | 109 { |
| 110 return new ConformanceResponse { ProtobufPayload = message.T
oByteString() }; | 110 switch (request.RequestedOutputFormat) |
| 111 default: | 111 { |
| 112 throw new Exception("Unsupported request output format: " +
request.PayloadCase); | 112 case global::Conformance.WireFormat.Json: |
| 113 var formatter = new JsonFormatter(new JsonFormatter.Sett
ings(false, typeRegistry)); |
| 114 return new ConformanceResponse { JsonPayload = formatter
.Format(message) }; |
| 115 case global::Conformance.WireFormat.Protobuf: |
| 116 return new ConformanceResponse { ProtobufPayload = messa
ge.ToByteString() }; |
| 117 default: |
| 118 throw new Exception("Unsupported request output format:
" + request.PayloadCase); |
| 119 } |
| 120 } |
| 121 catch (InvalidOperationException e) |
| 122 { |
| 123 return new ConformanceResponse { SerializeError = e.Message }; |
| 113 } | 124 } |
| 114 } | 125 } |
| 115 | 126 |
| 116 private static int? ReadInt32(BinaryReader input) | 127 private static int? ReadInt32(BinaryReader input) |
| 117 { | 128 { |
| 118 byte[] bytes = input.ReadBytes(4); | 129 byte[] bytes = input.ReadBytes(4); |
| 119 if (bytes.Length == 0) | 130 if (bytes.Length == 0) |
| 120 { | 131 { |
| 121 // Cleanly reached the end of the stream | 132 // Cleanly reached the end of the stream |
| 122 return null; | 133 return null; |
| 123 } | 134 } |
| 124 if (bytes.Length != 4) | 135 if (bytes.Length != 4) |
| 125 { | 136 { |
| 126 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"); |
| 127 } | 138 } |
| 128 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); |
| 129 } | 140 } |
| 130 } | 141 } |
| 131 } | 142 } |
| OLD | NEW |