Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "buffer.h"
- int main()
- {
- Buffer buffer(1000);
- //Source - notice that only the sign (which is the first bit) is different
- float f1 = 1.987654321;
- float f2 = -1.987654321;
- double d1 = 1.987654321;
- double d2 = -1.987654321;
- //Destination
- float _f1;
- float _f2;
- double _d1;
- double _d2;
- //Serialize
- buffer.tryWriteFloat(f1); // 4 bytes
- buffer.tryWriteFloat(f2); // 4 bytes
- buffer.tryWriteDouble(d1); // 8 bytes
- buffer.tryWriteDouble(d2); // 8 bytes
- //Deserialize
- buffer.tryReadFloat(_f1); // 4 bytes
- buffer.tryReadFloat(_f2); // 4 bytes
- buffer.tryReadDouble(_d1); // 8 bytes
- buffer.tryReadDouble(_d2); // 8 bytes
- //Display buffer contents
- printf("\nBuffer contents:\n\n");
- for(long long i = 0; i < buffer.Written(); ++i)
- {
- if(i != 0 && i % 8 == 0 ) printf(" "); // separate after 8 bytes
- printf("%02x", buffer.GetArray()[i]);
- }
- printf("\n\n");
- //Values of deserialized variables
- printf("\nValues:\n\n");
- printf("%f\n", _f1);
- printf("%f\n", _f2);
- printf("%lf\n", _d1);
- printf("%lf\n", _d2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment