This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds logic to detect IDL-defined message types and store the IDL. Signed-off-by: James Smith <james@foxglove.dev>
- Loading branch information
Showing
15 changed files
with
426 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
rosbag2_storage_mcap/include/rosbag2_storage_mcap/message_definition_cache.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2022, Foxglove Technologies. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef ROSBAG2_STORAGE_MCAP__MESSAGE_DEFINITION_CACHE_HPP_ | ||
#define ROSBAG2_STORAGE_MCAP__MESSAGE_DEFINITION_CACHE_HPP_ | ||
|
||
#include <set> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <unordered_set> | ||
#include <utility> | ||
|
||
namespace rosbag2_storage_mcap::internal { | ||
|
||
enum struct Format { | ||
IDL, | ||
MSG, | ||
}; | ||
|
||
struct MessageSpec { | ||
MessageSpec(Format format, std::string text, const std::string& package_context); | ||
const std::set<std::string> dependencies; | ||
const std::string text; | ||
Format format; | ||
}; | ||
|
||
struct DefinitionIdentifier { | ||
Format format; | ||
std::string package_resource_name; | ||
|
||
bool operator==(const DefinitionIdentifier& di) const { | ||
return (format == di.format) && (package_resource_name == di.package_resource_name); | ||
} | ||
}; | ||
|
||
class DefinitionNotFoundError : public std::exception { | ||
private: | ||
std::string name_; | ||
|
||
public: | ||
explicit DefinitionNotFoundError(const std::string& name) | ||
: name_(name) {} | ||
const char* what() const throw() { | ||
return name_.c_str(); | ||
} | ||
}; | ||
|
||
class MessageDefinitionCache final { | ||
public: | ||
/** | ||
* Concatenate the message definition with its dependencies into a self-contained schema. | ||
* The format is different for MSG and IDL definitions, and is described fully here: | ||
* [MSG](https://mcap.dev/specification/appendix.html#ros2msg-data-format) | ||
* [IDL](https://mcap.dev/specification/appendix.html#ros2idl-data-format) | ||
* Throws DefinitionNotFoundError if one or more definition files are missing for the given | ||
* package resource name. | ||
*/ | ||
std::pair<Format, std::string> get_full_text(const std::string& package_resource_name); | ||
|
||
private: | ||
struct DefinitionIdentifierHash { | ||
std::size_t operator()(const DefinitionIdentifier& di) const { | ||
std::size_t h1 = std::hash<Format>()(di.format); | ||
std::size_t h2 = std::hash<std::string>()(di.package_resource_name); | ||
return h1 ^ h2; | ||
} | ||
}; | ||
/** | ||
* Load and parse the message file referenced by the given datatype, or return it from | ||
* msg_specs_by_datatype | ||
*/ | ||
const MessageSpec& load_message_spec(const DefinitionIdentifier& definition_identifier); | ||
|
||
std::unordered_map<DefinitionIdentifier, MessageSpec, DefinitionIdentifierHash> | ||
msg_specs_by_definition_identifier_; | ||
}; | ||
|
||
std::set<std::string> parse_dependencies(Format format, const std::string& text, | ||
const std::string& package_context); | ||
|
||
} // namespace rosbag2_storage_mcap::internal | ||
|
||
#endif // ROSBAG2_STORAGE_MCAP__MESSAGE_DEFINITION_CACHE_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.