I store a column value in DB either as:
- an empty byte array
new byte[0] - an int value
- a non-empty
byte[]
On retrieval of the column value I retrieve it as a Bytebuffer & I need to detect whether it stored an integer, empty byte[], or non-empty byte[].
How do I detect looking at read Bytebuffer, what was stored in it among the above 3 possible options ?
You can’t, after all they are just a pile of bits. You need an external indicator. It can be either a second column or the first bit(s) of input.
If you loaded an empty buffer, empty
byte[]was stored. If it’s not empty, check first bit (or byte for simplicity). Agree that some value indicates that the rest isbyte[]while other value indicates encodedint. Of course prior to that you must also store that indicator.