public void TestRoundTripRaw() { var stream = new MemoryStream(); var codedOutput = new CodedOutputStream(stream); codec.ValueWriter(codedOutput, sampleValue); codedOutput.Flush(); stream.Position = 0; var codedInput = new CodedInputStream(stream); Assert.AreEqual(sampleValue, codec.Read(codedInput)); Assert.IsTrue(codedInput.IsAtEnd); }
internal static T Read <T>(CodedInputStream input, FieldCodec <T> codec) { int length = input.ReadLength(); int oldLimit = input.PushLimit(length); uint tag; T value = codec.DefaultValue; while (input.ReadTag(out tag)) { if (tag == 0) { throw InvalidProtocolBufferException.InvalidTag(); } if (tag == codec.Tag) { value = codec.Read(input); } if (WireFormat.IsEndGroupTag(tag)) { break; } } input.CheckLastTagWas(0); input.PopLimit(oldLimit); return(value); }
public void TestRoundTripRaw() { var stream = new MemoryStream(); var codedOutput = new CodedOutputStream(stream); WriteContext.Initialize(codedOutput, out WriteContext ctx); try { // only write the value using the codec codec.ValueWriter(ref ctx, sampleValue); } finally { ctx.CopyStateTo(codedOutput); } codedOutput.Flush(); stream.Position = 0; var codedInput = new CodedInputStream(stream); Assert.AreEqual(sampleValue, codec.Read(codedInput)); Assert.IsTrue(codedInput.IsAtEnd); }
public void TestRoundTripWithTag() { var stream = new MemoryStream(); var codedOutput = CodedOutputStream.CreateInstance(stream); codec.WriteTagAndValue(codedOutput, sampleValue); codedOutput.Flush(); stream.Position = 0; var codedInput = CodedInputStream.CreateInstance(stream); codedInput.AssertNextTag(codec.Tag); Assert.AreEqual(sampleValue, codec.Read(codedInput)); Assert.IsTrue(codedInput.IsAtEnd); }
internal static T Read <T>(CodedInputStream input, FieldCodec <T> codec) { int length = input.ReadLength(); int oldLimit = input.PushLimit(length); uint tag; T value = codec.DefaultValue; while ((tag = input.ReadTag()) != 0) { if (tag == codec.Tag) { value = codec.Read(input); } else { input.SkipLastField(); } } input.CheckReadEndOfStreamTag(); input.PopLimit(oldLimit); return(value); }
internal static T Read <T>(ref ParseContext ctx, FieldCodec <T> codec) { int length = ctx.ReadLength(); int oldLimit = SegmentedBufferHelper.PushLimit(ref ctx.state, length); uint tag; T value = codec.DefaultValue; while ((tag = ctx.ReadTag()) != 0) { if (tag == codec.Tag) { value = codec.Read(ref ctx); } else { ParsingPrimitivesMessages.SkipLastField(ref ctx.buffer, ref ctx.state); } } ParsingPrimitivesMessages.CheckReadEndOfStreamTag(ref ctx.state); SegmentedBufferHelper.PopLimit(ref ctx.state, oldLimit); return(value); }
internal static T Read <T>(CodedInputStream input, FieldCodec <T> codec) { int byteLimit = input.ReadLength(); T result; while (true) { IL_FA: uint arg_C8_0 = 1476935752u; while (true) { uint num; switch ((num = (arg_C8_0 ^ 2018772964u)) % 9u) { case 0u: input.SkipLastField(); arg_C8_0 = 1768391466u; continue; case 1u: { uint num2; arg_C8_0 = (((num2 = input.ReadTag()) == 0u) ? 789788880u : 1000495088u); continue; } case 3u: arg_C8_0 = (num * 422428889u ^ 15908708u); continue; case 4u: result = codec.Read(input); arg_C8_0 = (num * 2015424451u ^ 1456283564u); continue; case 5u: { uint num2; arg_C8_0 = ((num2 == codec.Tag) ? 627669222u : 345821031u); continue; } case 6u: { input.CheckReadEndOfStreamTag(); int oldLimit; input.PopLimit(oldLimit); arg_C8_0 = (num * 1368242210u ^ 1133084529u); continue; } case 7u: { int oldLimit = input.PushLimit(byteLimit); result = codec.DefaultValue; arg_C8_0 = (num * 2466023856u ^ 3651674u); continue; } case 8u: goto IL_FA; } return(result); } } return(result); }