diff options
| author | Konstantin <const@const.me> | 2023-01-16 14:52:43 +0100 |
|---|---|---|
| committer | Konstantin <const@const.me> | 2023-01-16 14:52:43 +0100 |
| commit | 8c4603c73675958efc960fbd4bb599a2909d106a (patch) | |
| tree | 714dc6fc9a1672d5fd7f89676b97e10959662abc /ComLightLib/streams.h | |
| parent | 990a8d0dbaefc996244097397259e92758b15cce (diff) | |
Source codes
Diffstat (limited to 'ComLightLib/streams.h')
| -rw-r--r-- | ComLightLib/streams.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/ComLightLib/streams.h b/ComLightLib/streams.h new file mode 100644 index 0000000..87680e1 --- /dev/null +++ b/ComLightLib/streams.h @@ -0,0 +1,61 @@ +#pragma once +#include <vector> +#include "comLightCommon.h" + +// COM interfaces to marshal streams across the interop. +namespace ComLight +{ + enum struct eSeekOrigin : uint8_t + { + Begin = 0, + Current = 1, + End = 2 + }; + + namespace details + { + template<class E> + inline size_t sizeofVector( const std::vector<E>& vec ) + { + return sizeof( E ) * vec.size(); + } + } + + // COM interface for readonly stream. You'll get these interfaces what you use [ReadStream] attribute in C#. + struct DECLSPEC_NOVTABLE iReadStream : public IUnknown + { + DEFINE_INTERFACE_ID( "006af6db-734e-4595-8c94-19304b2389ac" ); + + virtual HRESULT COMLIGHTCALL read( void* lpBuffer, int nNumberOfBytesToRead, int &lpNumberOfBytesRead ) = 0; + virtual HRESULT COMLIGHTCALL seek( int64_t offset, eSeekOrigin origin ) = 0; + virtual HRESULT COMLIGHTCALL getPosition( int64_t& position ) = 0; + virtual HRESULT COMLIGHTCALL getLength( int64_t& length ) = 0; + + template<class E> + inline HRESULT read( std::vector<E>& vec ) + { + const int cb = (int)details::sizeofVector( vec ); + int cbRead = 0; + CHECK( read( vec.data(), cb, cbRead ) ); + if( cbRead >= cb ) + return S_OK; + return E_EOF; + } + }; + + // COM interface for readonly stream. You'll get these interfaces what you use [WriteStream] attribute in C#. + struct DECLSPEC_NOVTABLE iWriteStream : public IUnknown + { + DEFINE_INTERFACE_ID( "d7c3eb39-9170-43b9-ba98-2ea1f2fed8a8" ); + + virtual HRESULT COMLIGHTCALL write( const void* lpBuffer, int nNumberOfBytesToWrite ) = 0; + virtual HRESULT COMLIGHTCALL flush() = 0; + + template<class E> + inline HRESULT write( const std::vector<E>& vec ) + { + const int cb = (int)details::sizeofVector( vec ); + return write( vec.data(), cb ); + } + }; +}
\ No newline at end of file |
