Ejemplo n.º 1
0
		public override Stream GetStreamAdapter(IValueManager AManager, Stream AStream)
		{
			using (StreamReader LReader = new StreamReader(AStream))
			{
				string LValue = LReader.ReadToEnd();
				Streams.IConveyor LConveyor = AManager.GetConveyor(ScalarType);
				MemoryStream LStream = new MemoryStream(LConveyor.GetSize(LValue));
				LStream.SetLength(LStream.GetBuffer().Length);
				LConveyor.Write(LValue, LStream.GetBuffer(), 0);
				return LStream;
			}
		}
Ejemplo n.º 2
0
        private IDataValue _writeValue;      // saves the row instantiated to write the compound value if this is a compound scalar

        public override int GetPhysicalSize(bool expandStreams)
        {
            int size = 1;             // Scalar header

            if (!IsNil)
            {
                if (IsNative)
                {
                    if (DataType.IsCompound)
                    {
                        _writeValue = DataValue.FromNative(Manager, DataType.CompoundRowType, Value);
                        return(size + _writeValue.GetPhysicalSize(expandStreams));
                    }
                    else
                    {
                        Streams.IConveyor conveyor = Manager.GetConveyor(DataType);
                        if (conveyor.IsStreaming)
                        {
                            _writeStream = new MemoryStream(64);
                            conveyor.Write(Value, _writeStream);
                            return(size + (int)_writeStream.Length);
                        }
                        return(size + conveyor.GetSize(Value));
                    }
                }

                if (expandStreams)
                {
                    _writeStream = Manager.StreamManager.Open(StreamID, LockMode.Exclusive);
                    return(size + (int)_writeStream.Length);
                }

                return(size + StreamID.CSizeOf);
            }
            return(size);
        }
Ejemplo n.º 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
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override void WriteToPhysical(byte[] buffer, int offset, bool expandStreams)
        {
            if (_writeList == null)
            {
                throw new RuntimeException(RuntimeException.Codes.UnpreparedWriteToPhysicalCall);
            }

            buffer[offset] = (byte)(IsNil ? 0 : 1);             // Write the value indicator
            offset++;

            if (!IsNil)
            {
                buffer[offset] = (byte)(expandStreams ? 1 : 0);                 // Write the expanded streams indicator
                offset++;

                                #if USEDATATYPESINNATIVEROW
                Streams.IConveyor stringConveyor = null;
                                #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;
                IDataValue         element;
                for (int index = 0; index < _writeList.Length; index++)
                {
                    if (_row.Values[index] == null)
                    {
                        buffer[offset] = (byte)0;                         // Write the native nil indicator
                        offset++;
                    }
                    else
                    {
                                                #if USEDATATYPESINNATIVEROW
                        scalarType = _row.DataTypes[index] as Schema.IScalarType;
                                                #else
                        scalarType = DataType.Columns[index].DataType as Schema.IScalarType;
                                                #endif
                        if ((scalarType != null) && !scalarType.IsCompound)
                        {
                            if (_row.Values[index] is StreamID)
                            {
                                // If this is a non-native scalar
                                streamID = (StreamID)_row.Values[index];
                                if (streamID == StreamID.Null)
                                {
                                    buffer[offset] = (byte)1;                                     // Write the non-native nil indicator
                                    offset++;
                                }
                                else
                                {
                                                                        #if USEDATATYPESINNATIVEROW
                                    if (DataType.Columns[index].DataType.Equals(_row.DataTypes[index]))
                                    {
                                                                        #endif
                                    buffer[offset] = (byte)3;                                             // Write the native standard value indicator
                                    offset++;
                                                                        #if USEDATATYPESINNATIVEROW
                                }
                                else
                                {
                                    buffer[offset] = (byte)5;                                             // Write the native specialized value indicator
                                    offset++;
                                    if (stringConveyor == null)
                                    {
                                        stringConveyor = Manager.GetConveyor(Manager.DataTypes.SystemString);
                                    }
                                    elementSize = stringConveyor.GetSize(_row.DataTypes[index].Name);
                                    stringConveyor.Write(_row.DataTypes[index].Name, buffer, offset);                                             // Write the name of the data type of the value
                                    offset += elementSize;
                                }
                                                                        #endif

                                    if (expandStreams)
                                    {
                                        stream = (Stream)_writeList[index];
                                        int32Conveyor.Write(Convert.ToInt32(stream.Length), buffer, offset);
                                        offset += sizeof(int);
                                        stream.Read(buffer, offset, (int)stream.Length);
                                        offset += (int)stream.Length;
                                        stream.Close();
                                    }
                                    else
                                    {
                                        int64Conveyor.Write((long)streamID.Value, buffer, offset);
                                        offset += sizeof(long);
                                    }
                                }
                            }
                            else
                            {
                                                                #if USEDATATYPESINNATIVEROW
                                if (DataType.Columns[index].DataType.Equals(_row.DataTypes[index]))
                                {
                                                                #endif
                                buffer[offset] = (byte)2;                                         // Write the native standard value indicator
                                offset++;
                                                                #if USEDATATYPESINNATIVEROW
                            }
                            else
                            {
                                buffer[offset] = (byte)4;                                         // Write the native specialized value indicator
                                offset++;
                                if (stringConveyor == null)
                                {
                                    stringConveyor = Manager.GetConveyor(Manager.DataTypes.SystemString);
                                }
                                elementSize = stringConveyor.GetSize(_row.DataTypes[index].Name);
                                stringConveyor.Write(_row.DataTypes[index].Name, buffer, offset);                                         // Write the name of the data type of the value
                                offset += elementSize;
                            }
                                                                #endif

                                conveyor = Manager.GetConveyor(scalarType);
                                if (conveyor.IsStreaming)
                                {
                                    stream = (Stream)_writeList[index];
                                    int32Conveyor.Write(Convert.ToInt32(stream.Length), buffer, offset);                 // Write the length of the value
                                    offset += sizeof(int);
                                    stream.Read(buffer, offset, (int)stream.Length);                                     // Write the value of this scalar
                                    offset += (int)stream.Length;
                                }
                                else
                                {
                                    elementSize = (int)_writeList[index];                                     // Write the length of the value
                                    int32Conveyor.Write(elementSize, buffer, offset);
                                    offset += sizeof(int);
                                    conveyor.Write(_row.Values[index], buffer, offset);                                     // Write the value of this scalar
                                    offset += elementSize;
                                }
                            }
                        }
                        else
                        {
                                                        #if USEDATATYPESINNATIVEROW
                            if (DataType.Columns[index].DataType.Equals(_row.DataTypes[index]))
                            {
                                                        #endif
                            buffer[offset] = (byte)2;                                     // Write the native standard value indicator
                            offset++;
                                                        #if USEDATATYPESINNATIVEROW
                        }
                        else
                        {
                            buffer[offset] = (byte)4;                                     // Write the native specialized value indicator
                            offset++;
                            if (stringConveyor == null)
                            {
                                stringConveyor = Manager.GetConveyor(Manager.DataTypes.SystemString);
                            }
                            elementSize = stringConveyor.GetSize(_row.DataTypes[index].Name);
                            stringConveyor.Write(_row.DataTypes[index].Name, buffer, offset);                                     // Write the name of the data type of the value
                            offset += elementSize;
                        }
                                                        #endif

                            element     = _elementWriteList[index];
                            elementSize = (int)_writeList[index];
                            int32Conveyor.Write(elementSize, buffer, offset);
                            offset += sizeof(int);
                            element.WriteToPhysical(buffer, offset, expandStreams);                             // Write the physical representation of the value;
                            offset += elementSize;
                            element.Dispose();
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
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;
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        /*
         *      List Value Format ->
         *
         *              00 -> 0 - Indicates that the list is nil, no data follows 1 - Indicates that the list is non-nil, data follows as specified
         *              01 -> 0 - Indicates that non-native values are stored as a StreamID 1 - Indicates non-native values are stored inline
         *              02-05 -> Number of elements in the list
         *              06-XX -> N List Elements
         *
         *      List Element Format ->
         *
         *              There are five possibilities for an element ->
         *                      Nil Native
         *                      Nil Non-Native (StreamID.Null)
         *                      Standard Native
         *                      Standard Non-Native
         *                      Specialized Native
         *                      Specialized Non-Native
         *
         *                      For non-native values, the value will be expanded or not dependending on the expanded setting for the list value
         *
         *              00	-> 0 - 5
         *                      0 if the list contains a native nil for this element - no data follows
         *                      1 if the list contains a non-native nil for this element - no data follows
         *                      2 if the list contains a native value of the element type of the list
         *                              01-04 -> The length of the physical representation of this value
         *                              05-XX -> The physical representation of this value
         *                      3 if the list contains a non-native value of the element type of the list
         *                              01-04 -> The length of the physical representation of this value
         *                              05-XX -> The physical representation of this value (expanded based on the expanded setting for the list value)
         *                      4 if the list contains a native value of some specialization of the element type of the list
         *                              01-XX -> The data type name of this value, stored using a StringConveyor
         *                              XX+1-XX+4 -> The length of the physical representation of this value
         *                              XX+5-YY -> The physical representation of this value
         *                      5 if the list contains a non-native value of some specialization of the element type of the list
         *                              01-XX -> The data type name of this value, stored using a StringConveyor
         *                              XX+1-XX+4 -> The lnegth of the physical representation of this value
         *                              XX+5-YY -> The physical representation of this value (expanded based on the expanded setting for the list value)
         */

        public override int GetPhysicalSize(bool expandStreams)
        {
            int size = 1;             // write the value indicator

            if (!IsNil)
            {
                size             += sizeof(int) + 1;        // write the extended streams indicator and the number of elements in the list
                _writeList        = new object[Count()];    // list for saving the sizes or streams of each element in the list
                _elementWriteList = new DataValue[Count()]; // list for saving host representations of values between the GetPhysicalSize and WriteToPhysical calls
                Stream             stream;
                StreamID           streamID;
                Schema.IScalarType scalarType;
                IDataValue         element;
                int elementSize;
                for (int index = 0; index < _writeList.Length; index++)
                {
                    size += sizeof(byte);                     // write a value indicator
                    if (_list.Values[index] != null)
                    {
                        if (!DataType.ElementType.Equals(_list.DataTypes[index]))
                        {
                            size += Manager.GetConveyor(Manager.DataTypes.SystemString).GetSize(_list.DataTypes[index].Name);                             // write the name of the data type of the value
                        }
                        scalarType = _list.DataTypes[index] as Schema.IScalarType;
                        if ((scalarType != null) && !scalarType.IsCompound)
                        {
                            if (_list.Values[index] is StreamID)
                            {
                                // If this is a non-native scalar
                                streamID = (StreamID)_list.Values[index];
                                if (expandStreams)
                                {
                                    if (streamID != StreamID.Null)
                                    {
                                        stream            = Manager.StreamManager.Open((StreamID)_list.Values[index], LockMode.Exclusive);
                                        _writeList[index] = stream;
                                        size += sizeof(int) + (int)stream.Length;
                                    }
                                }
                                else
                                {
                                    if (streamID != StreamID.Null)
                                    {
                                        elementSize       = StreamID.CSizeOf;
                                        _writeList[index] = elementSize;
                                        size += elementSize;
                                    }
                                }
                            }
                            else
                            {
                                Streams.IConveyor conveyor = Manager.GetConveyor(scalarType);
                                if (conveyor.IsStreaming)
                                {
                                    stream            = new MemoryStream(64);
                                    _writeList[index] = stream;
                                    conveyor.Write(_list.Values[index], stream);
                                    stream.Position = 0;
                                    size           += sizeof(int) + (int)stream.Length;
                                }
                                else
                                {
                                    elementSize       = conveyor.GetSize(_list.Values[index]);
                                    _writeList[index] = elementSize;
                                    size += sizeof(int) + elementSize;;
                                }
                            }
                        }
                        else
                        {
                            element = DataValue.FromNativeList(Manager, DataType, _list, index);
                            _elementWriteList[index] = element;
                            elementSize       = element.GetPhysicalSize(expandStreams);
                            _writeList[index] = elementSize;
                            size += sizeof(int) + elementSize;
                        }
                    }
                }
            }
            return(size);
        }