InvalidProtocolBufferException.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.IO;
  3. namespace Google.ProtocolBuffers {
  4. /// <summary>
  5. /// Thrown when a protocol message being parsed is invalid in some way,
  6. /// e.g. it contains a malformed varint or a negative byte length.
  7. ///
  8. /// TODO(jonskeet): Make the methods throw directly? Rename them?
  9. /// </summary>
  10. public class InvalidProtocolBufferException : IOException {
  11. private InvalidProtocolBufferException(string message)
  12. : base(message) {
  13. }
  14. /// TODO(jonskeet): Make this internal again and use InternalVisibleTo?
  15. public static InvalidProtocolBufferException TruncatedMessage() {
  16. return new InvalidProtocolBufferException(
  17. "While parsing a protocol message, the input ended unexpectedly " +
  18. "in the middle of a field. This could mean either than the " +
  19. "input has been truncated or that an embedded message " +
  20. "misreported its own length.");
  21. }
  22. /// TODO(jonskeet): Make this internal again and use InternalVisibleTo?
  23. internal static InvalidProtocolBufferException NegativeSize() {
  24. return new InvalidProtocolBufferException(
  25. "CodedInputStream encountered an embedded string or message " +
  26. "which claimed to have negative size.");
  27. }
  28. public static InvalidProtocolBufferException MalformedVarint() {
  29. return new InvalidProtocolBufferException(
  30. "CodedInputStream encountered a malformed varint.");
  31. }
  32. internal static InvalidProtocolBufferException InvalidTag() {
  33. return new InvalidProtocolBufferException(
  34. "Protocol message contained an invalid tag (zero).");
  35. }
  36. internal static InvalidProtocolBufferException InvalidEndTag() {
  37. return new InvalidProtocolBufferException(
  38. "Protocol message end-group tag did not match expected tag.");
  39. }
  40. internal static InvalidProtocolBufferException InvalidWireType() {
  41. return new InvalidProtocolBufferException(
  42. "Protocol message tag had invalid wire type.");
  43. }
  44. internal static InvalidProtocolBufferException RecursionLimitExceeded() {
  45. return new InvalidProtocolBufferException(
  46. "Protocol message had too many levels of nesting. May be malicious. " +
  47. "Use CodedInputStream.setRecursionLimit() to increase the depth limit.");
  48. }
  49. internal static InvalidProtocolBufferException SizeLimitExceeded() {
  50. return new InvalidProtocolBufferException(
  51. "Protocol message was too large. May be malicious. " +
  52. "Use CodedInputStream.setSizeLimit() to increase the size limit.");
  53. }
  54. }
  55. }