Commit ef7091c9 authored by csharptest's avatar csharptest Committed by rogerk

Issue #54: should retire all bytes in buffer (bufferSize)

parent 30f73e2e
......@@ -10,6 +10,7 @@ _ReSharper.*
*.suo
*.bat
*.zip
*.DotSettings
build/*.log
BenchmarkResults.txt
......
......@@ -106,3 +106,12 @@ enum UnpackedTypesForeignEnumLite {
FOREIGN_LITE_BAR = 5;
FOREIGN_LITE_BAZ = 6;
}
message BucketOfBytes {
optional bytes value = 1;
}
message BucketOfBytesEx {
optional bytes value = 1;
optional bytes value2 = 255;
}
\ No newline at end of file
......@@ -1780,7 +1780,11 @@ namespace Google.ProtocolBuffers
{
// Skipping more bytes than are in the buffer. First skip what we have.
int pos = bufferSize - bufferPos;
totalBytesRetired += pos;
// ROK 5/7/2013 Issue #54: should retire all bytes in buffer (bufferSize)
// totalBytesRetired += pos;
totalBytesRetired += bufferSize;
bufferPos = 0;
bufferSize = 0;
......
......@@ -305,5 +305,32 @@ namespace Google.ProtocolBuffers
copy = msg.DefaultInstanceForType.ToBuilder().MergeFrom(msg).Build();
TestUtil.AssertBytesEqual(msg.ToByteArray(), copy.ToByteArray());
}
// ROK 5/7/2013 Issue #54: should retire all bytes in buffer (bufferSize)
[TestMethod]
public void TestBufferRefillIssue()
{
var ms = new MemoryStream();
BucketOfBytes.CreateBuilder()
.SetValue(ByteString.CopyFrom(new byte[3000]))
.Build().WriteDelimitedTo(ms);
BucketOfBytesEx.CreateBuilder()
.SetValue(ByteString.CopyFrom(new byte[1000]))
.SetValue2(ByteString.CopyFrom(new byte[1100]))
.Build().WriteDelimitedTo(ms);
BucketOfBytes.CreateBuilder()
.SetValue(ByteString.CopyFrom(new byte[100]))
.Build().WriteDelimitedTo(ms);
ms.Position = 0;
var input = CodedInputStream.CreateInstance(ms);
var builder = BucketOfBytes.CreateBuilder();
input.ReadMessage(builder, ExtensionRegistry.Empty);
Assert.AreEqual(3000, builder.Value.Length);
input.ReadMessage(builder, ExtensionRegistry.Empty);
Assert.AreEqual(1000, builder.Value.Length);
input.ReadMessage(builder, ExtensionRegistry.Empty);
Assert.AreEqual(100, builder.Value.Length);
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment