UNPKG

@foxglove/ulog

Version:
56 lines 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseMessageDefinition = parseMessageDefinition; exports.parseFieldDefinition = parseFieldDefinition; const BUILTIN_TYPES = new Set([ "int8_t", "uint8_t", "int16_t", "uint16_t", "int32_t", "uint32_t", "int64_t", "uint64_t", "float", "double", "bool", "char", ]); function parseMessageDefinition(format) { const [name, fieldStrings] = format.split(":"); if (!name || !fieldStrings) { return undefined; } const fields = []; for (const fieldString of fieldStrings.split(";")) { const trimmed = fieldString.trim(); if (!trimmed) { continue; } const definition = parseFieldDefinition(trimmed); if (!definition) { return undefined; } fields.push(definition); } return { name, fields, format }; } function parseFieldDefinition(fieldString) { const [typeAndArray, name] = fieldString.split(" "); if (!typeAndArray || !name) { return undefined; } // Handle fixed length arrays as part of the type, e.g. "float[8]" const arrayMatch = /([^[]+)\[(\d+)\]/.exec(typeAndArray); if (arrayMatch) { const type = arrayMatch[1]; const arrayLength = parseInt(arrayMatch[2]); if (isNaN(arrayLength) || arrayLength <= 0) { return undefined; } return { type, name, arrayLength, isComplex: !BUILTIN_TYPES.has(type) }; } const type = typeAndArray; return { type, name, isComplex: !BUILTIN_TYPES.has(type) }; } //# sourceMappingURL=definition.js.map