internal static void WriteHeaderCore(int fieldNumber, WireType wireType, ProtoWriter writer, ref State state) { uint header = (((uint)fieldNumber) << 3) | (((uint)wireType) & 7); int bytes = writer.ImplWriteVarint32(ref state, header); writer.Advance(bytes); }
/// <summary> /// Copies any extension data stored for the instance to the underlying stream /// </summary> public static void AppendExtensionData(IExtensible instance, ProtoWriter writer, ref State state) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } if (writer == null) { throw new ArgumentNullException(nameof(writer)); } // we expect the writer to be raw here; the extension data will have the // header detail, so we'll copy it implicitly if (writer.WireType != WireType.None) { throw CreateException(writer); } IExtension extn = instance.GetExtensionObject(false); if (extn != null) { // unusually we *don't* want "using" here; the "finally" does that, with // the extension object being responsible for disposal etc Stream source = extn.BeginQuery(); try { if (ProtoReader.TryConsumeSegmentRespectingPosition(source, out var data, ProtoReader.TO_EOF)) { writer.ImplWriteBytes(ref state, data.Array, data.Offset, data.Count); writer.Advance(data.Count); } else { writer.ImplCopyRawFromStream(ref state, source); } }