Exemple #1
0
 public EnumFormatterImplementor(TypeProvider provider)
 {
     this.module        = provider.Module;
     this.writerHelper  = provider.MessagePackWriterHelper;
     this.readerHelper  = provider.MessagePackReaderHelper;
     this.importer      = provider.Importer;
     this.optionsHelper = provider.MessagePackSerializerOptionsHelper;
     this.provider      = provider;
 }
Exemple #2
0
 public UnionInterfaceFormatterAllConsequentImplementor(ModuleDefinition module, SystemObjectHelper objectHelper, InterfaceMessagePackFormatterHelper interfaceMessagePackFormatterHelper, SystemInvalidOperationExceptionHelper invalidOperationExceptionHelper, ModuleImporter importer, MessagePackSecurityHelper securityHelper, MessagePackSerializerOptionsHelper messagePackSerializerOptionsHelper, MessagePackWriterHelper writerHelper, MessagePackReaderHelper readerHelper, FormatterResolverExtensionHelper formatterResolverExtensionHelper, FixedTypeKeyInt32ValueHashtableGenerator generator)
 {
     this.module       = module;
     this.objectHelper = objectHelper;
     this.interfaceMessagePackFormatterHelper = interfaceMessagePackFormatterHelper;
     this.invalidOperationExceptionHelper     = invalidOperationExceptionHelper;
     this.importer       = importer;
     this.securityHelper = securityHelper;
     this.messagePackSerializerOptionsHelper = messagePackSerializerOptionsHelper;
     this.writerHelper = writerHelper;
     this.readerHelper = readerHelper;
     this.formatterResolverExtensionHelper = formatterResolverExtensionHelper;
     this.generator = generator;
 }
Exemple #3
0
        public static Instruction[] DeserializeFixedSizeBuffer(VariableDefinition targetVariable, FieldDefinition fixedField, ModuleDefinition module, MessagePackReaderHelper reader, ModuleImporter importer, SystemInvalidOperationExceptionHelper invalidOperationExceptionHelper, FixedSizeBufferElementType elementType, int count)
        {
            var same   = Instruction.Create(OpCodes.Ldloca_S, targetVariable);
            var read   = reader.ReadMessagePackPrimitive(GetType(module, elementType));
            var stride = SizeOf(elementType);

            switch (count)
            {
            case 1:
                return(new[]
                {
                    Instruction.Create(OpCodes.Ldarg_1),
                    Instruction.Create(OpCodes.Call, reader.ReadArrayHeader),
                    InstructionUtility.LdcI4(count),
                    Instruction.Create(OpCodes.Beq_S, same),
                    Instruction.Create(OpCodes.Ldstr, "Fixed size buffer field should have " + count.ToString(CultureInfo.InvariantCulture) + " element(s)."),
                    Instruction.Create(OpCodes.Newobj, invalidOperationExceptionHelper.Ctor),
                    Instruction.Create(OpCodes.Throw),
                    same,
                    Instruction.Create(OpCodes.Ldflda, importer.Import(fixedField)),
                    Instruction.Create(OpCodes.Ldarg_1),
                    Instruction.Create(OpCodes.Call, read),
                    Instruction.Create(StInd(elementType)),
                });

            case 2:
                return(new[]
                {
                    Instruction.Create(OpCodes.Ldarg_1),
                    Instruction.Create(OpCodes.Call, reader.ReadArrayHeader),
                    InstructionUtility.LdcI4(count),
                    Instruction.Create(OpCodes.Beq_S, same),
                    Instruction.Create(OpCodes.Ldstr, "Fixed size buffer field should have " + count.ToString(CultureInfo.InvariantCulture) + " element(s)."),
                    Instruction.Create(OpCodes.Newobj, invalidOperationExceptionHelper.Ctor),
                    Instruction.Create(OpCodes.Throw),
                    same,
                    Instruction.Create(OpCodes.Ldflda, importer.Import(fixedField)),
                    Instruction.Create(OpCodes.Dup),
                    Instruction.Create(OpCodes.Ldarg_1),
                    Instruction.Create(OpCodes.Call, read),
                    Instruction.Create(StInd(elementType)),
                    InstructionUtility.LdcI4(stride),
                    Instruction.Create(OpCodes.Add),
                    Instruction.Create(OpCodes.Ldarg_1),
                    Instruction.Create(OpCodes.Call, read),
                    Instruction.Create(StInd(elementType)),
                });

            default:
            {
                var answer = new Instruction[6 + (6 * count)];
                answer[0] = Instruction.Create(OpCodes.Ldarg_1);
                answer[1] = Instruction.Create(OpCodes.Call, reader.ReadArrayHeader);
                answer[2] = InstructionUtility.LdcI4(count);
                answer[3] = Instruction.Create(OpCodes.Beq_S, same);
                answer[4] = Instruction.Create(OpCodes.Ldstr, "Fixed size buffer field should have " + count.ToString(CultureInfo.InvariantCulture) + " element(s). field : " + fixedField.FullName);
                answer[5] = Instruction.Create(OpCodes.Newobj, invalidOperationExceptionHelper.Ctor);
                answer[6] = Instruction.Create(OpCodes.Throw);
                answer[7] = same;
                answer[8] = Instruction.Create(OpCodes.Ldflda, importer.Import(fixedField));

                answer[9]  = Instruction.Create(OpCodes.Dup);
                answer[10] = Instruction.Create(OpCodes.Ldarg_1);
                answer[11] = Instruction.Create(OpCodes.Call, read);
                answer[12] = Instruction.Create(StInd(elementType));

                for (var i = 1; i < count - 1; i++)
                {
                    var start = 7 + (i * 6);
                    answer[start++] = Instruction.Create(OpCodes.Dup);
                    answer[start++] = InstructionUtility.LdcI4(stride);
                    answer[start++] = Instruction.Create(OpCodes.Add);
                    answer[start++] = Instruction.Create(OpCodes.Ldarg_1);
                    answer[start++] = Instruction.Create(OpCodes.Call, read);
                    answer[start]   = Instruction.Create(StInd(elementType));
                }

                answer[1 + (6 * count)] = InstructionUtility.LdcI4(stride);
                answer[2 + (6 * count)] = Instruction.Create(OpCodes.Add);
                answer[3 + (6 * count)] = Instruction.Create(OpCodes.Ldarg_1);
                answer[4 + (6 * count)] = Instruction.Create(OpCodes.Call, read);
                answer[5 + (6 * count)] = Instruction.Create(StInd(elementType));

                return(answer);
            }
            }
        }