aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/Google.Protobuf
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/Google.Protobuf')
-rw-r--r--csharp/src/Google.Protobuf/CodedInputStream.cs62
-rw-r--r--csharp/src/Google.Protobuf/Reflection/DescriptorProtoFile.cs22
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/Any.cs1
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/Api.cs2
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs1
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs1
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs1
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs1
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs3
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs1
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/Type.cs5
-rw-r--r--csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs9
12 files changed, 109 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf/CodedInputStream.cs b/csharp/src/Google.Protobuf/CodedInputStream.cs
index a1abfcb0..5da03b5c 100644
--- a/csharp/src/Google.Protobuf/CodedInputStream.cs
+++ b/csharp/src/Google.Protobuf/CodedInputStream.cs
@@ -54,13 +54,37 @@ namespace Google.Protobuf
/// </remarks>
public sealed class CodedInputStream
{
+ /// <summary>
+ /// Buffer of data read from the stream or provided at construction time.
+ /// </summary>
private readonly byte[] buffer;
+
+ /// <summary>
+ /// The number of valid bytes in the buffer.
+ /// </summary>
private int bufferSize;
+
private int bufferSizeAfterLimit = 0;
+ /// <summary>
+ /// The position within the current buffer (i.e. the next byte to read)
+ /// </summary>
private int bufferPos = 0;
+
+ /// <summary>
+ /// The stream to read further input from, or null if the byte array buffer was provided
+ /// directly on construction, with no further data available.
+ /// </summary>
private readonly Stream input;
+
+ /// <summary>
+ /// The last tag we read. 0 indicates we've read to the end of the stream
+ /// (or haven't read anything yet).
+ /// </summary>
private uint lastTag = 0;
+ /// <summary>
+ /// The next tag, used to store the value read by PeekTag.
+ /// </summary>
private uint nextTag = 0;
private bool hasNextTag = false;
@@ -309,6 +333,39 @@ namespace Google.Protobuf
}
/// <summary>
+ /// Consumes the data for the field with the tag we've just read.
+ /// This should be called directly after <see cref="ReadTag"/>, when
+ /// the caller wishes to skip an unknown field.
+ /// </summary>
+ public void ConsumeLastField()
+ {
+ if (lastTag == 0)
+ {
+ throw new InvalidOperationException("ConsumeLastField cannot be called at the end of a stream");
+ }
+ switch (WireFormat.GetTagWireType(lastTag))
+ {
+ case WireFormat.WireType.StartGroup:
+ case WireFormat.WireType.EndGroup:
+ // TODO: Work out how to skip them instead? See issue 688.
+ throw new InvalidProtocolBufferException("Group tags not supported by proto3 C# implementation");
+ case WireFormat.WireType.Fixed32:
+ ReadFixed32();
+ break;
+ case WireFormat.WireType.Fixed64:
+ ReadFixed64();
+ break;
+ case WireFormat.WireType.LengthDelimited:
+ var length = ReadLength();
+ SkipRawBytes(length);
+ break;
+ case WireFormat.WireType.Varint:
+ ReadRawVarint32();
+ break;
+ }
+ }
+
+ /// <summary>
/// Reads a double field from the stream.
/// </summary>
public double ReadDouble()
@@ -423,6 +480,11 @@ namespace Google.Protobuf
++recursionDepth;
builder.MergeFrom(this);
CheckLastTagWas(0);
+ // Check that we've read exactly as much data as expected.
+ if (!ReachedLimit)
+ {
+ throw InvalidProtocolBufferException.TruncatedMessage();
+ }
--recursionDepth;
PopLimit(oldLimit);
}
diff --git a/csharp/src/Google.Protobuf/Reflection/DescriptorProtoFile.cs b/csharp/src/Google.Protobuf/Reflection/DescriptorProtoFile.cs
index e40472cb..a12e70f8 100644
--- a/csharp/src/Google.Protobuf/Reflection/DescriptorProtoFile.cs
+++ b/csharp/src/Google.Protobuf/Reflection/DescriptorProtoFile.cs
@@ -247,6 +247,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
file_.AddEntriesFrom(input, _repeated_file_codec);
@@ -545,6 +546,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
@@ -840,6 +842,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
@@ -1008,6 +1011,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
Start = input.ReadInt32();
@@ -1140,6 +1144,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
Start = input.ReadInt32();
@@ -1434,6 +1439,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
@@ -1608,6 +1614,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
@@ -1753,6 +1760,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
@@ -1917,6 +1925,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
@@ -2073,6 +2082,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
@@ -2303,6 +2313,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
@@ -2732,6 +2743,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
JavaPackage = input.ReadString();
@@ -2986,6 +2998,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
MessageSetWireFormat = input.ReadBool();
@@ -3232,6 +3245,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
ctype_ = (global::Google.Protobuf.Reflection.FieldOptions.Types.CType) input.ReadEnum();
@@ -3416,6 +3430,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 16: {
AllowAlias = input.ReadBool();
@@ -3544,6 +3559,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
Deprecated = input.ReadBool();
@@ -3668,6 +3684,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 264: {
Deprecated = input.ReadBool();
@@ -3792,6 +3809,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 264: {
Deprecated = input.ReadBool();
@@ -4026,6 +4044,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 18: {
name_.AddEntriesFrom(input, _repeated_name_codec);
@@ -4179,6 +4198,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
NamePart_ = input.ReadString();
@@ -4286,6 +4306,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
location_.AddEntriesFrom(input, _repeated_location_codec);
@@ -4457,6 +4478,7 @@ namespace Google.Protobuf.Reflection {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10:
case 8: {
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
index 93395871..4352c16a 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
@@ -155,6 +155,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
TypeUrl = input.ReadString();
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
index 366bba21..a5d48166 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
@@ -218,6 +218,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
@@ -445,6 +446,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs
index 26c8d2b6..1ca33dce 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs
@@ -156,6 +156,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
Seconds = input.ReadInt64();
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs
index e14992f4..0d948e38 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs
@@ -111,6 +111,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
}
}
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
index 45ef9859..58dbc7fa 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
@@ -125,6 +125,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
paths_.AddEntriesFrom(input, _repeated_paths_codec);
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs
index 04fb6350..5566b5ce 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs
@@ -134,6 +134,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
FileName = input.ReadString();
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
index 15dd6dcd..72bd16d4 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
@@ -144,6 +144,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
fields_.AddEntriesFrom(input, _map_fields_codec);
@@ -398,6 +399,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
kind_ = input.ReadEnum();
@@ -527,6 +529,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
values_.AddEntriesFrom(input, _repeated_values_codec);
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
index 3c42068a..c3e5383e 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
@@ -156,6 +156,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
Seconds = input.ReadInt64();
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
index 64142934..862caf82 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
@@ -231,6 +231,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
@@ -502,6 +503,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
kind_ = (global::Google.Protobuf.WellKnownTypes.Field.Types.Kind) input.ReadEnum();
@@ -723,6 +725,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
@@ -880,6 +883,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
@@ -1019,6 +1023,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Name = input.ReadString();
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs
index c9dd6ea6..2b3814cc 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs
@@ -143,6 +143,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 9: {
Value = input.ReadDouble();
@@ -249,6 +250,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 13: {
Value = input.ReadFloat();
@@ -355,6 +357,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
Value = input.ReadInt64();
@@ -461,6 +464,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
Value = input.ReadUInt64();
@@ -567,6 +571,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
Value = input.ReadInt32();
@@ -673,6 +678,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
Value = input.ReadUInt32();
@@ -779,6 +785,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 8: {
Value = input.ReadBool();
@@ -885,6 +892,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Value = input.ReadString();
@@ -991,6 +999,7 @@ namespace Google.Protobuf.WellKnownTypes {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return;
}
+ input.ConsumeLastField();
break;
case 10: {
Value = input.ReadBytes();