InvalidProtocolBufferException.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. internal static InvalidProtocolBufferException TruncatedMessage() {
  27. return new InvalidProtocolBufferException(
  28. "While parsing a protocol message, the input ended unexpectedly " +
  29. "in the middle of a field. This could mean either than the " +
  30. "input has been truncated or that an embedded message " +
  31. "misreported its own length.");
  32. }
  33. internal static InvalidProtocolBufferException NegativeSize() {
  34. return new InvalidProtocolBufferException(
  35. "CodedInputStream encountered an embedded string or message " +
  36. "which claimed to have negative size.");
  37. }
  38. public static InvalidProtocolBufferException MalformedVarint() {
  39. return new InvalidProtocolBufferException(
  40. "CodedInputStream encountered a malformed varint.");
  41. }
  42. internal static InvalidProtocolBufferException InvalidTag() {
  43. return new InvalidProtocolBufferException(
  44. "Protocol message contained an invalid tag (zero).");
  45. }
  46. internal static InvalidProtocolBufferException InvalidEndTag() {
  47. return new InvalidProtocolBufferException(
  48. "Protocol message end-group tag did not match expected tag.");
  49. }
  50. internal static InvalidProtocolBufferException InvalidWireType() {
  51. return new InvalidProtocolBufferException(
  52. "Protocol message tag had invalid wire type.");
  53. }
  54. internal static InvalidProtocolBufferException RecursionLimitExceeded() {
  55. return new InvalidProtocolBufferException(
  56. "Protocol message had too many levels of nesting. May be malicious. " +
  57. "Use CodedInputStream.SetRecursionLimit() to increase the depth limit.");
  58. }
  59. internal static InvalidProtocolBufferException SizeLimitExceeded() {
  60. return new InvalidProtocolBufferException(
  61. "Protocol message was too large. May be malicious. " +
  62. "Use CodedInputStream.SetSizeLimit() to increase the size limit.");
  63. }
  64. }
  65. }