Binvalues

23 views
Skip to first unread message

Bela Berde

unread,
Jun 10, 2016, 6:10:19 AM6/10/16
to leveldb
Hi,
struct BinValues
{
int intVal;
double doubleVal;
}
is Ok, but
struct TripleValues
{
std::string strVal;
int intVal;
double doubleVal;
}
is not Ok; Why?
Thanks


Robert Escriva

unread,
Jun 14, 2016, 1:02:41 PM6/14/16
to lev...@googlegroups.com
This isn't part of the LevelDB API, which deals in slices.

I assume you are taking these structs and doing something like:

TripleValues t(...)
leveldb::Slice value(&t, sizeof(t));

This will work for BinValues because it's a struct of plain old data
(you'll see this called a POD struct). The TripleValues struct won't
work because strVal is a non-plain type, and what you'd be serializing
is the members of the struct. In this case, that would be pointers to
the actual string data that you want to store.

You'll need to transform TripleValues into a byte string that does what
you want.

-Robert
> --
> You received this message because you are subscribed to the Google Groups
> "leveldb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to leveldb+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Florian Weimer

unread,
Jun 18, 2016, 4:37:31 PM6/18/16
to Robert Escriva, lev...@googlegroups.com
* Robert Escriva:

> This isn't part of the LevelDB API, which deals in slices.
>
> I assume you are taking these structs and doing something like:
>
> TripleValues t(...)
> leveldb::Slice value(&t, sizeof(t));
>
> This will work for BinValues because it's a struct of plain old data
> (you'll see this called a POD struct).

The padding (a 4-byte hole between the int and double members) could
still break some things, I think.
Reply all
Reply to author
Forward
0 new messages