static InvalidProtocolBufferException truncatedMessage() { 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 " + "misreported its own length."); }
/** * Verifies that the last call to readTag() returned the given tag value. * This is used to verify that a nested group ended with the correct end * tag. * * @throws InvalidProtocolBufferException * {@code value} does not match the last tag. */ public void checkLastTagWas(int value) throws InvalidProtocolBufferException { if (lastTag != value) { throw InvalidProtocolBufferException.invalidEndTag(); } }
/** Read a raw Varint from the stream. */ public long readRawVarint64() throws IOException { int shift = 0; long result = 0; while (shift < 64) { byte b = readRawByte(); result |= (long) (b & 0x7F) << shift; if ((b & 0x80) == 0) return result; shift += 7; } throw InvalidProtocolBufferException.malformedVarint(); }
/** * Attempt to read a field tag, returning zero if we have reached EOF. * Protocol message parsers use this to read tags, since a protocol message * may legally end wherever a tag occurs, and zero is not a valid tag * number. */ public int readTag() throws IOException { if( pos >= limit ) { lastTag=0; return 0; } try { lastTag = readRawVarint32(); if (lastTag == 0) { // If we actually read zero, that's not a valid tag. throw InvalidProtocolBufferException.invalidTag(); } return lastTag; } catch (EOFException e) { lastTag=0; return 0; } }
/** * Reads and discards a single field, given its tag value. * * @return {@code false} if the tag is an endgroup tag, in which case * nothing is skipped. Otherwise, returns {@code true}. */ public boolean skipField(int tag) throws IOException { switch (WireFormat.getTagWireType(tag)) { case WireFormat.WIRETYPE_VARINT: readInt32(); return true; case WireFormat.WIRETYPE_FIXED64: readRawLittleEndian64(); return true; case WireFormat.WIRETYPE_LENGTH_DELIMITED: skipRawBytes(readRawVarint32()); return true; case WireFormat.WIRETYPE_START_GROUP: skipMessage(); checkLastTagWas(WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); return true; case WireFormat.WIRETYPE_END_GROUP: return false; case WireFormat.WIRETYPE_FIXED32: readRawLittleEndian32(); return true; default: throw InvalidProtocolBufferException.invalidWireType(); } }
/** Read a raw Varint from the stream. */ public long readRawVarint64() throws IOException { int shift = 0; long result = 0; while (shift < 64) { byte b = readRawByte(); result |= (long) (b & 0x7F) << shift; if ((b & 0x80) == 0) return result; shift += 7; } throw InvalidProtocolBufferException.malformedVarint(); }
/** * Attempt to read a field tag, returning zero if we have reached EOF. * Protocol message parsers use this to read tags, since a protocol message * may legally end wherever a tag occurs, and zero is not a valid tag * number. */ public int readTag() throws IOException { if( pos >= limit ) { lastTag=0; return 0; } try { lastTag = readRawVarint32(); if (lastTag == 0) { // If we actually read zero, that's not a valid tag. throw InvalidProtocolBufferException.invalidTag(); } return lastTag; } catch (EOFException e) { lastTag=0; return 0; } }
/** * Reads and discards a single field, given its tag value. * * @return {@code false} if the tag is an endgroup tag, in which case * nothing is skipped. Otherwise, returns {@code true}. */ public boolean skipField(int tag) throws IOException { switch (WireFormat.getTagWireType(tag)) { case WireFormat.WIRETYPE_VARINT: readInt32(); return true; case WireFormat.WIRETYPE_FIXED64: readRawLittleEndian64(); return true; case WireFormat.WIRETYPE_LENGTH_DELIMITED: skipRawBytes(readRawVarint32()); return true; case WireFormat.WIRETYPE_START_GROUP: skipMessage(); checkLastTagWas(WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); return true; case WireFormat.WIRETYPE_END_GROUP: return false; case WireFormat.WIRETYPE_FIXED32: readRawLittleEndian32(); return true; default: throw InvalidProtocolBufferException.invalidWireType(); } }
static InvalidProtocolBufferException truncatedMessage() { 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 " + "misreported its own length."); }
/** Read a raw Varint from the stream. */ public long readRawVarint64() throws IOException { int shift = 0; long result = 0; while (shift < 64) { byte b = readRawByte(); result |= (long) (b & 0x7F) << shift; if ((b & 0x80) == 0) return result; shift += 7; } throw InvalidProtocolBufferException.malformedVarint(); }
/** * Verifies that the last call to readTag() returned the given tag value. * This is used to verify that a nested group ended with the correct end * tag. * * @throws InvalidProtocolBufferException * {@code value} does not match the last tag. */ public void checkLastTagWas(int value) throws InvalidProtocolBufferException { if (lastTag != value) { throw InvalidProtocolBufferException.invalidEndTag(); } }
/** * Attempt to read a field tag, returning zero if we have reached EOF. * Protocol message parsers use this to read tags, since a protocol message * may legally end wherever a tag occurs, and zero is not a valid tag * number. */ public int readTag() throws IOException { if( pos >= limit ) { lastTag=0; return 0; } try { lastTag = readRawVarint32(); if (lastTag == 0) { // If we actually read zero, that's not a valid tag. throw InvalidProtocolBufferException.invalidTag(); } return lastTag; } catch (EOFException e) { lastTag=0; return 0; } }
/** * Reads and discards a single field, given its tag value. * * @return {@code false} if the tag is an endgroup tag, in which case * nothing is skipped. Otherwise, returns {@code true}. */ public boolean skipField(int tag) throws IOException { switch (WireFormat.getTagWireType(tag)) { case WireFormat.WIRETYPE_VARINT: readInt32(); return true; case WireFormat.WIRETYPE_FIXED64: readRawLittleEndian64(); return true; case WireFormat.WIRETYPE_LENGTH_DELIMITED: skipRawBytes(readRawVarint32()); return true; case WireFormat.WIRETYPE_START_GROUP: skipMessage(); checkLastTagWas(WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP)); return true; case WireFormat.WIRETYPE_END_GROUP: return false; case WireFormat.WIRETYPE_FIXED32: readRawLittleEndian32(); return true; default: throw InvalidProtocolBufferException.invalidWireType(); } }
static InvalidProtocolBufferException sizeLimitExceeded() { return new InvalidProtocolBufferException("Protocol message was too large. May be malicious. " + "Use CodedInputStream.setSizeLimit() to increase the size limit."); } }
return result; throw InvalidProtocolBufferException.malformedVarint();
/** * Verifies that the last call to readTag() returned the given tag value. * This is used to verify that a nested group ended with the correct end * tag. * * @throws InvalidProtocolBufferException * {@code value} does not match the last tag. */ public void checkLastTagWas(int value) throws InvalidProtocolBufferException { if (lastTag != value) { throw InvalidProtocolBufferException.invalidEndTag(); } }
static InvalidProtocolBufferException sizeLimitExceeded() { return new InvalidProtocolBufferException("Protocol message was too large. May be malicious. " + "Use CodedInputStream.setSizeLimit() to increase the size limit."); } }
return result; throw InvalidProtocolBufferException.malformedVarint();
static InvalidProtocolBufferException sizeLimitExceeded() { return new InvalidProtocolBufferException("Protocol message was too large. May be malicious. " + "Use CodedInputStream.setSizeLimit() to increase the size limit."); } }
return result; throw InvalidProtocolBufferException.malformedVarint();