public WriteFixed32 ( uint value ) : void | ||
value | uint | The value to write |
return | void |
/// <summary> /// Serializes the field, including the field number, and writes it to /// <paramref name="output"/> /// </summary> /// <param name="fieldNumber">The unknown field number.</param> /// <param name="output">The CodedOutputStream to write to.</param> internal void WriteTo(int fieldNumber, CodedOutputStream output) { if (varintList != null) { foreach (ulong value in varintList) { output.WriteTag(fieldNumber, WireFormat.WireType.Varint); output.WriteUInt64(value); } } if (fixed32List != null) { foreach (uint value in fixed32List) { output.WriteTag(fieldNumber, WireFormat.WireType.Fixed32); output.WriteFixed32(value); } } if (fixed64List != null) { foreach (ulong value in fixed64List) { output.WriteTag(fieldNumber, WireFormat.WireType.Fixed64); output.WriteFixed64(value); } } if (lengthDelimitedList != null) { foreach (ByteString value in lengthDelimitedList) { output.WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited); output.WriteBytes(value); } } }
public void SkipGroup_WrongEndGroupTag() { // Create an output stream with: // Field 1: string "field 1" // Start group 2 // Field 3: fixed int32 // End group 4 (should give an error) var stream = new MemoryStream(); var output = new CodedOutputStream(stream); output.WriteTag(1, WireFormat.WireType.LengthDelimited); output.WriteString("field 1"); // The outer group... output.WriteTag(2, WireFormat.WireType.StartGroup); output.WriteTag(3, WireFormat.WireType.Fixed32); output.WriteFixed32(100); output.WriteTag(4, WireFormat.WireType.EndGroup); output.Flush(); stream.Position = 0; // Now act like a generated client var input = new CodedInputStream(stream); Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited), input.ReadTag()); Assert.AreEqual("field 1", input.ReadString()); Assert.AreEqual(WireFormat.MakeTag(2, WireFormat.WireType.StartGroup), input.ReadTag()); Assert.Throws <InvalidProtocolBufferException>(input.SkipLastField); }
public void ExtraEndGroupThrows() { var stream = new MemoryStream(); var output = new CodedOutputStream(stream); output.WriteTag(TestAllTypes.SingleFixed32FieldNumber, WireFormat.WireType.Fixed32); output.WriteFixed32(123); output.WriteTag(100, WireFormat.WireType.EndGroup); output.Flush(); stream.Position = 0; MessageParsingHelpers.AssertReadingMessageThrows <TestAllTypes, InvalidProtocolBufferException>(TestAllTypes.Parser, stream.ToArray()); }
public void ExtraEndGroupThrows() { var message = SampleMessages.CreateFullTestAllTypes(); var stream = new MemoryStream(); var output = new CodedOutputStream(stream); output.WriteTag(TestAllTypes.SingleFixed32FieldNumber, WireFormat.WireType.Fixed32); output.WriteFixed32(123); output.WriteTag(100, WireFormat.WireType.EndGroup); output.Flush(); stream.Position = 0; Assert.Throws <IOException>(() => TestAllTypes.Parser.ParseFrom(stream)); }
public void SkipGroup() { // Create an output stream with a group in: // Field 1: string "field 1" // Field 2: group containing: // Field 1: fixed int32 value 100 // Field 2: string "ignore me" // Field 3: nested group containing // Field 1: fixed int64 value 1000 // Field 3: string "field 3" var stream = new MemoryStream(); var output = new CodedOutputStream(stream); output.WriteTag(1, WireFormat.WireType.LengthDelimited); output.WriteString("field 1"); // The outer group... output.WriteTag(2, WireFormat.WireType.StartGroup); output.WriteTag(1, WireFormat.WireType.Fixed32); output.WriteFixed32(100); output.WriteTag(2, WireFormat.WireType.LengthDelimited); output.WriteString("ignore me"); // The nested group... output.WriteTag(3, WireFormat.WireType.StartGroup); output.WriteTag(1, WireFormat.WireType.Fixed64); output.WriteFixed64(1000); // Note: Not sure the field number is relevant for end group... output.WriteTag(3, WireFormat.WireType.EndGroup); // End the outer group output.WriteTag(2, WireFormat.WireType.EndGroup); output.WriteTag(3, WireFormat.WireType.LengthDelimited); output.WriteString("field 3"); output.Flush(); stream.Position = 0; // Now act like a generated client var input = new CodedInputStream(stream); Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited), input.ReadTag()); Assert.AreEqual("field 1", input.ReadString()); Assert.AreEqual(WireFormat.MakeTag(2, WireFormat.WireType.StartGroup), input.ReadTag()); input.SkipLastField(); // Should consume the whole group, including the nested one. Assert.AreEqual(WireFormat.MakeTag(3, WireFormat.WireType.LengthDelimited), input.ReadTag()); Assert.AreEqual("field 3", input.ReadString()); }
public void ExtraEndGroupSkipped() { var message = SampleMessages.CreateFullTestAllTypes(); var stream = new MemoryStream(); var output = new CodedOutputStream(stream); output.WriteTag(100, WireFormat.WireType.EndGroup); output.WriteTag(TestAllTypes.SingleFixed32FieldNumber, WireFormat.WireType.Fixed32); output.WriteFixed32(123); output.Flush(); stream.Position = 0; var parsed = TestAllTypes.Parser.ParseFrom(stream); Assert.AreEqual(new TestAllTypes { SingleFixed32 = 123 }, parsed); }
public void ExtraEndGroupThrows() { var message = SampleMessages.CreateFullTestAllTypes(); var stream = new MemoryStream(); var output = new CodedOutputStream(stream); output.WriteTag(TestAllTypes.SingleFixed32FieldNumber, WireFormat.WireType.Fixed32); output.WriteFixed32(123); output.WriteTag(100, WireFormat.WireType.EndGroup); output.Flush(); stream.Position = 0; Assert.Throws<InvalidProtocolBufferException>(() => TestAllTypes.Parser.ParseFrom(stream)); }
public void SkipGroup_WrongEndGroupTag() { // Create an output stream with: // Field 1: string "field 1" // Start group 2 // Field 3: fixed int32 // End group 4 (should give an error) var stream = new MemoryStream(); var output = new CodedOutputStream(stream); output.WriteTag(1, WireFormat.WireType.LengthDelimited); output.WriteString("field 1"); // The outer group... output.WriteTag(2, WireFormat.WireType.StartGroup); output.WriteTag(3, WireFormat.WireType.Fixed32); output.WriteFixed32(100); output.WriteTag(4, WireFormat.WireType.EndGroup); output.Flush(); stream.Position = 0; // Now act like a generated client var input = new CodedInputStream(stream); Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited), input.ReadTag()); Assert.AreEqual("field 1", input.ReadString()); Assert.AreEqual(WireFormat.MakeTag(2, WireFormat.WireType.StartGroup), input.ReadTag()); Assert.Throws<InvalidProtocolBufferException>(input.SkipLastField); }
public void SkipGroup() { // Create an output stream with a group in: // Field 1: string "field 1" // Field 2: group containing: // Field 1: fixed int32 value 100 // Field 2: string "ignore me" // Field 3: nested group containing // Field 1: fixed int64 value 1000 // Field 3: string "field 3" var stream = new MemoryStream(); var output = new CodedOutputStream(stream); output.WriteTag(1, WireFormat.WireType.LengthDelimited); output.WriteString("field 1"); // The outer group... output.WriteTag(2, WireFormat.WireType.StartGroup); output.WriteTag(1, WireFormat.WireType.Fixed32); output.WriteFixed32(100); output.WriteTag(2, WireFormat.WireType.LengthDelimited); output.WriteString("ignore me"); // The nested group... output.WriteTag(3, WireFormat.WireType.StartGroup); output.WriteTag(1, WireFormat.WireType.Fixed64); output.WriteFixed64(1000); // Note: Not sure the field number is relevant for end group... output.WriteTag(3, WireFormat.WireType.EndGroup); // End the outer group output.WriteTag(2, WireFormat.WireType.EndGroup); output.WriteTag(3, WireFormat.WireType.LengthDelimited); output.WriteString("field 3"); output.Flush(); stream.Position = 0; // Now act like a generated client var input = new CodedInputStream(stream); Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited), input.ReadTag()); Assert.AreEqual("field 1", input.ReadString()); Assert.AreEqual(WireFormat.MakeTag(2, WireFormat.WireType.StartGroup), input.ReadTag()); input.SkipLastField(); // Should consume the whole group, including the nested one. Assert.AreEqual(WireFormat.MakeTag(3, WireFormat.WireType.LengthDelimited), input.ReadTag()); Assert.AreEqual("field 3", input.ReadString()); }
public void ExtraEndGroupSkipped() { var message = SampleMessages.CreateFullTestAllTypes(); var stream = new MemoryStream(); var output = new CodedOutputStream(stream); output.WriteTag(100, WireFormat.WireType.EndGroup); output.WriteTag(TestAllTypes.SingleFixed32FieldNumber, WireFormat.WireType.Fixed32); output.WriteFixed32(123); output.Flush(); stream.Position = 0; var parsed = TestAllTypes.Parser.ParseFrom(stream); Assert.AreEqual(new TestAllTypes { SingleFixed32 = 123 }, parsed); }
internal void <ForFixed32> b__5_1(CodedOutputStream output, uint value) { output.WriteFixed32(value); }