ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

@PeteBlackerThe3rd is 100% right, you should probably create your custom message as explained in the tutorials.

Nevertheless, just __for your information__, ROS use the Boost Serialization library. May be you want to learn how that work to do your own serializations...

If you are not worry about indianess (and usually you should), serializing a double is as easy as using __reinterpret_cast__

double val = 3.14; uint8_t buffer[sizeof(double)]; //serialize memcopy( buffer, reinterpret_cast<uint8_t*>(&val), sizeof(double) );

//deserialize double val2 = *( reinterpret_cast<double*>( buffer ));

@PeteBlackerThe3rd is 100% right, you should probably create your custom message as explained in the tutorials.

Nevertheless, just __for your information__, ROS use the Boost Serialization library. May be you want to learn how that work to do your own serializations...

If you are not worry about indianess (and usually you should), serializing a double is as easy as using __reinterpret_cast__

double val = 3.14; uint8_t buffer[sizeof(double)]; 3.14; uint8_t buffer[sizeof(double)]; //serialize memcopy( buffer, reinterpret_cast<uint8_t*>(&val), buffer, reinterpret_cast<uint8_t*>(&val), sizeof(double) );

//deserialize //deserialize double val2 = *( *( reinterpret_cast<double*>( buffer ));

@PeteBlackerThe3rd is 100% right, you should probably create your custom message as explained in the tutorials.

Nevertheless, just __for your information__, ROS use the Boost Serialization library. May be you want to learn how that work to do your own serializations...

If you are not worry about indianess (and usually you should), serializing a double is as easy as using __reinterpret_cast__

double val = 3.14; uint8_t
  
uint8_t buffer[sizeof(double)]; //serialize
  
//serialize 
memcopy( buffer,
  reinterpret_cast<uint8_t*>(&val),
  buffer, reinterpret_cast<uint8_t*>(&val), sizeof(double) );

); //deserialize

//deserialize double val2 = *( *( reinterpret_cast<double*>( buffer ));

));

@PeteBlackerThe3rd is 100% right, you should probably create your custom message as explained in the tutorials.

Nevertheless, just __for for your information__, information, ROS use the Boost Serialization library. May be you want to learn how that work to do your own serializations...

If you are not worry about indianess (and usually you should), serializing a double is as easy as using __reinterpret_cast__reinterpret_cast

double val = 3.14; 
uint8_t buffer[sizeof(double)]; 
//serialize 
memcopy( buffer, reinterpret_cast<uint8_t*>(&val), sizeof(double) );

//deserialize 
double val2 =  *( reinterpret_cast<double*>( buffer ));

@PeteBlackerThe3rd is 100% right, you should probably create your custom message as explained in the tutorials.

Nevertheless, just for your information, ROS use the Boost Serialization library. May be you want to learn how that work to do your own serializations...

If you are not worry about indianess endianess (and usually you should), serializing a double is as easy as using reinterpret_cast

double val = 3.14; 
uint8_t buffer[sizeof(double)]; 
//serialize 
memcopy( buffer, reinterpret_cast<uint8_t*>(&val), sizeof(double) );

//deserialize 
double val2 =  *( reinterpret_cast<double*>( buffer ));