public void ResetSizeCounter() { CodedInputStream input = CodedInputStream.CreateInstance( new SmallBlockInputStream(new byte[256], 8)); input.SetSizeLimit(16); input.ReadRawBytes(16); try { input.ReadRawByte(); Assert.Fail("Should have thrown an exception!"); } catch (InvalidProtocolBufferException) { // Success. } input.ResetSizeCounter(); input.ReadRawByte(); // No exception thrown. try { input.ReadRawBytes(16); // Hits limit again. Assert.Fail("Should have thrown an exception!"); } catch (InvalidProtocolBufferException) { // Success. } }
public IEnumerator <TMessage> GetEnumerator() { using (Stream stream = streamProvider()) { CodedInputStream input = CodedInputStream.CreateInstance(stream); input.SetSizeLimit(sizeLimit); uint tag; string name; while (input.ReadTag(out tag, out name)) { if ((tag == 0 && name == "item") || (tag == ExpectedTag)) { IBuilder builder = defaultMessageInstance.WeakCreateBuilderForType(); input.ReadMessage(builder, extensionRegistry); yield return((TMessage)builder.WeakBuild()); } else { throw InvalidProtocolBufferException.InvalidMessageStreamTag(); } input.ResetSizeCounter(); } } }
public void SizeLimit() { // Have to use a Stream rather than ByteString.CreateCodedInput as SizeLimit doesn't // apply to the latter case. MemoryStream ms = new MemoryStream(TestUtil.GetAllSet().ToByteString().ToByteArray()); CodedInputStream input = CodedInputStream.CreateInstance(ms); input.SetSizeLimit(16); Assert.Throws <InvalidProtocolBufferException>(() => TestAllTypes.ParseFrom(input)); }
public void ResetSizeCounter() { CodedInputStream input = CodedInputStream.CreateInstance( new SmallBlockInputStream(new byte[256], 8)); input.SetSizeLimit(16); input.ReadRawBytes(16); Assert.Throws <InvalidProtocolBufferException>(() => input.ReadRawByte()); input.ResetSizeCounter(); input.ReadRawByte(); // No exception thrown. Assert.Throws <InvalidProtocolBufferException>(() => input.ReadRawBytes(16)); }
public void SizeLimit() { // Have to use a Stream rather than ByteString.CreateCodedInput as SizeLimit doesn't // apply to the latter case. MemoryStream ms = new MemoryStream(TestUtil.GetAllSet().ToByteString().ToByteArray()); CodedInputStream input = CodedInputStream.CreateInstance(ms); input.SetSizeLimit(16); try { TestAllTypes.ParseFrom(input); Assert.Fail("Should have thrown an exception!"); } catch (InvalidProtocolBufferException) { // success. } }
public IEnumerator <TMessage> GetEnumerator() { using (Stream stream = streamProvider()) { CodedInputStream input = CodedInputStream.CreateInstance(stream); input.SetSizeLimit(sizeLimit); uint tag; while ((tag = input.ReadTag()) != 0) { if (tag != ExpectedTag) { throw InvalidProtocolBufferException.InvalidMessageStreamTag(); } yield return(messageReader(input, extensionRegistry)); input.ResetSizeCounter(); } } }