Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="root"></param>
        /// <param name="rootClassDescriptor"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        private Object CreateObjectModel(Object root, ClassDescriptor rootClassDescriptor, int length)
        {
            int bytesRead = 0;

            while (!_isEos && bytesRead < length)
            {
                bytesRead += NextHeader();

                if (_blockType == TranslationContext.SimplId.GetTlvId())
                {
                    int simplId = _binaryReader.ReadInt32();
                    translationContext.MarkAsUnmarshalled(simplId.ToString(), root);
                    bytesRead += 4;
                    continue;
                }

                if (_blockType == TranslationContext.SimplRef.GetTlvId())
                {
                    int simplRef = _binaryReader.ReadInt32();
                    return(translationContext.GetFromMap(simplRef.ToString()));
                }

                FieldDescriptor currentFieldDescriptor = rootClassDescriptor.GetFieldDescriptorByTlvId(_blockType);

                int fieldType = currentFieldDescriptor.FdType;

                switch (fieldType)
                {
                case FieldTypes.Scalar:
                    bytesRead += DeserializeScalar(root, currentFieldDescriptor);
                    break;

                case FieldTypes.CollectionScalar:
                    bytesRead += DeserializeScalarCollectionElement(root, currentFieldDescriptor);
                    break;

                case FieldTypes.CompositeElement:
                    bytesRead += DeserializeComposite(root, currentFieldDescriptor);
                    break;

                case FieldTypes.CollectionElement:
                    bytesRead += DeserializeCompositeCollectionElement(root, currentFieldDescriptor);
                    break;

                case FieldTypes.MapElement:
                    bytesRead += DeserializeCompositeMapElement(root, currentFieldDescriptor);
                    break;

                case FieldTypes.Wrapper:
                    currentFieldDescriptor = currentFieldDescriptor.WrappedFd;
                    switch (currentFieldDescriptor.FdType)
                    {
                    case FieldTypes.CollectionScalar:
                        bytesRead += DeserializeScalarCollection(root, currentFieldDescriptor);
                        break;

                    case FieldTypes.CollectionElement:
                        bytesRead += DeserializeCompositeCollection(root, currentFieldDescriptor);
                        break;

                    case FieldTypes.MapElement:
                        bytesRead += DeserializeCompositeMap(root, currentFieldDescriptor);
                        break;

                    case FieldTypes.CompositeElement:
                        //TODO: wrapped composites in tlv?
                        break;
                    }
                    break;
                }
            }

            DeserializationPostHook(root, translationContext);
            if (deserializationHookStrategy != null)
            {
                deserializationHookStrategy.DeserializationPostHook(root, null);
            }

            return(root);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="root"></param>
        /// <param name="rootClassDescriptor"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        private Object CreateObjectModel(Object root, ClassDescriptor rootClassDescriptor, int length)
        {
            int bytesRead = 0;

            while (!_isEos && bytesRead < length)
            {
                bytesRead += NextHeader();

                if (_blockType == TranslationContext.SimplId.GetTlvId())
                {
                    int simplId = _binaryReader.ReadInt32();
                    translationContext.MarkAsUnmarshalled(simplId.ToString(), root);
                    bytesRead += 4;
                    continue;
                }

                if (_blockType == TranslationContext.SimplRef.GetTlvId())
                {
                    int simplRef = _binaryReader.ReadInt32();
                    return translationContext.GetFromMap(simplRef.ToString());
                }

                FieldDescriptor currentFieldDescriptor = rootClassDescriptor.GetFieldDescriptorByTlvId(_blockType);

                int fieldType = currentFieldDescriptor.FdType;

                switch (fieldType)
                {
                    case FieldTypes.Scalar:
                        bytesRead += DeserializeScalar(root, currentFieldDescriptor);
                        break;
                    case FieldTypes.CollectionScalar:
                        bytesRead += DeserializeScalarCollectionElement(root, currentFieldDescriptor);
                        break;
                    case FieldTypes.CompositeElement:
                        bytesRead += DeserializeComposite(root, currentFieldDescriptor);
                        break;
                    case FieldTypes.CollectionElement:
                        bytesRead += DeserializeCompositeCollectionElement(root, currentFieldDescriptor);
                        break;
                    case FieldTypes.MapElement:
                        bytesRead += DeserializeCompositeMapElement(root, currentFieldDescriptor);
                        break;
                    case FieldTypes.Wrapper:
                        currentFieldDescriptor = currentFieldDescriptor.WrappedFd;
                        switch (currentFieldDescriptor.FdType)
                        {
                            case FieldTypes.CollectionScalar:
                                bytesRead += DeserializeScalarCollection(root, currentFieldDescriptor);
                                break;
                            case FieldTypes.CollectionElement:
                                bytesRead += DeserializeCompositeCollection(root, currentFieldDescriptor);
                                break;
                            case FieldTypes.MapElement:
                                bytesRead += DeserializeCompositeMap(root, currentFieldDescriptor);
                                break;
                            case FieldTypes.CompositeElement:
                                //TODO: wrapped composites in tlv?
                                break;
                        }
                        break;
                }
            }

            DeserializationPostHook(root, translationContext);
            if (deserializationHookStrategy != null)
                deserializationHookStrategy.DeserializationPostHook(root, null);

            return root;
        }