user3130782
user3130782

Reputation: 861

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.

Upvotes: 6

Views: 2969

Answers (2)

Aardappel
Aardappel

Reputation: 6074

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

Upvotes: 6

Shivendra Agarwal
Shivendra Agarwal

Reputation: 688

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

Upvotes: 4

Related Questions