Пример #1
0
 public void Code(Type t, ref IArrayVector value)
 {
     value = (IArrayVector)FastObjectFactory.ObjectFactory(t)();
     Array array  = null; Code(value.ArrayType, ref array); value.Array = array;
     long  origin = 0L; CodeLong(ref origin); value.Origin = origin;
     long  length = 0L; CodeLong(ref length); value.Size = length;
     long  delta  = 0L; CodeLong(ref delta); value.Delta = delta;
 }
Пример #2
0
 public void Code(Type t, ref IArrayTensor4 value)
 {
     value = (IArrayTensor4)FastObjectFactory.ObjectFactory(t)();
     Array array  = null; Code(value.ArrayType, ref array); value.Array = array;
     long  origin = 0L; CodeLong(ref origin); value.Origin = origin;
     V4l   length = default(V4l); CodeV4l(ref length); value.Size = length;
     V4l   delta  = default(V4l); CodeV4l(ref delta); value.Delta = delta;
 }
Пример #3
0
        public void Code(ref object obj)
        {
            var      typeName    = m_reader.ReadString();
            TypeInfo newTypeInfo = null;
            TypeInfo typeInfo;

            if (TryGetTypeInfo(typeName, out typeInfo))
            {
                if (typeInfo.Type == typeof(TypeCoder.Null))
                {
                    if ((typeInfo.Options & TypeInfo.Option.Active) != 0)
                    {
                        obj = null;
                        return;
                    }
                    else
                    {
                        throw new Exception("cannot decode null object "
                                            + "- change by configuring coder with "
                                            + "\"coder.Add(TypeCoder.Default.Null);\"");
                    }
                }
                if (typeInfo.Type == typeof(TypeCoder.Reference))
                {
                    if ((typeInfo.Options & TypeInfo.Option.Active) != 0)
                    {
                        if (CoderVersion < 5)
                        {
                            obj = UseRef(m_reader.ReadInt32());
                        }
                        else
                        {
                            obj = UseRef(m_reader.ReadGuid());
                        }
                        return;
                    }
                    else
                    {
                        throw new Exception(
                                  "cannot decode multiply referenced object "
                                  + "- change by configuring coder with "
                                  + "\"coder.Add(TypeCoder.Default.Reference);\"");
                    }
                }
            }
            else
            {
                typeInfo = new TypeInfo(typeName, Type.GetType(typeName),
                                        TypeInfo.Option.Size | TypeInfo.Option.Version);
                if ((m_debugMode & CoderDebugMode.ReportQualifiedNames) != 0)
                {
                    Report.Line("qualified name \"{0}\"", typeName);
                }
            }

            if ((typeInfo.Options & TypeInfo.Option.Version) != 0)
            {
                m_versionStack.Push(m_version);
                m_version = m_reader.ReadInt32();
                if (m_version < typeInfo.Version)
                {
                    TypeInfo oldTypeInfo;
                    if (typeInfo.VersionMap.TryGetValue(m_version, out oldTypeInfo))
                    {
                        newTypeInfo = typeInfo; typeInfo = oldTypeInfo;
                    }
                }
            }

            long end = 0;

            if ((typeInfo.Options & TypeInfo.Option.Size) != 0)
            {
                end = m_reader.ReadInt64() + m_reader.BaseStream.Position;
            }

            if (typeInfo.Type != null)
            {
                if (!TypeCoder.ReadPrimitive(this, typeInfo.Type, ref obj))
                {
                    if ((typeInfo.Options & TypeInfo.Option.Ignore) != 0)
                    {
                        m_reader.BaseStream.Position = end;
                        obj = null;
                    }
                    else
                    {
                        var codedVersion = m_version;

                        m_typeInfoStack.Push(typeInfo);

                        if (typeInfo.Creator != null)
                        {
                            obj = typeInfo.Creator();
                        }
                        else
                        {
                            obj = FastObjectFactory.ObjectFactory(typeInfo.Type)();
                        }

                        if ((m_debugMode & CoderDebugMode.ReportObjects) != 0)
                        {
                            Report.Line("{0,-34} 0x{1:x}", typeName, obj.GetHashCode());
                        }

                        if (m_doRefs)
                        {
                            AddRef(obj);
                        }

                        #region code fields based on supported interface

                        var fcobj = obj as IFieldCodeable;
                        if (fcobj != null)
                        {
                            CodeFields(typeInfo.Type, codedVersion, fcobj);
                            if (typeInfo.ProxyType != null)
                            {
                                obj = typeInfo.Proxy2ObjectFun(fcobj);
                            }
                            else
                            {
                                var tmobj = obj as ITypedMap;
                                if (tmobj != null)
                                {
                                    CodeFields(typeInfo.Type, tmobj);
                                }
                            }
                            if ((typeInfo.Options & TypeInfo.Option.Size) != 0)
                            {
                                m_reader.BaseStream.Position = end;
                            }
                        }
                        else
                        {
                            if ((typeInfo.Options & TypeInfo.Option.Size) != 0)
                            {
                                m_reader.BaseStream.Position = end;
                                Report.Warn(
                                    "skipping object of uncodeable type \"{0}\"",
                                    typeName);
                                obj = null;
                            }
                            else
                            {
                                throw new Exception(
                                          "cannot skip uncodeable object of type \""
                                          + typeName + '"');
                            }
                        }

                        var aobj = obj as IAwakeable;
                        if (aobj != null)
                        {
                            aobj.Awake(codedVersion);               // codedVersion
                        }
                        #endregion

                        m_typeInfoStack.Pop();
                    }
                }
            }
            else
            {
                if ((typeInfo.Options & TypeInfo.Option.Size) != 0)
                {
                    m_reader.BaseStream.Position = end;
                    Report.Warn("skipping object of unknown type " + typeName);
                    obj = null;
                }
                else
                {
                    throw new Exception(
                              "cannot skip object of unknown type \""
                              + typeName + '"');
                }
            }

            if ((typeInfo.Options & TypeInfo.Option.Version) != 0)
            {
                m_version = m_versionStack.Pop();
                if (obj != null && newTypeInfo != null)
                {
                    var source = new Convertible(typeInfo.Name, obj);
                    var target = new Convertible(newTypeInfo.Name, null);
                    source.ConvertInto(target);
                    obj = target.Data;
                }
            }
        }