public void IntermixingOfNewAndLegacyGeneratedCodeWorksWithCodedInputStream() { var message = new ParseContextEnabledMessageB { A = new LegacyGeneratedCodeMessageA { Bb = new ParseContextEnabledMessageB { OptionalInt32 = 12345 } }, OptionalInt32 = 6789 }; var data = message.ToByteArray(); // when parsing started using CodedInputStream and a message with legacy generated code // is encountered somewhere in the parse tree, we still need to be able to use its // MergeFrom(CodedInputStream) method to parse correctly. var codedInput = new CodedInputStream(data); var parsed = new ParseContextEnabledMessageB(); codedInput.ReadRawMessage(parsed); Assert.IsTrue(codedInput.IsAtEnd); Assert.AreEqual(12345, parsed.A.Bb.OptionalInt32); Assert.AreEqual(6789, parsed.OptionalInt32); }
public void IntermixingOfNewAndLegacyGeneratedCodeWorksWithCodedOutputStream() { // when serialization started using CodedOutputStream and a message with legacy generated code // is encountered somewhere in the parse tree, we still need to be able to use its // WriteTo(CodedOutputStream) method to serialize correctly. var ms = new MemoryStream(); var codedOutput = new CodedOutputStream(ms); var message = new ParseContextEnabledMessageB { A = new LegacyGeneratedCodeMessageA { Bb = new ParseContextEnabledMessageB { OptionalInt32 = 12345 } }, OptionalInt32 = 6789 }; message.WriteTo(codedOutput); codedOutput.Flush(); var codedInput = new CodedInputStream(ms.ToArray()); var parsed = new ParseContextEnabledMessageB(); codedInput.ReadRawMessage(parsed); Assert.IsTrue(codedInput.IsAtEnd); Assert.AreEqual(12345, parsed.A.Bb.OptionalInt32); Assert.AreEqual(6789, parsed.OptionalInt32); }
public void MergeFrom(pb.CodedInputStream input) { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE input.ReadRawMessage(this); #else uint tag; while ((tag = input.ReadTag()) != 0) { switch (tag) { default: _unknownFields = pb.UnknownFieldSet.MergeFieldFrom(_unknownFields, input); break; case 10: { ClientId = input.ReadString(); break; } case 18: { MessageId = input.ReadString(); break; } case 24: { Type = (MessageType)input.ReadEnum(); break; } case 34: { if (time_ == null) { Time = new global.Google.Protobuf.WellKnownTypes.Timestamp(); } input.ReadMessage(Time); break; } case 40: { Status = (MessageStatus)input.ReadEnum(); break; } case 50: { Payload = input.ReadBytes(); break; } case 56: { Response = (ResponseType)input.ReadEnum(); break; } } } #endif }