6

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.

user3130782
  • 841
  • 1
  • 6
  • 15

2 Answers2

6

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).

Aardappel
  • 5,559
  • 1
  • 19
  • 22
4

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; 
}