rmw_ret_t
rmw_deserialize(
  const rmw_serialized_message_t * serialized_message,
  const rosidl_message_type_support_t * type_support,
  void * ros_message)
{
  const rosidl_message_type_support_t * ts = get_message_typesupport_handle(
    type_support, RMW_FASTRTPS_CPP_TYPESUPPORT_C);
  if (!ts) {
    ts = get_message_typesupport_handle(
      type_support, RMW_FASTRTPS_CPP_TYPESUPPORT_CPP);
    if (!ts) {
      RMW_SET_ERROR_MSG("type support not from this implementation");
      return RMW_RET_ERROR;
    }
  }

  auto callbacks = static_cast<const message_type_support_callbacks_t *>(ts->data);
  auto tss = new MessageTypeSupport_cpp(callbacks);
  eprosima::fastcdr::FastBuffer buffer(
    reinterpret_cast<char *>(serialized_message->buffer), serialized_message->buffer_length);
  eprosima::fastcdr::Cdr deser(buffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
    eprosima::fastcdr::Cdr::DDS_CDR);

  auto ret = tss->deserializeROSmessage(deser, ros_message);
  delete tss;
  return ret == true ? RMW_RET_OK : RMW_RET_ERROR;
}
示例#2
0
bool Data64kbType::deserialize(SerializedPayload_t* payload, void* data) {
	Data64kb* p_type = (Data64kb*) data; 	//Convert DATA to pointer of your type
	eprosima::fastcdr::FastBuffer fastbuffer((char*)payload->data, payload->length); 	// Object that manages the raw buffer.
	eprosima::fastcdr::Cdr deser(fastbuffer, payload->encapsulation == CDR_BE ? eprosima::fastcdr::Cdr::BIG_ENDIANNESS : eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS); 	// Object that deserializes the data.
	p_type->deserialize(deser);	//Deserialize the object:
	return true;
}
示例#3
0
bool HelloWorldType::deserialize(SerializedPayload_t* payload, void* data)
{
	HelloWorld* hw = (HelloWorld*) data;
	// Object that manages the raw buffer.
	eprosima::fastcdr::FastBuffer fastbuffer((char*)payload->data, payload->length);
	// Object that serializes the data.
	eprosima::fastcdr::Cdr deser(fastbuffer);
	//serialize the object:
	hw->deserialize(deser);
	return true;
}
/** Resets ALE (emulator and ROM settings) to the state described by
  * this object. */
void ALEState::load() {
  assert(serialized.length() > 0);
  assert(m_settings != NULL);
  Deserializer deser(serialized);
  
  m_osystem->console().system().loadState(s_cartridge_md5, deser);
  m_settings->loadState(deser);
  
  left_paddle_curr_x = deser.getInt();
  right_paddle_curr_x = deser.getInt();
  frame_number = deser.getInt();
}
示例#5
0
/** Restores ALE to the given previously saved state. */ 
void ALEState::load(OSystem* osystem, RomSettings* settings, std::string md5, const ALEState &rhs) {
  assert(rhs.m_serialized_state.length() > 0);
  
  // Deserialize the stored string into the emulator state
  Deserializer deser(rhs.m_serialized_state);
  
  osystem->console().system().loadState(md5, deser);
  settings->loadState(deser);
 
  // Copy over other member variables
  m_left_paddle = rhs.m_left_paddle; 
  m_right_paddle = rhs.m_right_paddle; 
  m_frame_number = rhs.m_frame_number; 
}
bool MetaTestTypesPubSubType::deserialize(SerializedPayload_t* payload, void* data)
{
    //CONVERT DATA to pointer of your type
    MetaTestType* p_type = (MetaTestType*) data;

    // Object that manages the raw buffer.
    eprosima::fastcdr::FastBuffer fastbuffer((char*)payload->data, payload->length);
    //select the correct endianess
    eprosima::fastcdr::Cdr::Endianness endian = payload->encapsulation == CDR_LE ? eprosima::fastcdr::Cdr::LITTLE_ENDIANNESS : eprosima::fastcdr::Cdr::BIG_ENDIANNESS;
    // Object that deserializes the data.
    eprosima::fastcdr::Cdr deser(fastbuffer,endian);
    //deserialize the object:
    p_type->deserialize(deser);
    return true;
}
示例#7
0
bool
Device::loadFromCache()
{
    std::string sDevicePath = getCachePath() + getConfigRom().getGuidString();

    char* configId;
    asprintf(&configId, "%016"PRIx64"", getConfigurationId() );
    if ( !configId ) {
        debugError( "could not create id string\n" );
        return false;
    }

    std::string sFileName = sDevicePath + "/" + configId + ".xml";
    free( configId );
    debugOutput( DEBUG_LEVEL_NORMAL, "filename %s\n", sFileName.c_str() );

    struct stat buf;
    if ( stat( sFileName.c_str(), &buf ) != 0 ) {
        debugOutput( DEBUG_LEVEL_NORMAL,  "\"%s\" does not exist\n",  sFileName.c_str() );
        return false;
    } else {
        if ( !S_ISREG( buf.st_mode ) ) {
            debugOutput( DEBUG_LEVEL_NORMAL,  "\"%s\" is not a regular file\n",  sFileName.c_str() );
            return false;
        }
    }

    Util::XMLDeserialize deser( sFileName, getDebugLevel() );

    if (!deser.isValid()) {
        debugOutput( DEBUG_LEVEL_NORMAL, "cache not valid: %s\n",
                     sFileName.c_str() );
        return false;
    }

    bool result = deserialize( "", deser );
    if ( result ) {
        debugOutput( DEBUG_LEVEL_NORMAL, "could create valid bebob driver from %s\n",
                     sFileName.c_str() );
    }

    if(result) {
        buildMixer();
    }

    return result;
}
示例#8
0
TEST(RequestSerializationTest, UrlTests) {
  {
    WdtUri uri("wdt://blah.com?k1=v1&k2=v2&k3=v3.1,v3.2");
    EXPECT_EQ(uri.getErrorCode(), OK);
    EXPECT_EQ(uri.getHostName(), "blah.com");
    EXPECT_EQ(uri.getQueryParam("k1"), "v1");
    EXPECT_EQ(uri.getQueryParam("k2"), "v2");
    EXPECT_EQ(uri.getQueryParam("k3"), "v3.1,v3.2");
    EXPECT_EQ(uri.getQueryParams().size(), 3);

    uri = "wdt://blah?name=first,second";
    EXPECT_EQ(uri.getErrorCode(), OK);
    EXPECT_EQ(uri.getQueryParam("name"), "first,second");
    uri = "http://blah.com?name=test";
    ASSERT_TRUE(uri.getHostName().empty());

    uri = "wdt://localhost";
    EXPECT_EQ(uri.getErrorCode(), OK);
    EXPECT_EQ(uri.getHostName(), "localhost");

    uri = "wdt://localhost.facebook.com?key=value1,value2";
    EXPECT_EQ(uri.getHostName(), "localhost.facebook.com");
    EXPECT_EQ(uri.getQueryParam("key"), "value1,value2");

    uri = "wdt://127.0.0.1?";
    EXPECT_EQ(uri.getHostName(), "127.0.0.1");
    EXPECT_EQ(uri.getQueryParams().size(), 0);

    uri = "wdt://127.0.0.1?a";
    EXPECT_EQ(uri.getHostName(), "127.0.0.1");
    EXPECT_EQ(uri.getQueryParams().size(), 1);

    EXPECT_EQ(uri.generateUrl(), "wdt://127.0.0.1?a=");

    uri = "wdt://?a=10";
    EXPECT_NE(uri.getErrorCode(), OK);

    vector<string> keys;
    vector<string> values;
    WdtUri wdtUri;
    for (int i = 0; i < 100; i++) {
      keys.push_back(to_string(rand32()));
      values.push_back(to_string(rand32()));
    }
    for (size_t i = 0; i < keys.size(); i++) {
      wdtUri.setQueryParam(keys[i], values[i]);
    }
    uri = wdtUri.generateUrl();
    EXPECT_NE(uri.getErrorCode(), OK);
    ASSERT_TRUE(uri.getHostName().empty());
    for (size_t i = 0; i < keys.size(); i++) {
      EXPECT_EQ(uri.getQueryParam(keys[i]), values[i]);
    }
  }
  {
    // ipv6 uri test
    WdtUri uri("wdt://[::1]:22356?k1=v1");
    EXPECT_EQ(uri.getErrorCode(), OK);
    EXPECT_EQ(uri.getHostName(), "::1");
    EXPECT_EQ(uri.getPort(), 22356);

    uri = "wdt://[::1]:";
    EXPECT_EQ(uri.getErrorCode(), URI_PARSE_ERROR);
    EXPECT_EQ(uri.getHostName(), "::1");
    EXPECT_EQ(uri.getPort(), -1);

    uri = "wdt://[12::12:1]:1";
    EXPECT_EQ(uri.getErrorCode(), OK);
    EXPECT_EQ(uri.getHostName(), "12::12:1");
    EXPECT_EQ(uri.getPort(), 1);

    uri = "wdt://123.4.5.6:22356";
    EXPECT_EQ(uri.getErrorCode(), OK);
    EXPECT_EQ(uri.getHostName(), "123.4.5.6");
    EXPECT_EQ(uri.getPort(), 22356);

    uri = "wdt://[";
    EXPECT_EQ(uri.getErrorCode(), URI_PARSE_ERROR);
    EXPECT_EQ(uri.getHostName(), "");

    uri = "wdt://[121";
    EXPECT_EQ(uri.getErrorCode(), URI_PARSE_ERROR);
    EXPECT_EQ(uri.getHostName(), "");

    uri = "wdt://[]";
    EXPECT_EQ(uri.getErrorCode(), URI_PARSE_ERROR);
    EXPECT_EQ(uri.getHostName(), "");

    uri = "wdt://[]:22356";
    EXPECT_EQ(uri.getErrorCode(), URI_PARSE_ERROR);
    EXPECT_EQ(uri.getHostName(), "");
    EXPECT_EQ(uri.getPort(), 22356);

    uri = "wdt://[::1]:*";
    EXPECT_EQ(uri.getErrorCode(), URI_PARSE_ERROR);
    EXPECT_EQ(uri.getHostName(), "::1");
    EXPECT_EQ(uri.getPort(), -1);

    uri = "wdt://]:22356";
    EXPECT_EQ(uri.getErrorCode(), OK);
    EXPECT_EQ(uri.getHostName(), "]");
    EXPECT_EQ(uri.getPort(), 22356);

    {
      uri = "wdt://[::1]:24689?num_ports=3";
      EXPECT_EQ(uri.getPort(), 24689);
      WdtTransferRequest transferRequest(uri.generateUrl());
      EXPECT_EQ(uri.getErrorCode(), OK);
      EXPECT_EQ(transferRequest.hostName, "::1");
      EXPECT_EQ(transferRequest.ports,
                WdtTransferRequest::genPortsVector(24689, 3));
    }
    {
      uri = "wdt://[::1]?num_ports=10";  // missing port
      WdtTransferRequest transferRequest(uri.generateUrl());
      EXPECT_EQ(uri.getErrorCode(), OK);
      EXPECT_EQ(transferRequest.errorCode, INVALID_REQUEST);
      EXPECT_EQ(transferRequest.hostName, "::1");
    }
    {
      uri = "wdt://[::1]:12345?num_ports=abc";  // bad num ports
      WdtTransferRequest transferRequest(uri.generateUrl());
      EXPECT_EQ(uri.getErrorCode(), OK);
      EXPECT_EQ(transferRequest.errorCode, URI_PARSE_ERROR);
      EXPECT_EQ(transferRequest.hostName, "::1");
    }
    {
      uri = "wdt://[::1]:24689?start_port=22356&ports=1,2,3,4";
      WdtTransferRequest transferRequest(uri.generateUrl());
      EXPECT_EQ(uri.getErrorCode(), OK);
      EXPECT_EQ(transferRequest.hostName, "::1");
      EXPECT_EQ(transferRequest.ports,
                WdtTransferRequest::genPortsVector(1, 4));
    }
  }
  {
    WdtTransferRequest request(123, 5, "");
    request.hostName = "host1";
    request.transferId = "tid1";
    request.protocolVersion = 753;
    string serialized = request.genWdtUrlWithSecret();
    LOG(INFO) << "Serialized " << serialized;
    WdtTransferRequest deser(serialized);
    EXPECT_EQ(deser.hostName, "host1");
    EXPECT_EQ(deser.transferId, "tid1");
    EXPECT_EQ(deser.protocolVersion, 753);
    EXPECT_EQ(deser.ports.size(), 5);
    for (int i = 0; i < 5; ++i) {
      EXPECT_EQ(deser.ports[i], 123 + i);
    }
    EXPECT_EQ(deser.errorCode, OK);
    EXPECT_EQ(deser.genWdtUrlWithSecret(), serialized);
    EXPECT_EQ(deser, request);
  }
  {
    WdtTransferRequest transferRequest(24689, 1, "");
    // Lets not populate anything else
    transferRequest.hostName = "localhost";
    string serializedString = transferRequest.genWdtUrlWithSecret();
    LOG(INFO) << serializedString;
    WdtTransferRequest dummy(serializedString);
    LOG(INFO) << dummy.getLogSafeString();
    EXPECT_EQ(transferRequest, dummy);
  }
  {
    string uri = "wdt://localhost?ports=1&recpv=10";
    WdtTransferRequest transferRequest(uri);
    EXPECT_EQ(transferRequest.errorCode, OK);
    ASSERT_EQ(transferRequest.ports.size(), 1);
    EXPECT_EQ(transferRequest.ports[0], 1);
  }
  {
    WdtTransferRequest transferRequest(0, 8, "/dir3/dir4");
    Receiver receiver(transferRequest);
    transferRequest = receiver.init();
    EXPECT_EQ(transferRequest.errorCode, OK);
    ASSERT_TRUE(transferRequest.ports.size() != 0);
    for (auto port : transferRequest.ports) {
      ASSERT_TRUE(port != 0);
    }
    LOG(INFO) << transferRequest.hostName;
    ASSERT_TRUE(!transferRequest.hostName.empty());
  }
  {
    string uri = "wdt://localhost?ports=1,2,3,10&dir=test&recpv=100&id=111";
    WdtTransferRequest transferRequest(uri);
    EXPECT_EQ(transferRequest.errorCode, OK);
    EXPECT_EQ(transferRequest.hostName, "localhost");
    EXPECT_EQ(transferRequest.directory, "test");
    EXPECT_EQ(transferRequest.protocolVersion, 100);
    EXPECT_EQ(transferRequest.transferId, "111");
    vector<int32_t> expectedPorts;
    for (int i = 0; i < 3; i++) {
      expectedPorts.push_back(i + 1);
    }
    expectedPorts.push_back(10);
    EXPECT_EQ(transferRequest.ports, expectedPorts);
  }
  {
    // missing numports/ports
    string uri = "wdt://localhost?dir=test&recpv=100&id=111";
    WdtTransferRequest transferRequest(uri);
    EXPECT_EQ(transferRequest.errorCode, INVALID_REQUEST);
    EXPECT_EQ(transferRequest.genWdtUrlWithSecret(), "INVALID_REQUEST");
  }
  {
    string url = "wdt://";
    WdtTransferRequest transferRequest(url);
    EXPECT_EQ(transferRequest.errorCode, INVALID_REQUEST);
    EXPECT_EQ(transferRequest.genWdtUrlWithSecret(), "INVALID_REQUEST");
  }
  {
    string url = "wdt://localhost:22355?num_ports=3";
    WdtTransferRequest transferRequest(url);
    Receiver receiver(transferRequest);
    auto retTransferRequest = receiver.init();
    EXPECT_EQ(retTransferRequest.errorCode, INVALID_REQUEST);
  }
  {
    string url = "wdt://localhost:22355";
    WdtTransferRequest transferRequest(url);
    Sender sender(transferRequest);
    auto retTransferRequest = sender.init();
    EXPECT_EQ(retTransferRequest.errorCode, INVALID_REQUEST);
  }
  {
    string url = "wdt://localhost:22355?num_ports=3";
    WdtTransferRequest transferRequest(url);
    EXPECT_EQ(transferRequest.errorCode, OK);
    transferRequest.directory = "blah";
    // Artificial error
    transferRequest.errorCode = ERROR;
    Receiver receiver(transferRequest);
    auto retTransferRequest = receiver.init();
    EXPECT_EQ(retTransferRequest.errorCode, ERROR);
  }
}
示例#9
0
文件: Unit.cpp 项目: vcmi/vcmi
void UnitInfo::load(uint32_t id_, const JsonNode & data)
{
	id = id_;
    JsonDeserializer deser(nullptr, data);
    deser.serializeStruct("newUnitInfo", *this);
}
示例#10
0
/* *********************************************************************
	Loads the OSystem/GameSettings states from a string
 ******************************************************************** */
void SearchAgent::load_state(const string state_str) {
	Deserializer deser(state_str);
	p_osystem->console().system().loadState(s_cartridge_md5, deser);
	p_game_settings->load_state(deser);
}