real-logic / simple-binary-encoding

Simple Binary Encoding (SBE) - High Performance Message Codec
Apache License 2.0
3.11k stars 521 forks source link

[csharp] use IDirectBuffer implementation from Agrona.NET #492

Open bpb1 opened 7 years ago

bpb1 commented 7 years ago

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

mjpt777 commented 6 years ago

@JPWatson Should anything be done on this?

swimtver commented 5 years ago

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.

mjpt777 commented 5 years ago

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

JPWatson commented 5 years ago

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);
}
swimtver commented 5 years ago

@mjpt777 , @JPWatson thank you very much!

juddgaddie commented 5 years ago

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

JPWatson commented 5 years ago

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?

juddgaddie commented 5 years ago

That would be much appreciated.

JPWatson commented 5 years ago

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

JPWatson commented 5 years ago

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

JPWatson commented 5 years ago

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

juddgaddie commented 5 years ago

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 ?

JPWatson commented 5 years ago

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

juddgaddie commented 5 years ago

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

JPWatson commented 5 years ago

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

juddgaddie commented 5 years ago

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 commented 5 years ago

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