summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWouter van Oortmerssen <wvo@google.com>2015-12-07 17:35:57 -0800
committerWouter van Oortmerssen <wvo@google.com>2015-12-07 17:35:57 -0800
commit96cd275603573ebdea3b6c61d459ea438f3b1525 (patch)
tree134ad026e8b2ed07fa66adeac3db1610e932e550 /src
parent42b48bd55faf0e4a2a957f03e1bd3817fd6b25f0 (diff)
parente083e466b85c1ae512193cee74e0dbd60be5ab87 (diff)
downloadflatbuffers-96cd275603573ebdea3b6c61d459ea438f3b1525.tar.gz
flatbuffers-96cd275603573ebdea3b6c61d459ea438f3b1525.tar.bz2
flatbuffers-96cd275603573ebdea3b6c61d459ea438f3b1525.zip
Merge pull request #288 from mfcollins3/csharp-byte-buffer
Add Get Bytes Method Generator for C#
Diffstat (limited to 'src')
-rw-r--r--src/idl_gen_general.cpp36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/idl_gen_general.cpp b/src/idl_gen_general.cpp
index 936892fe..70c5badf 100644
--- a/src/idl_gen_general.cpp
+++ b/src/idl_gen_general.cpp
@@ -145,7 +145,7 @@ LanguageParameters language_parameters[] = {
"",
"Position",
"Offset",
- "using FlatBuffers;\n\n",
+ "using System;\nusing FlatBuffers;\n\n",
{
nullptr,
"///",
@@ -852,17 +852,29 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
code += "}\n";
}
// Generate a ByteBuffer accessor for strings & vectors of scalars.
- if (((field.value.type.base_type == BASE_TYPE_VECTOR &&
- IsScalar(field.value.type.VectorType().base_type)) ||
- field.value.type.base_type == BASE_TYPE_STRING) &&
- lang.language == IDLOptions::kJava) {
- code += " public ByteBuffer ";
- code += MakeCamel(field.name, lang.first_camel_upper);
- code += "AsByteBuffer() { return __vector_as_bytebuffer(";
- code += NumToString(field.value.offset) + ", ";
- code += NumToString(field.value.type.base_type == BASE_TYPE_STRING ? 1 :
- InlineSize(field.value.type.VectorType()));
- code += "); }\n";
+ if ((field.value.type.base_type == BASE_TYPE_VECTOR &&
+ IsScalar(field.value.type.VectorType().base_type)) ||
+ field.value.type.base_type == BASE_TYPE_STRING) {
+ switch (lang.language) {
+ case IDLOptions::kJava:
+ code += " public ByteBuffer ";
+ code += MakeCamel(field.name, lang.first_camel_upper);
+ code += "AsByteBuffer() { return __vector_as_bytebuffer(";
+ code += NumToString(field.value.offset) + ", ";
+ code += NumToString(field.value.type.base_type == BASE_TYPE_STRING ? 1 :
+ InlineSize(field.value.type.VectorType()));
+ code += "); }\n";
+ break;
+ case IDLOptions::kCSharp:
+ code += " public ArraySegment<byte>? Get";
+ code += MakeCamel(field.name, lang.first_camel_upper);
+ code += "Bytes() { return __vector_as_arraysegment(";
+ code += NumToString(field.value.offset);
+ code += "); }\n";
+ break;
+ default:
+ break;
+ }
}
// generate mutators for scalar fields or vectors of scalars