-
Notifications
You must be signed in to change notification settings - Fork 5
Reader and Writer
This two classes are helper classes, meaning that they were created to be used internally. Does that mean that you can't use them in your program? No, of course you can! Just keep in mind that both classes are considered deprecated, so they might be removed in the near future.
The Reader class allows you to deserialize C++ data types, so if you want to deserialize an int
from a pointer, you can just do:
int result = Cereal::Reader::readBytes<int>(pointer, offset);
The Writer class allow you to serialize C++ data types, so if you want to write a float
to an address, you can call Cereal::Writer::writeBytes<dataType>(pointer, offset, data):
offset = Cereal::Writer::writeBytes<float>(pointer, offset, 7.2f);
As you can see, the writeBytes
function returns the new offset (in this case, 4 bytes ahead), so you can use that in a for or while loop to serialize a lot of data:
void writeData(void* mem, short* data, int count)
{
int pointer = 0;
for(int i = 0; i < count; i++)
{
pointer = Cereal::Writer::writeBytes<short>(mem, pointer, data[i]);
}
}
Home | About Cereal | Setup Guide | Technical Docs | API Reference | Copyright © 2016 - 2019 The Cereal Team