Cxx11BindingsSharp 1.4.0
See the version list below for details.
dotnet add package Cxx11BindingsSharp --version 1.4.0
NuGet\Install-Package Cxx11BindingsSharp -Version 1.4.0
<PackageReference Include="Cxx11BindingsSharp" Version="1.4.0" />
<PackageVersion Include="Cxx11BindingsSharp" Version="1.4.0" />
<PackageReference Include="Cxx11BindingsSharp" />
paket add Cxx11BindingsSharp --version 1.4.0
#r "nuget: Cxx11BindingsSharp, 1.4.0"
#:package Cxx11BindingsSharp@1.4.0
#addin nuget:?package=Cxx11BindingsSharp&version=1.4.0
#tool nuget:?package=Cxx11BindingsSharp&version=1.4.0
Cxx11BindingsSharp
Introduction
Provide a thin layer to wrap a System.IO.Stream
in C# to a portable C++ stream (std::streambuf
).
The intermediate C layer is exposed and can be used directly in a C11 project.
The custom std::streambuf
implementation simply uses the portable C layer to call back into the C# stream.
This is somewhat related to System.Runtime.InteropServices.ComTypes.IStream
on windows.
Typical usage in your library
In your C# library, you can now write something like:
using Cxx11BindingsSharp;
public void AcmeConvert(System.IO.Stream src, System.IO.Stream dst)
{
var srcWrap = new ManagedC11Stream(src);
var dstWrap = new ManagedC11Stream(dst);
if (NativeService.acme_convert(srcWrap, dstWrap)<0)
{
throw new ArgumentException($"Cannot convert");
}
}
This will expose a C# Stream-like interface to your C11 library.
The only requirement is the following P/Invoke declaration in your C# code:
[DllImport(NativeLibraryName, CallingConvention = CallingConvention.Cdecl)]
internal static extern int acme_convert(C11StreamHandle src, C11StreamHandle dst);
On the C11 side, export your function as:
ACME_EXPORT int acme_convert(c11_stream* src, c11_stream* dst);
At this point you can either re-use one of the existing std::streambuf
wrappers, or directly use the c11_stream
interface if you prefer to work with C-style APIs.
Implementation details
The stream abstraction is simply defined with a set of five function pointers:
struct c11_stream {
read_fn read;
write_fn write;
seek_fn seek;
flush_fn flush;
trunc_fn trunc;
};
Where function declarations are:
typedef int32_t (*read_fn)(byte* buffer, int32_t count);
typedef int32_t (*write_fn)(const byte* buffer, int32_t count);
typedef int64_t (*seek_fn)(int64_t off, int dir);
typedef int (*flush_fn)(void);
typedef int64_t (*trunc_fn)(int64_t size);
See:
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.