You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Create a vehicle code of the correct encoding
VehicleCode = Encoding.GetEncoding(Car.VehicleCodeCharacterEncoding).GetBytes("abcdef");
car.SetVehicleCode(vehicleCode, 0); // second argument is offset
This is terrible. It defeats the whole point of SBE because it uses a method GetBytes() which allocates a new array of bytes, and then copies that to the direct buffer we are targeting.
We should be using this method to get the number of bytes which a particular string would generate.
We should then check that against the size available, and use this method to write to the underlying buffer.
In order to do this, we need to be able to access the underlying byte array for the DirectBuffer, and it would be best to do this through support in the generated classes.
I can't see any way of writing a string into one of the generated classes without having auxiliary buffers of bytes hanging around if I want to avoid allocations, the way the accessor methods are currently provided.
Similarly to read a string, your example is
var vehicleCode = new byte[Car.VehicleCodeLength];
car.GetVehicleCode(vehicleCode, 0);
sb.Append(Encoding.GetEncoding(Car.VehicleCodeCharacterEncoding).GetString(vehicleCode, 0, Car.VehicleCodeLength));
Which suffers from the same problem...
We should be using this method to generate a string directly (perhaps having first looked through the buffer for a terminating \0 character to establish how many of the available bytes actually comprise the string we want to extract)
The text was updated successfully, but these errors were encountered:
)
* [C#] Add more string reading/writing methods to DirectBuffer
More, hopefully efficient, mechanisms to read and write strings to and from the DirectBuffer.
* [C#] Reverted to .net45
* [C#] Reverted to .net45
* [C#] Updated Samples to use the new String methods
* [C#] Fixed checkstyle
* [C#] Cleaning
* Added Modified Benchmarks\nBoth a modified version of the the CarBenchmark which encodes and decodes to/from string; and a version wich uses the new methods to encode and decode strings
Co-authored-by: Rob Purdy <rob.purdy@iongroup.com>
Using your example in the documentation
This is terrible. It defeats the whole point of SBE because it uses a method GetBytes() which allocates a new array of bytes, and then copies that to the direct buffer we are targeting.
We should be using this method to get the number of bytes which a particular string would generate.
We should then check that against the size available, and use
this method to write to the underlying buffer.
In order to do this, we need to be able to access the underlying byte array for the DirectBuffer, and it would be best to do this through support in the generated classes.
I can't see any way of writing a string into one of the generated classes without having auxiliary buffers of bytes hanging around if I want to avoid allocations, the way the accessor methods are currently provided.
Similarly to read a string, your example is
Which suffers from the same problem...
We should be using this method to generate a string directly (perhaps having first looked through the buffer for a terminating \0 character to establish how many of the available bytes actually comprise the string we want to extract)
The text was updated successfully, but these errors were encountered: