コード例 #1
0
        private static void WriteAssemblyNames(SerializationState state, AbstractRecord curRecord)
        {
            if (curRecord != null)
            {
                switch (curRecord.Kind)
                {
                case RecordKind.Class:
                    var claas = (ClassRecord)curRecord;
                    WriteAssemblyName(state, claas);
                    foreach (var member in claas.Members)
                    {
                        WriteAssemblyName(state, member);
                        WriteAssemblyNames(state, member.Value as AbstractRecord);
                    }
                    break;

                case RecordKind.Array:
                    var array = (ArrayRecord)curRecord;
                    WriteAssemblyName(state, array);
                    foreach (var elem in array.ValuesAsVector)
                    {
                        WriteAssemblyNames(state, elem as AbstractRecord);
                    }
                    break;
                }
            }
        }
コード例 #2
0
            internal Boolean TryAddRecord(AbstractRecord record, out Int32 id)
            {
                id = 0;
                var retVal = record != null && !this.records.TryGetValue(record, out id);

                if (retVal)
                {
                    id = this.assemblies.Count + this.records.Count + 1;
                    this.records.Add(record, id);
                }
                return(retVal);
            }
コード例 #3
0
        private static void WriteSingleRecord(SerializationState state, AbstractRecord record, Boolean forceWrite)
        {
            Int32 id;

            if (state.TryAddRecord(record, out id) || forceWrite)
            {
                // If record hasn't been previously processed, or if we are told to write contents no matter what
                switch (record.Kind)
                {
                case RecordKind.String:
                    var s   = ((StringRecord)record).StringValue;
                    var len = UTF8.GetByteCount(s);
                    state.EnsureCapacity(10 + len);
                    state.array
                    .WriteByteToBytes(ref state.idx, (Byte)RecordTypeEnumeration.BinaryObjectString)
                    .WriteInt32LEToBytes(ref state.idx, id)
                    .WriteInt32Encoded7Bit(ref state.idx, len)
                    .WriteStringToBytes(ref state.idx, UTF8, s);
                    state.WriteArrayToStream();
                    break;

                case RecordKind.Class:
                    WriteClassRecord(state, (ClassRecord)record, id);
                    break;

                case RecordKind.Array:
                    WriteArrayRecord(state, (ArrayRecord)record, id);
                    break;

                case RecordKind.PrimitiveWrapper:
                    // Write header
                    state.EnsureCapacity(2);
                    var p     = ((PrimitiveWrapperRecord)record).Value;
                    var pType = GetPrimitiveType(p);
                    state.array
                    .WriteByteToBytes(ref state.idx, (Byte)RecordTypeEnumeration.MemberPrimitiveTyped)
                    .WriteByteToBytes(ref state.idx, (Byte)pType);
                    state.WriteArrayToStream();
                    // Write primitive
                    WritePrimitive(state, p, pType);
                    break;
                }
            }
            else
            {
                // Record was already serialized, write member reference to it
                state.EnsureCapacity(5);
                state.array
                .WriteByteToBytes(ref state.idx, (Byte)RecordTypeEnumeration.MemberReference)
                .WriteInt32LEToBytes(ref state.idx, id);
                state.WriteArrayToStream();
            }
        }
コード例 #4
0
        private static Boolean CheckPlaceholder(DeserializationState state, Object value, out AbstractRecord rec)
        {
            var record = value as AbstractRecord;
            var retVal = record != null;

            if (retVal)
            {
                var ph = record as RecordPlaceholder;
                retVal = ph != null;
                rec    = retVal ? state.records[((RecordPlaceholder)record).id] : null;
                if (!retVal)
                {
                    switch (record.Kind)
                    {
                    case RecordKind.Class:
                        var claas = (ClassRecord)record;
                        foreach (var member in claas.Members)
                        {
                            if (CheckPlaceholder(state, member.Value, out rec))
                            {
                                member.Value = rec;
                            }
                        }
                        break;

                    case RecordKind.Array:
                        var array = (ArrayRecord)record;
                        for (var i = 0; i < array.ValuesAsVector.Count; ++i)
                        {
                            if (CheckPlaceholder(state, array.ValuesAsVector[i], out rec))
                            {
                                array.ValuesAsVector[i] = rec;
                            }
                        }
                        break;
                    }
                }
                ((ClassRecord)rec).IsSerializedInPlace = !retVal;
            }
            else
            {
                rec = null;
            }
            return(retVal);
        }