InvalidProtocolBufferException.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Protocol Buffers - Google's data interchange format
  2. // Copyright 2008 Google Inc.
  3. // http://code.google.com/p/protobuf/
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. using System.IO;
  17. namespace Google.ProtocolBuffers {
  18. /// <summary>
  19. /// Thrown when a protocol message being parsed is invalid in some way,
  20. /// e.g. it contains a malformed varint or a negative byte length.
  21. /// </summary>
  22. public sealed class InvalidProtocolBufferException : IOException {
  23. internal InvalidProtocolBufferException(string message)
  24. : base(message) {
  25. }
  26. /// TODO(jonskeet): Make this internal again and use InternalVisibleTo?
  27. public static InvalidProtocolBufferException TruncatedMessage() {
  28. return new InvalidProtocolBufferException(
  29. "While parsing a protocol message, the input ended unexpectedly " +
  30. "in the middle of a field. This could mean either than the " +
  31. "input has been truncated or that an embedded message " +
  32. "misreported its own length.");
  33. }
  34. internal static InvalidProtocolBufferException NegativeSize() {
  35. return new InvalidProtocolBufferException(
  36. "CodedInputStream encountered an embedded string or message " +
  37. "which claimed to have negative size.");
  38. }
  39. public static InvalidProtocolBufferException MalformedVarint() {
  40. return new InvalidProtocolBufferException(
  41. "CodedInputStream encountered a malformed varint.");
  42. }
  43. internal static InvalidProtocolBufferException InvalidTag() {
  44. return new InvalidProtocolBufferException(
  45. "Protocol message contained an invalid tag (zero).");
  46. }
  47. internal static InvalidProtocolBufferException InvalidEndTag() {
  48. return new InvalidProtocolBufferException(
  49. "Protocol message end-group tag did not match expected tag.");
  50. }
  51. internal static InvalidProtocolBufferException InvalidWireType() {
  52. return new InvalidProtocolBufferException(
  53. "Protocol message tag had invalid wire type.");
  54. }
  55. internal static InvalidProtocolBufferException RecursionLimitExceeded() {
  56. return new InvalidProtocolBufferException(
  57. "Protocol message had too many levels of nesting. May be malicious. " +
  58. "Use CodedInputStream.SetRecursionLimit() to increase the depth limit.");
  59. }
  60. internal static InvalidProtocolBufferException SizeLimitExceeded() {
  61. return new InvalidProtocolBufferException(
  62. "Protocol message was too large. May be malicious. " +
  63. "Use CodedInputStream.SetSizeLimit() to increase the size limit.");
  64. }
  65. }
  66. }