Esempio n. 1
0
        void ProtoBuf.Serializers.IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
        {
            ProtoTypeCode typeCode = this.GetTypeCode();

            if (this.map == null)
            {
                ctx.LoadValue(valueFrom);
                ctx.ConvertToInt32(typeCode, false);
                ctx.EmitBasicWrite("WriteInt32", null);
                return;
            }
            using (Local localWithValue = ctx.GetLocalWithValue(this.ExpectedType, valueFrom))
            {
                CodeLabel codeLabel = ctx.DefineLabel();
                for (int i = 0; i < (int)this.map.Length; i++)
                {
                    CodeLabel codeLabel1 = ctx.DefineLabel();
                    CodeLabel codeLabel2 = ctx.DefineLabel();
                    ctx.LoadValue(localWithValue);
                    EnumSerializer.WriteEnumValue(ctx, typeCode, this.map[i].RawValue);
                    ctx.BranchIfEqual(codeLabel2, true);
                    ctx.Branch(codeLabel1, true);
                    ctx.MarkLabel(codeLabel2);
                    ctx.LoadValue(this.map[i].WireValue);
                    ctx.EmitBasicWrite("WriteInt32", null);
                    ctx.Branch(codeLabel, false);
                    ctx.MarkLabel(codeLabel1);
                }
                ctx.LoadReaderWriter();
                ctx.LoadValue(localWithValue);
                ctx.CastToObject(this.ExpectedType);
                ctx.EmitCall(ctx.MapType(typeof(ProtoWriter)).GetMethod("ThrowEnumException"));
                ctx.MarkLabel(codeLabel);
            }
        }
Esempio n. 2
0
        void ProtoBuf.Serializers.IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
        {
            Type expectedType = this.ExpectedType;

            if (!expectedType.IsValueType)
            {
                ctx.EmitCall(ctx.MapType(typeof(object)).GetMethod("ToString"));
            }
            else
            {
                using (Local localWithValue = ctx.GetLocalWithValue(expectedType, valueFrom))
                {
                    ctx.LoadAddress(localWithValue, expectedType);
                    ctx.EmitCall(ParseableSerializer.GetCustomToString(expectedType));
                }
            }
            ctx.EmitBasicWrite("WriteString", valueFrom);
        }
Esempio n. 3
0
 void ProtoBuf.Serializers.IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
 {
     ctx.EmitBasicWrite("WriteBoolean", valueFrom);
 }
Esempio n. 4
0
 void IProtoSerializer.EmitWrite(CompilerContext ctx, Local valueFrom)
 {
     ctx.EmitBasicWrite("WriteSByte", valueFrom);
 }