I followed the example code from Example00-Basics with a custom class MessagePacket, but the following code won't compile:
MessagePacket packet = /* ... */
int maxSize = MessagePacket.Serializer.GetMaxSize(packet);
byte[] buffer = new byte[maxSize];
int bytesWritten = MessagePacket.Serializer.Write(buffer, packet);
The generated Write method has an additional TSpanWriter parameter:
int Write<TSpanWriter>(TSpanWriter writer, Span<byte> destination, T item) where TSpanWriter : ISpanWriter;
Apparently I can provide a default SpanWriter like this:
int bytesWritten = MessagePacket.Serializer.Write(default(FlatSharp.SpanWriter), buffer, packet);
And now the code works as intended, but I don't know what this means. Where does the extra parameter come from, and what am I supposed to do? Am I doing something wrong, or did the API change and the examples haven't been updated yet?
Similarly, the following won't compile either:
byte[] data = /* ... */
var messagePacket = MessagePacket.Serializer.Parse(data);
as the Parse method expects an ArrayInputBuffer instead of a byte[] array. I can fix that like this:
var buffer = new FlatSharp.ArrayInputBuffer(data);
var messagePacket = MessagePacket.Serializer.Parse(buffer);
But again, I don't know why the method looks like that.
I found out this is a duplicate of #286. Adding using FlatSharp; makes the extension methods from ISerializerExtensions.cs available that are used in the example code.
I followed the example code from
Example00-Basics
with a custom classMessagePacket
, but the following code won't compile:The generated
Write
method has an additionalTSpanWriter
parameter:Apparently I can provide a default
SpanWriter
like this:And now the code works as intended, but I don't know what this means. Where does the extra parameter come from, and what am I supposed to do? Am I doing something wrong, or did the API change and the examples haven't been updated yet?
Similarly, the following won't compile either:
as the
Parse
method expects anArrayInputBuffer
instead of abyte[]
array. I can fix that like this:But again, I don't know why the method looks like that.
Could someone please clarify this?