Пример #1
0
        public void Write(BinaryBuffer buf)
        {
            buf.Write(collectionCounts.Count);
            foreach (var i in collectionCounts)
            {
                buf.Write(i);
            }

            buf.Write(fieldSizes.Count);
            foreach (var i in fieldSizes)
            {
                buf.Write(i);
            }
            fieldSizes.Clear();

            //Guid crumb, so we can jump to the guid table on read
            var guidCrumbPosition = buf.position;

            buf.position += 5;

            //Type table
            //At this point includes only node types, which we iterate through adding fields type ids
            var keys = new Type[typeToLocalID.Count];

            typeToLocalID.Keys.CopyTo(keys, 0);
            buf.Write(keys.Length);

            foreach (var type in keys)
            {
                var metaNode = NodeBindings.GetBindings(type);
                buf.Write(metaNode.fields.Length);
                foreach (var field in metaNode.fields)
                {
                    var typeUnits = TypeUnitUtility.GetTypeUnits(field.type);
                    buf.Write(typeUnits.Length);
                    foreach (var subType in typeUnits)
                    {
                        WriteLocalID(buf, subType);
                    }
                }
            }

            //Guids
            var currentPosition = buf.position;

            buf.position = guidCrumbPosition;
            buf.Write(currentPosition);
            buf.position = currentPosition;

            buf.Write(typeToLocalID.Count);
            foreach (var pair in typeToLocalID)
            {
                buf.Write(DeltaCore.GetGUID(pair.Key));
            }
            typeToLocalID.Clear();
        }
Пример #2
0
        //Parse type metadata in the footer so we can avoid indexing fields that no longer exist
        public void Read(BinaryBuffer buf)
        {
            collectionCounts.Clear();
            var collectionCountCount = buf.ReadInt();

            for (int i = 0; i < collectionCountCount; i++)
            {
                collectionCounts.Push(buf.ReadInt());
            }

            fieldSizes.Clear();
            var fieldSizesCount = buf.ReadInt();

            for (int i = 0; i < fieldSizesCount; i++)
            {
                fieldSizes.Enqueue(buf.ReadInt());
            }

            //Guids
            var typeTablePosition = buf.position + 5;

            buf.position = buf.ReadInt();             //Jump to guid table

            localIDToGuid.Clear();
            var numGuids = buf.ReadInt();

            for (int iGuid = 0; iGuid < numGuids; iGuid++)
            {
                localIDToGuid.Add(buf.ReadGuid());
            }

            var currentPosition = buf.position;

            //Jump back to type table
            buf.position = typeTablePosition;
            fieldTypeMatchTable.Clear();
            var numNodeTypes = buf.ReadInt();

            for (int localID = 0; localID < numNodeTypes; localID++)
            {
                var type     = DeltaCore.Get <Type>(localIDToGuid[localID]);
                var metaNode = NodeBindings.GetBindings(type);

                var oldFieldCount     = buf.ReadInt();
                var currentFieldCount = metaNode.fields.Length;
                var fieldTypeMatches  = new bool[Math.Max(oldFieldCount, currentFieldCount)];
                fieldTypeMatchTable.Add(fieldTypeMatches);

                for (int iField = 0; iField < fieldTypeMatches.Length; iField++)
                {
                    if (iField >= oldFieldCount)
                    {
                        continue;
                    }

                    var oldSubTypeLength = buf.ReadInt();
                    var currentTypeUnits = TypeUnitUtility.GetTypeUnits(metaNode.fields[iField].type);

                    var matches = true;
                    if (oldSubTypeLength != currentTypeUnits.Length)
                    {
                        matches = false;
                    }

                    for (int iTypeUnit = 0; iTypeUnit < oldSubTypeLength; iTypeUnit++)
                    {
                        var currentGUID  = DeltaCore.GetGUID(currentTypeUnits[iTypeUnit]);
                        var previousGUID = localIDToGuid[buf.ReadInt()];
                        if (currentGUID != previousGUID)
                        {
                            matches = false;
                        }
                    }

                    fieldTypeMatches[iField] = matches;
                }
            }

            buf.position = currentPosition;
        }