Created
March 28, 2022 19:42
-
-
Save juliarose/9e6d580de85e782c48d6974411998018 to your computer and use it in GitHub Desktop.
Rust macro generator for protobuf messages
This file contains hidden or 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
const fs = require('fs'); | |
const filepath = process.argv[2]; | |
const filename = filepath.match(/([a-z_0-9]+)\.rs$/)[1]; | |
const data = fs.readFileSync(filepath, 'utf8'); | |
const structs = data | |
.split('\n') | |
.filter(line => /^pub struct /.test(line)) | |
.map(line => line.replace(/(pub struct | \{)/g, '')); | |
const tab = ' '; | |
// console.log(`${filename}::{`); | |
// console.log(tab + structs.join(`,\n${tab}`)); | |
// console.log('}'); | |
structs.forEach(struct => console.log(`gc_msg!(${filename}::${struct});`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment