Skip to content

Commit 4c541ac

Browse files
authored
Indexed fields as spans (#780)
* Added a rough outline of my C# value type encoder/decoder. * Revert "Added a rough outline of my C# value type encoder/decoder." This reverts commit b34653f. * Expose an array property as a span * Get the Length property right * Get the type right * Add field-as-span method * Set the type correctly
1 parent de2e1b0 commit 4c541ac

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/csharp/CSharpGenerator.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,27 @@ private CharSequence generateArrayProperty(
889889
generateDocumentation(indent, fieldToken),
890890
propName, typeName, fieldLength, typePrefix, offset, typeSize, byteOrderStr));
891891

892+
// Expose the array as a ReadOnlySpan
893+
sb.append(String.format("\n" +
894+
"%1$s" +
895+
indent + "public ReadOnlySpan<%2$s> %3$s\n" +
896+
indent + "{\n" +
897+
indent + INDENT + "get => _buffer.AsReadOnlySpan<%2$s>(_offset + %4$s, %3$sLength);\n" +
898+
indent + INDENT + "set => value.CopyTo(_buffer.AsSpan<%2$s>(_offset + %4$s, %3$sLength));\n" +
899+
indent + "}\n",
900+
generateDocumentation(indent, fieldToken),
901+
typeName, propName, offset));
902+
903+
// Expose the array as a Span
904+
sb.append(String.format("\n" +
905+
"%1$s" +
906+
indent + "public Span<%2$s> %3$sAsSpan()\n" +
907+
indent + "{\n" +
908+
indent + INDENT + "return _buffer.AsSpan<%2$s>(_offset + %4$s, %3$sLength);\n" +
909+
indent + "}\n",
910+
generateDocumentation(indent, fieldToken),
911+
typeName, propName, offset));
912+
892913
if (typeToken.encoding().primitiveType() == PrimitiveType.CHAR)
893914
{
894915
generateCharacterEncodingMethod(sb, propertyName, typeToken.encoding().characterEncoding(), indent);

0 commit comments

Comments
 (0)