private DynamicMethod EmitDecode(bool doNoCheckBounds) { const int codecContainerArgIndex = 0; const int dataArgIndex = 1; const int remainingBytesArgIndex = 2; var dynamicMethod = new DynamicMethod("_decode_manual_" + type.FullName + (doNoCheckBounds ? "_dncb_" : ""), type, new[] { typeof(ICodecContainer), typeof(byte *).MakeByRefType(), typeof(int).MakeByRefType() }, Assembly.GetExecutingAssembly().ManifestModule, true); var il = new MyILGenerator(dynamicMethod.GetILGenerator()); var context = new ManualCodecEmittingContext(il, codecContainerArgIndex); il.Ldarg(dataArgIndex); il.Ldind_I(); il.Stloc(context.DataPointerVar); il.Ldarg(remainingBytesArgIndex); il.Ldind_I4(); il.Stloc(context.RemainingBytesVar); emittingCodec.EmitDecode(context, doNoCheckBounds); il.Ldarg(dataArgIndex); il.Ldloc(context.DataPointerVar); il.Stind_I(); il.Ldarg(remainingBytesArgIndex); il.Ldloc(context.RemainingBytesVar); il.Stind_I4(); il.Ret(); return(dynamicMethod); }
private DynamicMethod EmitEncode() { const int codecContainerArgIndex = 0; const int dataArgIndex = 1; const int valueArgIndex = 2; var dynamicMethod = new DynamicMethod("_encode_manual_" + type.FullName, typeof(void), new[] { typeof(ICodecContainer), typeof(byte *).MakeByRefType(), type }, Assembly.GetExecutingAssembly().ManifestModule, true); var il = new MyILGenerator(dynamicMethod.GetILGenerator()); var context = new ManualCodecEmittingContext(il, codecContainerArgIndex); il.Ldarg(dataArgIndex); il.Ldind_I(); il.Stloc(context.DataPointerVar); emittingCodec.EmitEncode(context, valueArgIndex); il.Ldarg(dataArgIndex); il.Ldloc(context.DataPointerVar); il.Stind_I(); il.Ret(); return(dynamicMethod); }