diff options
author | Wouter van Oortmerssen <wvo@google.com> | 2015-12-07 17:35:57 -0800 |
---|---|---|
committer | Wouter van Oortmerssen <wvo@google.com> | 2015-12-07 17:35:57 -0800 |
commit | 96cd275603573ebdea3b6c61d459ea438f3b1525 (patch) | |
tree | 134ad026e8b2ed07fa66adeac3db1610e932e550 /src | |
parent | 42b48bd55faf0e4a2a957f03e1bd3817fd6b25f0 (diff) | |
parent | e083e466b85c1ae512193cee74e0dbd60be5ab87 (diff) | |
download | flatbuffers-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.cpp | 36 |
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 |