Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
flatbuffers
Commits
c44bc6a7
Commit
c44bc6a7
authored
Dec 09, 2015
by
Wouter van Oortmerssen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/google/flatbuffers
parents
6fba6b6e
96cd2756
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
62 additions
and
4 deletions
+62
-4
Table.cs
net/FlatBuffers/Table.cs
+15
-0
idl_gen_general.cpp
src/idl_gen_general.cpp
+16
-4
Assert.cs
tests/FlatBuffers.Test/Assert.cs
+8
-0
FlatBuffersExampleTests.cs
tests/FlatBuffers.Test/FlatBuffersExampleTests.cs
+13
-0
Monster.cs
tests/MyGame/Example/Monster.cs
+5
-0
Stat.cs
tests/MyGame/Example/Stat.cs
+2
-0
Test.cs
tests/MyGame/Example/Test.cs
+1
-0
TestSimpleTableWithEnum.cs
tests/MyGame/Example/TestSimpleTableWithEnum.cs
+1
-0
Vec3.cs
tests/MyGame/Example/Vec3.cs
+1
-0
No files found.
net/FlatBuffers/Table.cs
View file @
c44bc6a7
...
@@ -67,6 +67,21 @@ namespace FlatBuffers
...
@@ -67,6 +67,21 @@ namespace FlatBuffers
return
offset
+
bb
.
GetInt
(
offset
)
+
sizeof
(
int
);
// data starts after the length
return
offset
+
bb
.
GetInt
(
offset
)
+
sizeof
(
int
);
// data starts after the length
}
}
// Get the data of a vector whoses offset is stored at "offset" in this object as an
// ArraySegment<byte>. If the vector is not present in the ByteBuffer,
// then a null value will be returned.
protected
ArraySegment
<
byte
>?
__vector_as_arraysegment
(
int
offset
)
{
var
o
=
this
.
__offset
(
offset
);
if
(
0
==
o
)
{
return
null
;
}
var
pos
=
this
.
__vector
(
o
);
var
len
=
this
.
__vector_len
(
o
);
return
new
ArraySegment
<
byte
>(
this
.
bb
.
Data
,
pos
,
len
);
}
// Initialize any Table-derived type to point to the union at the given offset.
// Initialize any Table-derived type to point to the union at the given offset.
protected
TTable
__union
<
TTable
>(
TTable
t
,
int
offset
)
where
TTable
:
Table
protected
TTable
__union
<
TTable
>(
TTable
t
,
int
offset
)
where
TTable
:
Table
{
{
...
...
src/idl_gen_general.cpp
View file @
c44bc6a7
...
@@ -145,7 +145,7 @@ LanguageParameters language_parameters[] = {
...
@@ -145,7 +145,7 @@ LanguageParameters language_parameters[] = {
""
,
""
,
"Position"
,
"Position"
,
"Offset"
,
"Offset"
,
"using FlatBuffers;
\n\n
"
,
"using
System;
\n
using
FlatBuffers;
\n\n
"
,
{
{
nullptr
,
nullptr
,
"///"
,
"///"
,
...
@@ -852,10 +852,11 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
...
@@ -852,10 +852,11 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
code
+=
"}
\n
"
;
code
+=
"}
\n
"
;
}
}
// Generate a ByteBuffer accessor for strings & vectors of scalars.
// Generate a ByteBuffer accessor for strings & vectors of scalars.
if
((
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
&&
if
((
field
.
value
.
type
.
base_type
==
BASE_TYPE_VECTOR
&&
IsScalar
(
field
.
value
.
type
.
VectorType
().
base_type
))
||
IsScalar
(
field
.
value
.
type
.
VectorType
().
base_type
))
||
field
.
value
.
type
.
base_type
==
BASE_TYPE_STRING
)
&&
field
.
value
.
type
.
base_type
==
BASE_TYPE_STRING
)
{
lang
.
language
==
IDLOptions
::
kJava
)
{
switch
(
lang
.
language
)
{
case
IDLOptions
:
:
kJava
:
code
+=
" public ByteBuffer "
;
code
+=
" public ByteBuffer "
;
code
+=
MakeCamel
(
field
.
name
,
lang
.
first_camel_upper
);
code
+=
MakeCamel
(
field
.
name
,
lang
.
first_camel_upper
);
code
+=
"AsByteBuffer() { return __vector_as_bytebuffer("
;
code
+=
"AsByteBuffer() { return __vector_as_bytebuffer("
;
...
@@ -863,6 +864,17 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
...
@@ -863,6 +864,17 @@ static void GenStruct(const LanguageParameters &lang, const Parser &parser,
code
+=
NumToString
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_STRING
?
1
:
code
+=
NumToString
(
field
.
value
.
type
.
base_type
==
BASE_TYPE_STRING
?
1
:
InlineSize
(
field
.
value
.
type
.
VectorType
()));
InlineSize
(
field
.
value
.
type
.
VectorType
()));
code
+=
"); }
\n
"
;
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
// generate mutators for scalar fields or vectors of scalars
...
...
tests/FlatBuffers.Test/Assert.cs
View file @
c44bc6a7
...
@@ -107,6 +107,14 @@ namespace FlatBuffers.Test
...
@@ -107,6 +107,14 @@ namespace FlatBuffers.Test
}
}
}
}
public
static
void
IsFalse
(
bool
value
)
{
if
(
value
)
{
throw
new
AssertFailedException
(
false
,
value
);
}
}
public
static
void
Throws
<
T
>(
Action
action
)
where
T
:
Exception
public
static
void
Throws
<
T
>(
Action
action
)
where
T
:
Exception
{
{
var
caught
=
false
;
var
caught
=
false
;
...
...
tests/FlatBuffers.Test/FlatBuffersExampleTests.cs
View file @
c44bc6a7
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
*/
*/
using
System.IO
;
using
System.IO
;
using
System.Text
;
using
MyGame.Example
;
using
MyGame.Example
;
namespace
FlatBuffers.Test
namespace
FlatBuffers.Test
...
@@ -184,6 +185,18 @@ namespace FlatBuffers.Test
...
@@ -184,6 +185,18 @@ namespace FlatBuffers.Test
Assert
.
AreEqual
(
"test2"
,
monster
.
GetTestarrayofstring
(
1
));
Assert
.
AreEqual
(
"test2"
,
monster
.
GetTestarrayofstring
(
1
));
Assert
.
AreEqual
(
false
,
monster
.
Testbool
);
Assert
.
AreEqual
(
false
,
monster
.
Testbool
);
var
nameBytes
=
monster
.
GetNameBytes
().
Value
;
Assert
.
AreEqual
(
"MyMonster"
,
Encoding
.
UTF8
.
GetString
(
nameBytes
.
Array
,
nameBytes
.
Offset
,
nameBytes
.
Count
));
if
(
0
==
monster
.
TestarrayofboolsLength
)
{
Assert
.
IsFalse
(
monster
.
GetTestarrayofboolsBytes
().
HasValue
);
}
else
{
Assert
.
IsTrue
(
monster
.
GetTestarrayofboolsBytes
().
HasValue
);
}
}
}
[
FlatBuffersTestMethod
]
[
FlatBuffersTestMethod
]
...
...
tests/MyGame/Example/Monster.cs
View file @
c44bc6a7
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
MyGame.Example
namespace
MyGame.Example
{
{
using
System
;
using
FlatBuffers
;
using
FlatBuffers
;
/// an example documentation comment: monster object
/// an example documentation comment: monster object
...
@@ -19,8 +20,10 @@ public sealed class Monster : Table {
...
@@ -19,8 +20,10 @@ public sealed class Monster : Table {
public
short
Hp
{
get
{
int
o
=
__offset
(
8
);
return
o
!=
0
?
bb
.
GetShort
(
o
+
bb_pos
)
:
(
short
)
100
;
}
}
public
short
Hp
{
get
{
int
o
=
__offset
(
8
);
return
o
!=
0
?
bb
.
GetShort
(
o
+
bb_pos
)
:
(
short
)
100
;
}
}
public
bool
MutateHp
(
short
hp
)
{
int
o
=
__offset
(
8
);
if
(
o
!=
0
)
{
bb
.
PutShort
(
o
+
bb_pos
,
hp
);
return
true
;
}
else
{
return
false
;
}
}
public
bool
MutateHp
(
short
hp
)
{
int
o
=
__offset
(
8
);
if
(
o
!=
0
)
{
bb
.
PutShort
(
o
+
bb_pos
,
hp
);
return
true
;
}
else
{
return
false
;
}
}
public
string
Name
{
get
{
int
o
=
__offset
(
10
);
return
o
!=
0
?
__string
(
o
+
bb_pos
)
:
null
;
}
}
public
string
Name
{
get
{
int
o
=
__offset
(
10
);
return
o
!=
0
?
__string
(
o
+
bb_pos
)
:
null
;
}
}
public
ArraySegment
<
byte
>?
GetNameBytes
()
{
return
__vector_as_arraysegment
(
10
);
}
public
byte
GetInventory
(
int
j
)
{
int
o
=
__offset
(
14
);
return
o
!=
0
?
bb
.
Get
(
__vector
(
o
)
+
j
*
1
)
:
(
byte
)
0
;
}
public
byte
GetInventory
(
int
j
)
{
int
o
=
__offset
(
14
);
return
o
!=
0
?
bb
.
Get
(
__vector
(
o
)
+
j
*
1
)
:
(
byte
)
0
;
}
public
int
InventoryLength
{
get
{
int
o
=
__offset
(
14
);
return
o
!=
0
?
__vector_len
(
o
)
:
0
;
}
}
public
int
InventoryLength
{
get
{
int
o
=
__offset
(
14
);
return
o
!=
0
?
__vector_len
(
o
)
:
0
;
}
}
public
ArraySegment
<
byte
>?
GetInventoryBytes
()
{
return
__vector_as_arraysegment
(
14
);
}
public
bool
MutateInventory
(
int
j
,
byte
inventory
)
{
int
o
=
__offset
(
14
);
if
(
o
!=
0
)
{
bb
.
Put
(
__vector
(
o
)
+
j
*
1
,
inventory
);
return
true
;
}
else
{
return
false
;
}
}
public
bool
MutateInventory
(
int
j
,
byte
inventory
)
{
int
o
=
__offset
(
14
);
if
(
o
!=
0
)
{
bb
.
Put
(
__vector
(
o
)
+
j
*
1
,
inventory
);
return
true
;
}
else
{
return
false
;
}
}
public
Color
Color
{
get
{
int
o
=
__offset
(
16
);
return
o
!=
0
?
(
Color
)
bb
.
GetSbyte
(
o
+
bb_pos
)
:
Color
.
Blue
;
}
}
public
Color
Color
{
get
{
int
o
=
__offset
(
16
);
return
o
!=
0
?
(
Color
)
bb
.
GetSbyte
(
o
+
bb_pos
)
:
Color
.
Blue
;
}
}
public
bool
MutateColor
(
Color
color
)
{
int
o
=
__offset
(
16
);
if
(
o
!=
0
)
{
bb
.
PutSbyte
(
o
+
bb_pos
,
(
sbyte
)
color
);
return
true
;
}
else
{
return
false
;
}
}
public
bool
MutateColor
(
Color
color
)
{
int
o
=
__offset
(
16
);
if
(
o
!=
0
)
{
bb
.
PutSbyte
(
o
+
bb_pos
,
(
sbyte
)
color
);
return
true
;
}
else
{
return
false
;
}
}
...
@@ -41,6 +44,7 @@ public sealed class Monster : Table {
...
@@ -41,6 +44,7 @@ public sealed class Monster : Table {
public
Monster
GetEnemy
(
Monster
obj
)
{
int
o
=
__offset
(
28
);
return
o
!=
0
?
obj
.
__init
(
__indirect
(
o
+
bb_pos
),
bb
)
:
null
;
}
public
Monster
GetEnemy
(
Monster
obj
)
{
int
o
=
__offset
(
28
);
return
o
!=
0
?
obj
.
__init
(
__indirect
(
o
+
bb_pos
),
bb
)
:
null
;
}
public
byte
GetTestnestedflatbuffer
(
int
j
)
{
int
o
=
__offset
(
30
);
return
o
!=
0
?
bb
.
Get
(
__vector
(
o
)
+
j
*
1
)
:
(
byte
)
0
;
}
public
byte
GetTestnestedflatbuffer
(
int
j
)
{
int
o
=
__offset
(
30
);
return
o
!=
0
?
bb
.
Get
(
__vector
(
o
)
+
j
*
1
)
:
(
byte
)
0
;
}
public
int
TestnestedflatbufferLength
{
get
{
int
o
=
__offset
(
30
);
return
o
!=
0
?
__vector_len
(
o
)
:
0
;
}
}
public
int
TestnestedflatbufferLength
{
get
{
int
o
=
__offset
(
30
);
return
o
!=
0
?
__vector_len
(
o
)
:
0
;
}
}
public
ArraySegment
<
byte
>?
GetTestnestedflatbufferBytes
()
{
return
__vector_as_arraysegment
(
30
);
}
public
bool
MutateTestnestedflatbuffer
(
int
j
,
byte
testnestedflatbuffer
)
{
int
o
=
__offset
(
30
);
if
(
o
!=
0
)
{
bb
.
Put
(
__vector
(
o
)
+
j
*
1
,
testnestedflatbuffer
);
return
true
;
}
else
{
return
false
;
}
}
public
bool
MutateTestnestedflatbuffer
(
int
j
,
byte
testnestedflatbuffer
)
{
int
o
=
__offset
(
30
);
if
(
o
!=
0
)
{
bb
.
Put
(
__vector
(
o
)
+
j
*
1
,
testnestedflatbuffer
);
return
true
;
}
else
{
return
false
;
}
}
public
Stat
Testempty
{
get
{
return
GetTestempty
(
new
Stat
());
}
}
public
Stat
Testempty
{
get
{
return
GetTestempty
(
new
Stat
());
}
}
public
Stat
GetTestempty
(
Stat
obj
)
{
int
o
=
__offset
(
32
);
return
o
!=
0
?
obj
.
__init
(
__indirect
(
o
+
bb_pos
),
bb
)
:
null
;
}
public
Stat
GetTestempty
(
Stat
obj
)
{
int
o
=
__offset
(
32
);
return
o
!=
0
?
obj
.
__init
(
__indirect
(
o
+
bb_pos
),
bb
)
:
null
;
}
...
@@ -64,6 +68,7 @@ public sealed class Monster : Table {
...
@@ -64,6 +68,7 @@ public sealed class Monster : Table {
public
bool
MutateTesthashu64Fnv1a
(
ulong
testhashu64_fnv1a
)
{
int
o
=
__offset
(
50
);
if
(
o
!=
0
)
{
bb
.
PutUlong
(
o
+
bb_pos
,
testhashu64_fnv1a
);
return
true
;
}
else
{
return
false
;
}
}
public
bool
MutateTesthashu64Fnv1a
(
ulong
testhashu64_fnv1a
)
{
int
o
=
__offset
(
50
);
if
(
o
!=
0
)
{
bb
.
PutUlong
(
o
+
bb_pos
,
testhashu64_fnv1a
);
return
true
;
}
else
{
return
false
;
}
}
public
bool
GetTestarrayofbools
(
int
j
)
{
int
o
=
__offset
(
52
);
return
o
!=
0
?
0
!=
bb
.
Get
(
__vector
(
o
)
+
j
*
1
)
:
false
;
}
public
bool
GetTestarrayofbools
(
int
j
)
{
int
o
=
__offset
(
52
);
return
o
!=
0
?
0
!=
bb
.
Get
(
__vector
(
o
)
+
j
*
1
)
:
false
;
}
public
int
TestarrayofboolsLength
{
get
{
int
o
=
__offset
(
52
);
return
o
!=
0
?
__vector_len
(
o
)
:
0
;
}
}
public
int
TestarrayofboolsLength
{
get
{
int
o
=
__offset
(
52
);
return
o
!=
0
?
__vector_len
(
o
)
:
0
;
}
}
public
ArraySegment
<
byte
>?
GetTestarrayofboolsBytes
()
{
return
__vector_as_arraysegment
(
52
);
}
public
bool
MutateTestarrayofbools
(
int
j
,
bool
testarrayofbools
)
{
int
o
=
__offset
(
52
);
if
(
o
!=
0
)
{
bb
.
Put
(
__vector
(
o
)
+
j
*
1
,
(
byte
)(
testarrayofbools
?
1
:
0
));
return
true
;
}
else
{
return
false
;
}
}
public
bool
MutateTestarrayofbools
(
int
j
,
bool
testarrayofbools
)
{
int
o
=
__offset
(
52
);
if
(
o
!=
0
)
{
bb
.
Put
(
__vector
(
o
)
+
j
*
1
,
(
byte
)(
testarrayofbools
?
1
:
0
));
return
true
;
}
else
{
return
false
;
}
}
public
static
void
StartMonster
(
FlatBufferBuilder
builder
)
{
builder
.
StartObject
(
25
);
}
public
static
void
StartMonster
(
FlatBufferBuilder
builder
)
{
builder
.
StartObject
(
25
);
}
...
...
tests/MyGame/Example/Stat.cs
View file @
c44bc6a7
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
MyGame.Example
namespace
MyGame.Example
{
{
using
System
;
using
FlatBuffers
;
using
FlatBuffers
;
public
sealed
class
Stat
:
Table
{
public
sealed
class
Stat
:
Table
{
...
@@ -11,6 +12,7 @@ public sealed class Stat : Table {
...
@@ -11,6 +12,7 @@ public sealed class Stat : Table {
public
Stat
__init
(
int
_i
,
ByteBuffer
_bb
)
{
bb_pos
=
_i
;
bb
=
_bb
;
return
this
;
}
public
Stat
__init
(
int
_i
,
ByteBuffer
_bb
)
{
bb_pos
=
_i
;
bb
=
_bb
;
return
this
;
}
public
string
Id
{
get
{
int
o
=
__offset
(
4
);
return
o
!=
0
?
__string
(
o
+
bb_pos
)
:
null
;
}
}
public
string
Id
{
get
{
int
o
=
__offset
(
4
);
return
o
!=
0
?
__string
(
o
+
bb_pos
)
:
null
;
}
}
public
ArraySegment
<
byte
>?
GetIdBytes
()
{
return
__vector_as_arraysegment
(
4
);
}
public
long
Val
{
get
{
int
o
=
__offset
(
6
);
return
o
!=
0
?
bb
.
GetLong
(
o
+
bb_pos
)
:
(
long
)
0
;
}
}
public
long
Val
{
get
{
int
o
=
__offset
(
6
);
return
o
!=
0
?
bb
.
GetLong
(
o
+
bb_pos
)
:
(
long
)
0
;
}
}
public
bool
MutateVal
(
long
val
)
{
int
o
=
__offset
(
6
);
if
(
o
!=
0
)
{
bb
.
PutLong
(
o
+
bb_pos
,
val
);
return
true
;
}
else
{
return
false
;
}
}
public
bool
MutateVal
(
long
val
)
{
int
o
=
__offset
(
6
);
if
(
o
!=
0
)
{
bb
.
PutLong
(
o
+
bb_pos
,
val
);
return
true
;
}
else
{
return
false
;
}
}
public
ushort
Count
{
get
{
int
o
=
__offset
(
8
);
return
o
!=
0
?
bb
.
GetUshort
(
o
+
bb_pos
)
:
(
ushort
)
0
;
}
}
public
ushort
Count
{
get
{
int
o
=
__offset
(
8
);
return
o
!=
0
?
bb
.
GetUshort
(
o
+
bb_pos
)
:
(
ushort
)
0
;
}
}
...
...
tests/MyGame/Example/Test.cs
View file @
c44bc6a7
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
MyGame.Example
namespace
MyGame.Example
{
{
using
System
;
using
FlatBuffers
;
using
FlatBuffers
;
public
sealed
class
Test
:
Struct
{
public
sealed
class
Test
:
Struct
{
...
...
tests/MyGame/Example/TestSimpleTableWithEnum.cs
View file @
c44bc6a7
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
MyGame.Example
namespace
MyGame.Example
{
{
using
System
;
using
FlatBuffers
;
using
FlatBuffers
;
public
sealed
class
TestSimpleTableWithEnum
:
Table
{
public
sealed
class
TestSimpleTableWithEnum
:
Table
{
...
...
tests/MyGame/Example/Vec3.cs
View file @
c44bc6a7
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
MyGame.Example
namespace
MyGame.Example
{
{
using
System
;
using
FlatBuffers
;
using
FlatBuffers
;
public
sealed
class
Vec3
:
Struct
{
public
sealed
class
Vec3
:
Struct
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment