simple-binary-encoding
simple-binary-encoding copied to clipboard
[csharp] use IDirectBuffer implementation from Agrona.NET
It would be nice if Aeron.NET and the generated c# from sbe referred to the same IDirectBuffer interface. I guess this is dependent on https://github.com/AdaptiveConsulting/Aeron.NET/issues/57
@JPWatson Should anything be done on this?
Hello, Do you have any plans to implement it? Or could you give me some tips how properly manipulate bytes from Agrona IDirectBuffer to DirectBuffer from this package.
Thanks for advance.
@swimtver I hear that @JPWatson plans to push a C# generator that uses this.
Yes, I have been working on it. We've got an early stage generator for SBE that uses .NET implementation of Agrona.
For the time being, there is a workaround. You can use the pointers to wrap the same underlying memory.
public static unsafe void Wrap(this DirectBuffer target, UnsafeBuffer source, int length)
{
target.Wrap((byte*) source.BufferPointer.ToPointer(), length);
}
@mjpt777 , @JPWatson thank you very much!
@JPWatson Any update on how you are getting along with this?
We have been incubating a generator that mirrors the Java generator and uses the Agrona.NET interfaces. Would be happy to share that if you're interested?
That would be much appreciated.
@juddgaddie Feel free to have a place around with this: https://github.com/JPWatson/sbe-generators
Eventually, I hope to get this into the main repository once it has some tests around it.
I also use this generator in Aeron.NET to generate the Archive/Cluster codecs. https://github.com/AdaptiveConsulting/Aeron.NET/blob/master/scripts/generate-archive-codecs.bat
Source for this build of the JAR is here: https://github.com/JPWatson/simple-binary-encoding/commits/csharp-update
Thanks for sharing, @JPWatson which version of CSharpGenerator is more up to date https://github.com/JPWatson/sbe-generators or https://github.com/JPWatson/simple-binary-encoding/commits/csharp-update ?
AFAIR there isn't any difference between the generators themselves.
@JPWatson is the bounds checking not implemented simply because you didn't get around to it or is there any technical reason?
@juddgaddie There is bound checking code in UnsafeBuffer but it's set at compile time rather than runtime. From what I remember, there just wasn't an obvious way to mirror the same behaviour as the java version.
Like Java, C# (unlike c/c++) is typically not compiled from sources for that reason I think the bounds checking would be better served with a runtime toggle we could use system environment variables (the same approach as c or c++ code uses for runtime configuration)
I also would think the default build that goes to Nuget should have bounds checking enabled by default. @JPWatson thoughts ?
Happy to send PRs
@JPWatson Example of what I mean here: https://gist.github.com/juddgaddie/eeafbbb195a332bf72808748cdcd4336