Exemple #1
0
        public override void ReadFromPhysical(byte[] buffer, int offset)
        {
            _table.Truncate(Manager);

            Streams.IConveyor int32Conveyor = Manager.GetConveyor(Manager.DataTypes.SystemInteger);

            if (buffer[offset] != 0)
            {
                offset++;

                int rowSize;
                int count = (int)int32Conveyor.Read(buffer, offset);

                for (int index = 0; index < count; index++)
                {
                    rowSize = (int)int32Conveyor.Read(buffer, offset);
                    offset += sizeof(int);
                    using (IRow row = (IRow)DataValue.FromPhysical(Manager, _table.RowType, buffer, offset))
                    {
                        _table.Insert(Manager, row);
                    }
                    offset += rowSize;
                }
            }
        }
Exemple #2
0
        public override void ReadFromPhysical(byte[] buffer, int offset)
        {
            // Clear current value
            if (ValuesOwned && !IsNative && (StreamID != StreamID.Null))
            {
                Manager.StreamManager.Deallocate(StreamID);
            }

            // Read scalar header
            byte header = buffer[offset];

            offset++;
            if ((header & 1) != 0)             // if not nil
            {
                if ((header & 2) != 0)
                {
                    if (DataType.IsCompound)
                    {
                        using (IRow row = (IRow)DataValue.FromPhysical(Manager, DataType.CompoundRowType, buffer, offset))
                        {
                            Value           = row.AsNative;
                            row.ValuesOwned = false;
                        }
                    }
                    else
                    {
                        Streams.IConveyor conveyor = Manager.GetConveyor(DataType);
                        if (conveyor.IsStreaming)
                        {
                            Stream stream = new MemoryStream(buffer, offset, buffer.Length - offset, false, true);
                            Value = conveyor.Read(stream);
                            stream.Close();
                        }
                        else
                        {
                            Value = conveyor.Read(buffer, offset);
                        }
                    }
                }
                else
                {
                    if ((header & 4) != 0)                     // if expanded form
                    {
                        Value = Manager.StreamManager.Allocate();
                        Stream stream = Manager.StreamManager.Open(StreamID, LockMode.Exclusive);
                        stream.Write(buffer, offset, buffer.Length - offset);
                        stream.Close();
                    }
                    else
                    {
                        Value = StreamID.Read(buffer, offset);
                    }
                }
            }
            else
            {
                if ((header & 2) != 0)
                {
                    Value = null;
                }
                else
                {
                    Value = StreamID.Null;
                }
            }
        }
Exemple #3
0
        public override void ReadFromPhysical(byte[] buffer, int offset)
        {
            ClearValues();             // Clear the current value of the row

            if (buffer[offset] == 0)
            {
                _row = null;
            }
            else
            {
                _row = new NativeRow(DataType.Columns.Count);
                offset++;

                bool expandStreams = buffer[offset] != 0;                 // Read the exapnded streams indicator
                offset++;

                                #if USEDATATYPESINNATIVEROW
                Streams.IConveyor stringConveyor = Manager.GetConveyor(Manager.DataTypes.SystemString);
                string dataTypeName;
                Schema.IDataType dataType;
                                #endif
                Streams.IConveyor int64Conveyor = Manager.GetConveyor(Manager.DataTypes.SystemLong);
                Streams.IConveyor int32Conveyor = Manager.GetConveyor(Manager.DataTypes.SystemInteger);

                Stream stream;
                StreamID streamID;
                int elementSize;
                Schema.IScalarType scalarType;
                Streams.IConveyor conveyor;
                for (int index = 0; index < DataType.Columns.Count; index++)
                {
                    byte valueIndicator = buffer[offset];
                    offset++;

                    switch (valueIndicator)
                    {
                    case 0:                              // native nil
                                                        #if USEDATATYPESINNATIVEROW
                        _row.DataTypes[index] = DataType.Columns[index].DataType;
                                                        #endif
                        _row.Values[index] = null;
                        break;

                    case 1:                              // non-native nil
                                                        #if USEDATATYPESINNATIVEROW
                        _row.DataTypes[index] = DataType.Columns[index].DataType;
                                                        #endif
                        _row.Values[index] = StreamID.Null;
                        break;

                    case 2:                              // native standard value
                        scalarType = DataType.Columns[index].DataType as Schema.IScalarType;
                        if ((scalarType != null) && !scalarType.IsCompound)
                        {
                            conveyor = Manager.GetConveyor(scalarType);
                            if (conveyor.IsStreaming)
                            {
                                elementSize = (int)int32Conveyor.Read(buffer, offset);
                                offset     += sizeof(int);
                                stream      = new MemoryStream(buffer, offset, elementSize, false, true);
                                                                        #if USEDATATYPESINNATIVEROW
                                _row.DataTypes[index] = DataType.Columns[index].DataType;
                                                                        #endif
                                _row.Values[index] = conveyor.Read(stream);
                                offset            += elementSize;
                            }
                            else
                            {
                                elementSize = (int)int32Conveyor.Read(buffer, offset);
                                offset     += sizeof(int);
                                                                        #if USEDATATYPESINNATIVEROW
                                _row.DataTypes[index] = DataType.Columns[index].DataType;
                                                                        #endif
                                _row.Values[index] = conveyor.Read(buffer, offset);
                                offset            += elementSize;
                            }
                        }
                        else
                        {
                            elementSize = (int)int32Conveyor.Read(buffer, offset);
                            offset     += sizeof(int);
                                                                #if USEDATATYPESINNATIVEROW
                            _row.DataTypes[index] = DataType.Columns[index].DataType;
                                                                #endif
                            using (IDataValue tempValue = DataValue.FromPhysical(Manager, DataType.Columns[index].DataType, buffer, offset))
                            {
                                _row.Values[index]    = tempValue.AsNative;
                                tempValue.ValuesOwned = false;
                            }
                            offset += elementSize;
                        }
                        break;

                    case 3:                              // non-native standard value
                        scalarType = DataType.Columns[index].DataType as Schema.IScalarType;
                        if (scalarType != null)
                        {
                            if (expandStreams)
                            {
                                elementSize = (int)int32Conveyor.Read(buffer, offset);
                                offset     += sizeof(int);
                                streamID    = Manager.StreamManager.Allocate();
                                stream      = Manager.StreamManager.Open(streamID, LockMode.Exclusive);
                                stream.Write(buffer, offset, elementSize);
                                stream.Close();
                                                                        #if USEDATATYPESINNATIVEROW
                                _row.DataTypes[index] = scalarType;
                                                                        #endif
                                _row.Values[index] = streamID;
                                offset            += elementSize;
                            }
                            else
                            {
                                                                        #if USEDATATYPESINNATIVEROW
                                _row.DataTypes[index] = scalarType;
                                                                        #endif
                                _row.Values[index] = new StreamID(Convert.ToUInt64(int64Conveyor.Read(buffer, offset)));
                                offset            += sizeof(long);
                            }
                        }
                        else
                        {
                            // non-scalar values cannot be non-native
                        }
                        break;

                    case 4:                              // native specialized value
                                                        #if USEDATATYPESINNATIVEROW
                        dataTypeName = (string)stringConveyor.Read(buffer, offset);
                        dataType     = Manager.CompileTypeSpecifier(dataTypeName);
                        offset      += stringConveyor.GetSize(dataTypeName);
                        scalarType   = dataType as Schema.IScalarType;
                        if ((scalarType != null) && !scalarType.IsCompound)
                        {
                            conveyor = Manager.GetConveyor(scalarType);
                            if (conveyor.IsStreaming)
                            {
                                elementSize           = (int)int32Conveyor.Read(buffer, offset);
                                offset               += sizeof(int);
                                stream                = new MemoryStream(buffer, offset, elementSize, false, true);
                                _row.DataTypes[index] = scalarType;
                                _row.Values[index]    = conveyor.Read(stream);
                                offset               += elementSize;
                            }
                            else
                            {
                                elementSize           = (int)int32Conveyor.Read(buffer, offset);
                                offset               += sizeof(int);
                                _row.DataTypes[index] = scalarType;
                                _row.Values[index]    = conveyor.Read(buffer, offset);
                                offset               += elementSize;
                            }
                        }
                        else
                        {
                            elementSize           = (int)int32Conveyor.Read(buffer, offset);
                            offset               += sizeof(int);
                            _row.DataTypes[index] = dataType;
                            using (IDataValue tempValue = DataValue.FromPhysical(Manager, dataType, buffer, offset))
                            {
                                _row.Values[index]    = tempValue.AsNative;
                                tempValue.ValuesOwned = false;
                            }
                            offset += elementSize;
                        }
                        break;
                                                        #else
                        throw new NotSupportedException("Specialized data types in rows are not supported");
                                                        #endif

                    case 5:                              // non-native specialized value
                                                        #if USEDATATYPESINNATIVEROW
                        dataTypeName = (string)stringConveyor.Read(buffer, offset);
                        dataType     = Manager.CompileTypeSpecifier(dataTypeName);
                        offset      += stringConveyor.GetSize(dataTypeName);
                        scalarType   = dataType as Schema.IScalarType;
                        if (scalarType != null)
                        {
                            if (expandStreams)
                            {
                                elementSize = (int)int32Conveyor.Read(buffer, offset);
                                offset     += sizeof(int);
                                streamID    = Manager.StreamManager.Allocate();
                                stream      = Manager.StreamManager.Open(streamID, LockMode.Exclusive);
                                stream.Write(buffer, offset, elementSize);
                                stream.Close();
                                _row.DataTypes[index] = scalarType;
                                _row.Values[index]    = streamID;
                                offset += elementSize;
                            }
                            else
                            {
                                _row.DataTypes[index] = scalarType;
                                _row.Values[index]    = new StreamID(Convert.ToUInt64(int64Conveyor.Read(buffer, offset)));
                                offset += sizeof(long);
                            }
                        }
                        else
                        {
                            // non-scalar values cannot be non-native
                        }
                        break;
                                                        #else
                        throw new NotSupportedException("Specialized data types in rows are not supported");
                                                        #endif
                    }
                }
            }
        }
Exemple #4
0
        public override void ReadFromPhysical(byte[] buffer, int offset)
        {
            Clear();             // Clear the current value of the list

            if (buffer[offset] == 0)
            {
                _list = null;
            }
            else
            {
                _list = new NativeList();
                if (buffer[offset] != 0)
                {
                    offset++;

                    bool expandStreams = buffer[offset] != 0;                     // Read the exapnded streams indicator
                    offset++;

                    Streams.IConveyor stringConveyor = null;
                    Streams.IConveyor int64Conveyor  = Manager.GetConveyor(Manager.DataTypes.SystemLong);
                    Streams.IConveyor int32Conveyor  = Manager.GetConveyor(Manager.DataTypes.SystemInteger);
                    int count = (int)int32Conveyor.Read(buffer, offset);                     // Read the number of elements in the list
                    offset += sizeof(int);

                    Stream             stream;
                    StreamID           streamID;
                    int                elementSize;
                    string             dataTypeName;
                    Schema.IDataType   dataType;
                    Schema.IScalarType scalarType;
                    Streams.IConveyor  conveyor;
                    for (int index = 0; index < count; index++)
                    {
                        byte valueIndicator = buffer[offset];
                        offset++;

                        switch (valueIndicator)
                        {
                        case 0:                                  // native nil
                            _list.DataTypes.Add(DataType.ElementType);
                            _list.Values.Add(null);
                            break;

                        case 1:                                  // non-native nil
                            _list.DataTypes.Add(DataType.ElementType);
                            _list.Values.Add(StreamID.Null);
                            break;

                        case 2:                                  // native standard value
                            scalarType = DataType.ElementType as Schema.IScalarType;
                            if ((scalarType != null) && !scalarType.IsCompound)
                            {
                                conveyor = Manager.GetConveyor(scalarType);
                                if (conveyor.IsStreaming)
                                {
                                    elementSize = (int)int32Conveyor.Read(buffer, offset);
                                    offset     += sizeof(int);
                                    stream      = new MemoryStream(buffer, offset, elementSize, false, true);
                                    _list.DataTypes.Add(DataType.ElementType);
                                    _list.Values.Add(conveyor.Read(stream));
                                    offset += elementSize;
                                }
                                else
                                {
                                    elementSize = (int)int32Conveyor.Read(buffer, offset);
                                    offset     += sizeof(int);
                                    _list.DataTypes.Add(DataType.ElementType);
                                    _list.Values.Add(conveyor.Read(buffer, offset));
                                    offset += elementSize;
                                }
                            }
                            else
                            {
                                elementSize = (int)int32Conveyor.Read(buffer, offset);
                                offset     += sizeof(int);
                                _list.DataTypes.Add(DataType.ElementType);
                                using (IDataValue tempValue = DataValue.FromPhysical(Manager, DataType.ElementType, buffer, offset))
                                {
                                    _list.Values.Add(tempValue.AsNative);
                                    tempValue.ValuesOwned = false;
                                }
                                offset += elementSize;
                            }
                            break;

                        case 3:                                  // non-native standard value
                            scalarType = DataType.ElementType as Schema.IScalarType;
                            if (scalarType != null)
                            {
                                if (expandStreams)
                                {
                                    elementSize = (int)int32Conveyor.Read(buffer, offset);
                                    offset     += sizeof(int);
                                    streamID    = Manager.StreamManager.Allocate();
                                    stream      = Manager.StreamManager.Open(streamID, LockMode.Exclusive);
                                    stream.Write(buffer, offset, elementSize);
                                    stream.Close();
                                    _list.DataTypes.Add(scalarType);
                                    _list.Values.Add(streamID);
                                    offset += elementSize;
                                }
                                else
                                {
                                    _list.DataTypes.Add(scalarType);
                                    _list.Values.Add(int64Conveyor.Read(buffer, offset));
                                    offset += sizeof(long);
                                }
                            }
                            else
                            {
                                // non-scalar values cannot be non-native
                            }
                            break;

                        case 4:                                  // native specialized value
                            dataTypeName = (string)stringConveyor.Read(buffer, offset);
                            dataType     = Manager.CompileTypeSpecifier(dataTypeName);
                            offset      += stringConveyor.GetSize(dataTypeName);
                            scalarType   = dataType as Schema.IScalarType;
                            if ((scalarType != null) && !scalarType.IsCompound)
                            {
                                conveyor = Manager.GetConveyor(scalarType);
                                if (conveyor.IsStreaming)
                                {
                                    elementSize = (int)int32Conveyor.Read(buffer, offset);
                                    offset     += sizeof(int);
                                    stream      = new MemoryStream(buffer, offset, elementSize, false, true);
                                    _list.DataTypes.Add(scalarType);
                                    _list.Values.Add(conveyor.Read(stream));
                                    offset += elementSize;
                                }
                                else
                                {
                                    elementSize = (int)int32Conveyor.Read(buffer, offset);
                                    offset     += sizeof(int);
                                    _list.DataTypes.Add(DataType.ElementType);
                                    _list.Values.Add(conveyor.Read(buffer, offset));
                                    offset += elementSize;
                                }
                            }
                            else
                            {
                                elementSize = (int)int32Conveyor.Read(buffer, offset);
                                offset     += sizeof(int);
                                _list.DataTypes.Add(dataType);
                                using (IDataValue tempValue = DataValue.FromPhysical(Manager, dataType, buffer, offset))
                                {
                                    _list.Values.Add(tempValue.AsNative);
                                    tempValue.ValuesOwned = false;
                                }
                                offset += elementSize;
                            }
                            break;

                        case 5:                                  // non-native specialized value
                            dataTypeName = (string)stringConveyor.Read(buffer, offset);
                            dataType     = Manager.CompileTypeSpecifier(dataTypeName);
                            offset      += stringConveyor.GetSize(dataTypeName);
                            scalarType   = dataType as Schema.IScalarType;
                            if (scalarType != null)
                            {
                                if (expandStreams)
                                {
                                    elementSize = (int)int32Conveyor.Read(buffer, offset);
                                    offset     += sizeof(int);
                                    streamID    = Manager.StreamManager.Allocate();
                                    stream      = Manager.StreamManager.Open(streamID, LockMode.Exclusive);
                                    stream.Write(buffer, offset, elementSize);
                                    stream.Close();
                                    _list.DataTypes.Add(scalarType);
                                    _list.Values.Add(streamID);
                                    offset += elementSize;
                                }
                                else
                                {
                                    _list.DataTypes.Add(scalarType);
                                    _list.Values.Add(int64Conveyor.Read(buffer, offset));
                                    offset += sizeof(long);
                                }
                            }
                            else
                            {
                                // non-scalar values cannot be non-native
                            }
                            break;
                        }
                    }
                }
            }
        }