예제 #1
0
        public override void WriteToPhysical(byte[] buffer, int offset, bool expandStreams)
        {
            // Write scalar header
            byte header = (byte)(IsNil ? 0 : 1);

            header        |= (byte)(IsNative ? 2 : 0);
            header        |= (byte)(expandStreams ? 4 : 0);
            buffer[offset] = header;
            offset++;

            if (!IsNil)
            {
                if (IsNative)
                {
                    if (DataType.IsCompound)
                    {
                        _writeValue.WriteToPhysical(buffer, offset, expandStreams);
                        _writeValue.Dispose();
                        _writeValue = null;
                    }
                    else
                    {
                        Streams.IConveyor conveyor = Manager.GetConveyor(DataType);
                        if (conveyor.IsStreaming)
                        {
                            _writeStream.Position = 0;
                            _writeStream.Read(buffer, offset, (int)_writeStream.Length);
                            _writeStream.Close();
                        }
                        else
                        {
                            conveyor.Write(Value, buffer, offset);
                        }
                    }
                }
                else
                {
                    if (expandStreams)
                    {
                        _writeStream.Position = 0;
                        _writeStream.Read(buffer, offset, (int)_writeStream.Length);
                        _writeStream.Close();
                    }
                    else
                    {
                        ((StreamID)Value).Write(buffer, offset);
                    }
                }
            }
        }
예제 #2
0
        public override object InternalExecute(Program program, object[] arguments)
        {
            IDataValue tempValue = arguments[0] as IDataValue;

            if (tempValue == null)
            {
                tempValue = DataValue.FromNative(program.ValueManager, arguments[0]);
            }

            if (tempValue.IsPhysicalStreaming)
            {
                using (Stream stream = tempValue.OpenStream())
                {
                    return((int)CRC32Utility.GetCRC32(stream));
                }
            }
            else
            {
                byte[] physical = new byte[tempValue.GetPhysicalSize(true)];
                tempValue.WriteToPhysical(physical, 0, true);
                return((int)CRC32Utility.GetCRC32(physical));
            }
        }