@foxglove/rosbag2
Version:
ROS 2 (Robot Operating System) bag reader and writer abstract implementation
96 lines • 3.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseQosProfiles = parseQosProfiles;
const rostime_1 = require("@foxglove/rostime");
const types_1 = require("./types");
const yaml_1 = require("./yaml");
const TIME_ZERO = { sec: 0, nsec: 0 };
const DURATION_INFINITY = { sec: 2147483647, nsec: 4294967295 };
/**
* Parses a YAML string into a list of ROS2 QoS profiles. Missing values will be filled in with
* rosbag2 QoS defaults.
*
* These are the default values for QoS profile fields, according to
* <https://github.com/ros2/rosbag2/blob/master/README.md#overriding-qos-profiles>
*
* history: keep_last
* depth: 10
* reliability: reliable
* durability: volatile
* deadline:
* # unspecified/infinity
* sec: 0
* nsec: 0
* lifespan:
* # unspecified/infinity
* sec: 0
* nsec: 0
* liveliness: system_default
* liveliness_lease_duration:
* # unspecified/infinity
* sec: 0
* nsec: 0
* avoid_ros_namespace_conventions: false
* @param data A string in YAML format
* @returns A list of parsed QoS profiles
*/
function parseQosProfiles(data) {
const parsed = (0, yaml_1.parseYaml)(data);
return Array.isArray(parsed) ? getQosProfiles(parsed) : [];
}
function getQosProfiles(array) {
const profiles = [];
for (const entryMaybe of array) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (entryMaybe == undefined) {
continue;
}
profiles.push(getQosProfile(entryMaybe));
}
return profiles;
}
function getQosProfile(obj) {
const history = getNumber(obj, "history") ?? -1;
const reliability = getNumber(obj, "reliability") ?? -1;
const durability = getNumber(obj, "durability") ?? -1;
const liveliness = getNumber(obj, "liveliness") ?? -1;
return {
history: history in types_1.QosPolicyHistory ? history : types_1.QosPolicyHistory.KeepLast,
depth: getNumber(obj, "depth") ?? 10,
reliability: reliability in types_1.QosPolicyReliability ? reliability : types_1.QosPolicyReliability.Reliable,
durability: durability in types_1.QosPolicyDurability ? durability : types_1.QosPolicyDurability.Volatile,
deadline: getDuration(obj, "deadline"),
lifespan: getDuration(obj, "lifespan"),
liveliness: liveliness in types_1.QosPolicyLiveliness ? liveliness : types_1.QosPolicyLiveliness.SystemDefault,
livelinessLeaseDuration: getDuration(obj, "liveliness_lease_duration"),
avoidRosNamespaceConventions: getBoolean(obj, "avoid_ros_namespace_conventions") ?? false,
};
}
function getNumber(obj, field) {
const value = obj[field];
return typeof value === "bigint" ? Number(value) : typeof value === "number" ? value : undefined;
}
function getBoolean(obj, field) {
const value = obj[field];
return typeof value === "boolean"
? value
: typeof value === "bigint" || typeof value === "number"
? Boolean(value)
: undefined;
}
function getDuration(obj, field) {
const value = obj[field];
if (value == undefined) {
return undefined;
}
// This handles both bigint and number types
const duration = { sec: Number(value["sec"]), nsec: Number(value["nsec"]) };
if (isNaN(duration.sec) ||
isNaN(duration.nsec) ||
(0, rostime_1.areEqual)(duration, TIME_ZERO) ||
(0, rostime_1.areEqual)(duration, DURATION_INFINITY)) {
return undefined;
}
return duration;
}
//# sourceMappingURL=metadata.js.map