Discussion:
[leveldb] Binvalues
Bela Berde
2016-06-10 10:10:19 UTC
Permalink
Hi,
struct BinValues
{
int intVal;
double doubleVal;
}
is Ok, but
struct TripleValues
{
std::string strVal;
int intVal;
double doubleVal;
}
is not Ok; Why?
Thanks
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Robert Escriva
2016-06-10 16:44:31 UTC
Permalink
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
Post by Bela Berde
Hi,
struct BinValues
{
int intVal;
double doubleVal;
}
is Ok, but
struct TripleValues
{
std::string strVal;
int intVal;
double doubleVal;
}
is not Ok; Why?
Thanks
--
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
For more options, visit https://groups.google.com/d/optout.
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Florian Weimer
2016-06-18 20:37:29 UTC
Permalink
Post by Robert Escriva
This isn't part of the LevelDB API, which deals in slices.
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.
--
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+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...