示例#1
0
        public object ReadPrimitive <T>()
        {
            if (typeof(T) == typeof(string))
            {
                throw new UsCmdIOError(UsCmdIOErrorCode.TypeMismatched);
            }

            if (_readOffset + Marshal.SizeOf(typeof(T)) > _buffer.Length)
            {
                throw new UsCmdIOError(UsCmdIOErrorCode.ReadOverflow);
            }

            object val = UsGeneric.Convert <T>(_buffer, _readOffset);

            _readOffset += Marshal.SizeOf(typeof(T));
            return(val);
        }
示例#2
0
        public void WritePrimitive <T>(T value)
        {
            if (typeof(T) == typeof(string))
            {
                throw new UsCmdIOError(UsCmdIOErrorCode.TypeMismatched);
            }

            if (_writeOffset + Marshal.SizeOf(typeof(T)) > _buffer.Length)
            {
                throw new UsCmdIOError(UsCmdIOErrorCode.WriteOverflow);
            }

            byte[] byteArray = UsGeneric.Convert(value);
            if (byteArray == null)
            {
                throw new UsCmdIOError(UsCmdIOErrorCode.TypeMismatched);
            }

            byteArray.CopyTo(_buffer, _writeOffset);
            _writeOffset += Marshal.SizeOf(typeof(T));
        }