mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-10 15:16:28 +00:00
C# support for directly reading and writting to memory other than byte[]. For example, ByteBuffer can be initialized with a custom allocator which uses shared memory / memory mapped files. (#4886)
Public access to the backing buffer uses Span<T> instead of ArraySegment<T>. Writing to the buffer now supports Span<T> in addition to T[]. To maintain backwards compatibility ENABLE_SPAN_T must be defined.
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
e1f48ad35a
commit
d0321df8cf
@@ -1113,12 +1113,21 @@ class GeneralGenerator : public BaseGenerator {
|
||||
code += "); }\n";
|
||||
break;
|
||||
case IDLOptions::kCSharp:
|
||||
code += "#if ENABLE_SPAN_T\n";
|
||||
code += " public Span<byte> Get";
|
||||
code += MakeCamel(field.name, lang_.first_camel_upper);
|
||||
code += "Bytes() { return ";
|
||||
code += lang_.accessor_prefix + "__vector_as_span(";
|
||||
code += NumToString(field.value.offset);
|
||||
code += "); }\n";
|
||||
code += "#else\n";
|
||||
code += " public ArraySegment<byte>? Get";
|
||||
code += MakeCamel(field.name, lang_.first_camel_upper);
|
||||
code += "Bytes() { return ";
|
||||
code += lang_.accessor_prefix + "__vector_as_arraysegment(";
|
||||
code += NumToString(field.value.offset);
|
||||
code += "); }\n";
|
||||
code += "#endif\n";
|
||||
|
||||
// For direct blockcopying the data into a typed array
|
||||
code += " public ";
|
||||
|
||||
Reference in New Issue
Block a user