Exemplo n.º 1
0
 public override object ReadValue(HessianReader reader, HessianContext context, Type objectType, byte initialOctet)
 {
     if (Constants.BC_REF == initialOctet)
     {
         var index = (int)IntConverter.ReadValue(reader, context, typeof(int));
         return(context.ValueRefs.GetItem(index));
     }
     else
     {
         return(ReadValueNotExisted(reader, context, objectType, initialOctet));
     }
 }
Exemplo n.º 2
0
        public override object ReadValueNotExisted(HessianReader reader, HessianContext context, Type objectType, byte initialOctet)
        {
            int  len         = 0;
            Type elementType = null;

            if (0x70 <= initialOctet && initialOctet <= 0x77)
            {
                elementType = ((Type)TypeConverter.ReadValue(reader, context, null)).GetElementType();
                len         = initialOctet - 0x70;
            }
            else if (0x78 <= initialOctet && initialOctet <= 0x7f)
            {
                elementType = typeof(object);
                len         = initialOctet - 0x78;
            }
            else if (Constants.BC_LIST_FIXED_UNTYPED == initialOctet)
            {
                elementType = typeof(object);
                len         = (int)IntConverter.ReadValue(reader, context, typeof(int));
            }
            else if (Constants.BC_LIST_FIXED == initialOctet)
            {
                elementType = ((Type)TypeConverter.ReadValue(reader, context, null)).GetElementType();
                len         = (int)IntConverter.ReadValue(reader, context, typeof(int));
            }

            var array = Array.CreateInstance(elementType, len);

            context.ValueRefs.AddItem(array);

            HessianConverter itemConverter = null;

            if (elementType == typeof(object))
            {
                itemConverter = AutoConverter;
            }
            else
            {
                itemConverter = AutoConverter.GetConverter(elementType);
            }

            for (int i = 0; i < len; i++)
            {
                var item = itemConverter.ReadValue(reader, context, elementType);
                array.SetValue(item, i);
            }
            return(array);
        }
Exemplo n.º 3
0
        public override object ReadValueNotExisted(HessianReader reader, HessianContext context, Type objectType, byte initialOctet)
        {
            if (ClassDefinitionConverter.CanRead(initialOctet))
            {
                ClassDefinitionConverter.ReadValue(reader, context, typeof(ClassDefinition), initialOctet);
                initialOctet = reader.ReadByte();
            }

            int definitionIndex = 0;

            if (0x60 <= initialOctet && initialOctet <= 0x6f)
            {
                definitionIndex = initialOctet - Constants.BC_OBJECT_DIRECT;
            }
            else if (Constants.BC_OBJECT == initialOctet)
            {
                definitionIndex = (int)IntConverter.ReadValue(reader, context, typeof(int));
            }
            var definition = context.ClassRefs.GetItem(definitionIndex);

            object value = null;

            if (definition.Type.IsEnum)
            {
                definition.VisitFields(field =>
                {
                    var fieldValue = AutoConverter.ReadValue(reader, context, field.Type);
                    if (field.Name == "name")
                    {
                        value = Enum.Parse(definition.Type, (string)fieldValue);
                        context.ValueRefs.AddItem(value);
                    }
                });
            }
            else
            {
                value = Activator.CreateInstance(definition.Type);
                context.ValueRefs.AddItem(value);
                definition.VisitFields(field =>
                {
                    var fieldValue = AutoConverter.ReadValue(reader, context, field.Type);
                    field.Setter(value, fieldValue);
                });
            }
            return(value);
        }
Exemplo n.º 4
0
        public override object ReadValue(HessianReader reader, HessianContext context, Type objectType, byte initialOctet)
        {
            if (Constants.BC_REF == initialOctet)
            {
                var index = (int)IntConverter.ReadValue(reader, context, typeof(int));
                return(context.ValueRefs.GetItem(index));
            }

            foreach (var converter in ConverterCache.Values)
            {
                if (converter != this && !(converter is ClassDefinitionConverter) && converter.CanRead(initialOctet))
                {
                    return(converter.ReadValue(reader, context, objectType, initialOctet));
                }
            }

            throw Exceptions.UnExpectedInitialOctet(this, initialOctet);
        }
Exemplo n.º 5
0
 public override object ReadValue(HessianReader reader, HessianContext context, Type objectType, byte initialOctet)
 {
     if (StringConverter.CanRead(initialOctet))
     {
         var typeName = (string)StringConverter.ReadValue(reader, context, typeof(string), initialOctet);
         var type     = GetType(typeName);
         context.TypeRefs.AddItem(type);
         return(type);
     }
     else if (IntConverter.CanRead(initialOctet))
     {
         var typeIndex = (int)IntConverter.ReadValue(reader, context, typeof(int), initialOctet);
         return(context.TypeRefs.GetItem(typeIndex));
     }
     else
     {
         throw Exceptions.UnExpectedInitialOctet(this, initialOctet);
     }
 }
Exemplo n.º 6
0
        public override object ReadValue(HessianReader reader, HessianContext context, Type objectType, byte initialOctet)
        {
            if (Constants.BC_OBJECT_DEF != initialOctet)
            {
                throw Exceptions.UnExpectedInitialOctet(this, initialOctet);
            }

            var type       = (Type)TypeConverter.ReadValue(reader, context, null);
            var len        = (int)IntConverter.ReadValue(reader, context, typeof(int));
            var fieldNames = new List <string>(len);

            for (int i = 0; i < len; i++)
            {
                var fieldName = (string)StringConverter.ReadValue(reader, context, typeof(string));
                fieldNames.Add(fieldName);
            }
            var definition = ClassDefinition.FromHessianDefinition(type, fieldNames);

            context.ClassRefs.AddItem(definition);
            return(definition);
        }