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); }
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)); }