simple-binary-encoding icon indicating copy to clipboard operation
simple-binary-encoding copied to clipboard

[csharp] use IDirectBuffer implementation from Agrona.NET

Open bpb1 opened this issue 7 years ago • 17 comments

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

bpb1 avatar Aug 05 '17 13:08 bpb1

@JPWatson Should anything be done on this?

mjpt777 avatar Aug 02 '18 19:08 mjpt777

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 avatar Nov 28 '18 09:11 swimtver

@swimtver I hear that @JPWatson plans to push a C# generator that uses this.

mjpt777 avatar Nov 28 '18 10:11 mjpt777

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

JPWatson avatar Nov 28 '18 10:11 JPWatson

@mjpt777 , @JPWatson thank you very much!

swimtver avatar Nov 28 '18 10:11 swimtver

@JPWatson Any update on how you are getting along with this?

juddgaddie avatar Mar 21 '19 17:03 juddgaddie

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?

JPWatson avatar Mar 21 '19 17:03 JPWatson

That would be much appreciated.

juddgaddie avatar Mar 21 '19 20:03 juddgaddie

@juddgaddie Feel free to have a place around with this: https://github.com/JPWatson/sbe-generators

JPWatson avatar Mar 21 '19 23:03 JPWatson

Eventually, I hope to get this into the main repository once it has some tests around it.

JPWatson avatar Mar 21 '19 23:03 JPWatson

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

JPWatson avatar Mar 21 '19 23:03 JPWatson

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 ?

juddgaddie avatar Mar 22 '19 10:03 juddgaddie

AFAIR there isn't any difference between the generators themselves.

JPWatson avatar Mar 22 '19 15:03 JPWatson

@JPWatson is the bounds checking not implemented simply because you didn't get around to it or is there any technical reason?

juddgaddie avatar Apr 02 '19 19:04 juddgaddie

@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.

JPWatson avatar Apr 05 '19 21:04 JPWatson

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

juddgaddie avatar Apr 18 '19 11:04 juddgaddie

@JPWatson Example of what I mean here: https://gist.github.com/juddgaddie/eeafbbb195a332bf72808748cdcd4336

juddgaddie avatar Apr 26 '19 15:04 juddgaddie