001 // Protocol Buffers - Google's data interchange format
002 // Copyright 2008 Google Inc.
003 // http://code.google.com/p/protobuf/
004 //
005 // Licensed under the Apache License, Version 2.0 (the "License");
006 // you may not use this file except in compliance with the License.
007 // You may obtain a copy of the License at
008 //
009 // http://www.apache.org/licenses/LICENSE-2.0
010 //
011 // Unless required by applicable law or agreed to in writing, software
012 // distributed under the License is distributed on an "AS IS" BASIS,
013 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 // See the License for the specific language governing permissions and
015 // limitations under the License.
016
017 package org.fusesource.hawtbuf.proto;
018
019 import java.io.IOException;
020
021 /**
022 * Thrown when a protocol message being parsed is invalid in some way, e.g. it
023 * contains a malformed varint or a negative byte length.
024 *
025 * @author kenton@google.com Kenton Varda
026 */
027 public class InvalidProtocolBufferException extends IOException {
028 private static final long serialVersionUID = 5685337441004132240L;
029
030 public InvalidProtocolBufferException(String description) {
031 super(description);
032 }
033
034 static InvalidProtocolBufferException truncatedMessage() {
035 return new InvalidProtocolBufferException("While parsing a protocol message, the input ended unexpectedly " + "in the middle of a field. This could mean either than the " + "input has been truncated or that an embedded message "
036 + "misreported its own length.");
037 }
038
039 static InvalidProtocolBufferException negativeSize() {
040 return new InvalidProtocolBufferException("CodedInputStream encountered an embedded string or message " + "which claimed to have negative size.");
041 }
042
043 static InvalidProtocolBufferException malformedVarint() {
044 return new InvalidProtocolBufferException("CodedInputStream encountered a malformed varint.");
045 }
046
047 static InvalidProtocolBufferException invalidTag() {
048 return new InvalidProtocolBufferException("Protocol message contained an invalid tag (zero).");
049 }
050
051 static InvalidProtocolBufferException invalidEndTag() {
052 return new InvalidProtocolBufferException("Protocol message end-group tag did not match expected tag.");
053 }
054
055 static InvalidProtocolBufferException invalidWireType() {
056 return new InvalidProtocolBufferException("Protocol message tag had invalid wire type.");
057 }
058
059 static InvalidProtocolBufferException recursionLimitExceeded() {
060 return new InvalidProtocolBufferException("Protocol message had too many levels of nesting. May be malicious. " + "Use CodedInputStream.setRecursionLimit() to increase the depth limit.");
061 }
062
063 static InvalidProtocolBufferException sizeLimitExceeded() {
064 return new InvalidProtocolBufferException("Protocol message was too large. May be malicious. " + "Use CodedInputStream.setSizeLimit() to increase the size limit.");
065 }
066 }