Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FlatBuffers and NULL value

What is canonical way to store NULL value in FlatBuffers ?

I have

ExpirationDate     *int64

I understand why FlatBuffers is not defining NULL. But I do not understand how to handle that properly. Should I have extra bool field or make value a array?

ExpirationDate     [int64]

vs

ExpirationDate     int64
ExpirationDateNull bool

For tables may be I can use also union.

like image 361
user3130782 Avatar asked Dec 16 '18 15:12

user3130782


2 Answers

A third option is struct NullableInt64 { i:int64 } and then in table have a field of type NullableInt64. When this field is not present, the accessor function will return NULL. And because it a struct, it will take the same space on the wire as a naked int64 (they're both 8 bytes and are stored inline in the parent).

like image 120
Aardappel Avatar answered Oct 02 '22 21:10

Aardappel


For storing values like int32 / int64 etc. You can directly keep the scalars in the table.

But in your case you have an indirection, which can be mimiced by an indirection created by non-scalars in flatbuffers.

Non-scalars are struct, array, and table.

So you may try :

Struct IntPtr 
{ 
val:int64
} 

Table Expiration 
{ 
ExpirationDate:IntPtr; 
}
like image 38
Shivendra Agarwal Avatar answered Oct 02 '22 19:10

Shivendra Agarwal