Пример #1
0
        protected override void AppendMessageHeaderCore(
            ILGenerator generator, ForEachLoop loop, MessageField field)
        {
            LocalBuilder length = generator.DeclareLocal(typeof(int));

            loop.Create(body => {
                body.Emit(OpCodes.Ldarg_1);
                loop.LoadCurrentAs(FieldType);
                field.AppendFieldLength(generator);
                body.Emit(OpCodes.Ldloc, length.LocalIndex);
                body.Emit(OpCodes.Add);
                body.Emit(OpCodes.Stloc, length.LocalIndex);
            });

            generator.Emit(OpCodes.Ldloc, length.LocalIndex);
            Label done = generator.DefineLabel();

            generator.Emit(OpCodes.Brfalse, done);

            generator.Emit(OpCodes.Ldarg_1);
            generator.Emit(OpCodes.Ldc_I4, MessageTag.AsInt(field.Number, WireType.String));
            generator.Call <MessageWriter>("WriteVarint", typeof(uint));
            generator.Emit(OpCodes.Ldloc, length.LocalIndex);
            generator.Call <MessageWriter>("WriteVarint", typeof(uint)).Pop();
            generator.MarkLabel(done);
        }
Пример #2
0
 public override void AppendWrite(ILGenerator il, MessageField field)
 {
     var loop = new ForEachLoop(il, property);
     AppendMessageHeaderCore(il, loop, field);
     loop.Create(body =>
     {
         field.AppendHeader(il);
         loop.LoadCurrentAs(FieldType);
         field.AppendWriteField(il);
         body.Emit(OpCodes.Pop);
     });
 }
Пример #3
0
        public override void AppendWrite(ILGenerator generator, MessageField field)
        {
            ForEachLoop loop = new ForEachLoop(generator, Property);

            AppendMessageHeaderCore(generator, loop, field);

            loop.Create(body => {
                field.AppendHeader(generator);
                loop.LoadCurrentAs(FieldType);
                field.AppendWriteField(generator);
                body.Emit(OpCodes.Pop);
            });
        }
Пример #4
0
		protected override void AppendMessageHeaderCore(
			ILGenerator generator, ForEachLoop loop, MessageField field)
		{
			LocalBuilder length = generator.DeclareLocal(typeof(int));
			loop.Create(body => {
				body.Emit(OpCodes.Ldarg_1);
				loop.LoadCurrentAs(FieldType);
				field.AppendFieldLength(generator);
				body.Emit(OpCodes.Ldloc, length.LocalIndex);
				body.Emit(OpCodes.Add);
				body.Emit(OpCodes.Stloc, length.LocalIndex);
			});

			generator.Emit(OpCodes.Ldloc, length.LocalIndex);
			Label done = generator.DefineLabel();
			generator.Emit(OpCodes.Brfalse, done);

			generator.Emit(OpCodes.Ldarg_1);
			generator.Emit(OpCodes.Ldc_I4, MessageTag.AsInt(field.Number, WireType.String));
			generator.Call<MessageWriter>("WriteVarint", typeof(uint));
			generator.Emit(OpCodes.Ldloc, length.LocalIndex);
			generator.Call<MessageWriter>("WriteVarint", typeof(uint)).Pop();
			generator.MarkLabel(done);
		}