O'Reilly logo

Getting Started with LevelDB by Andy Dent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Dealing with integer key endianness

LevelDB doesn't actually care if you store string values or arbitrary binary bytes—we've already seen how you can just push the structure into a record and that the Slice structure works with binary for keys and values. If you want an efficient, unique, compact key, storing a binary integer is an obvious choice for all or part of a key, such as our nameId.

However, the BytewiseComparator, used by default, will cause problems if you try making keys using integers straight from memory. Both Intel and ARM chips (Mac and iPhone) store integers in Little Endian order which means the least-significant byte is to the left and sorting of an integer key by bytes won't work. This is only a problem if you want the keys ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required