Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This will:
4. Generate C# bindings (`generated/cs_lcm_msgs/`)
5. Generate Java bindings (`generated/java_lcm_msgs/`)
6. Generate Typescript bindings (`generated/ts_lcm_msgs/`)
7. Generate Rust bindings (`generated/rust_lcm_msgs/`)

## Directory Structure

Expand Down
6 changes: 6 additions & 0 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ deno run --allow-read --allow-write "$SCRIPT_DIR/tools/ts/gen/mod.ts" -q -o "$SC
rm -rf "$SCRIPT_DIR/tools/ts/msgs/generated"
cp -r "$SCRIPT_DIR/generated/ts_lcm_msgs" "$SCRIPT_DIR/tools/ts/msgs/generated"
echo -e "\033[32mLCM -> TypeScript done\033[0m"

# Generate Rust bindings
rm -rf "$SCRIPT_DIR/generated/rust_lcm_msgs"
python3 "$SCRIPT_DIR/tools/rust/lcm_rust_gen.py" "$SCRIPT_DIR/lcm_types" -o "$SCRIPT_DIR/generated/rust_lcm_msgs"
(cd "$SCRIPT_DIR/generated/rust_lcm_msgs" && cargo check --quiet)
echo -e "\033[32mLCM -> Rust done\033[0m"
1 change: 1 addition & 0 deletions generated/rust_lcm_msgs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
16 changes: 16 additions & 0 deletions generated/rust_lcm_msgs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions generated/rust_lcm_msgs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "lcm-msgs"
version = "0.1.0"
edition = "2021"
description = "Auto-generated LCM message types for Rust"

[dependencies]
byteorder = "1"
86 changes: 86 additions & 0 deletions generated/rust_lcm_msgs/src/actionlib_msgs/goal_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Auto-generated by lcm-rust-gen. DO NOT EDIT.

use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{self, Read, Write, Cursor};
use std::sync::OnceLock;

#[derive(Debug, Clone, Default, PartialEq)]
pub struct GoalID {
pub stamp: crate::std_msgs::Time,
pub id: std::string::String,
}

impl GoalID {
pub const HASH: i64 = 0xEF36683EF0767E95u64 as i64;
pub const NAME: &str = "actionlib_msgs.GoalID";

fn packed_fingerprint() -> u64 {
static CACHE: OnceLock<u64> = OnceLock::new();
*CACHE.get_or_init(|| Self::hash_recursive(&mut Vec::new()))
}

pub(crate) fn hash_recursive(parents: &mut Vec<u64>) -> u64 {
let self_hash = Self::HASH as u64;
if parents.contains(&self_hash) {
return 0;
}
parents.push(self_hash);
let mut tmphash = self_hash as u64;
tmphash = tmphash.wrapping_add(crate::std_msgs::Time::hash_recursive(parents));
parents.pop();
// rotate left by 1
tmphash << 1 | tmphash >> 63
}

pub fn encode(&self) -> Vec<u8> {
let mut buf = Vec::with_capacity(8 + self.encoded_size());
buf.write_u64::<BigEndian>(Self::packed_fingerprint()).unwrap();
self.encode_one(&mut buf).unwrap();
buf
}

pub fn decode(data: &[u8]) -> io::Result<Self> {
let mut cursor = Cursor::new(data);
let hash = cursor.read_u64::<BigEndian>()?;
let expected = Self::packed_fingerprint();
if hash != expected {
return Err(io::Error::new(io::ErrorKind::InvalidData,
format!("Hash mismatch: expected {:016x}, got {:016x}", expected, hash)));
}
Self::decode_one(&mut cursor)
}

pub fn encode_one<W: Write>(&self, buf: &mut W) -> io::Result<()> {
self.stamp.encode_one(buf)?;
{
let bytes = self.id.as_bytes();
buf.write_u32::<BigEndian>((bytes.len() + 1) as u32)?;
buf.write_all(bytes)?;
buf.write_u8(0)?;
}
Ok(())
}

pub fn decode_one<R: Read>(buf: &mut R) -> io::Result<Self> {
let stamp = crate::std_msgs::Time::decode_one(buf)?;
let id = {
let len = buf.read_u32::<BigEndian>()? as usize;
let mut bytes = vec![0u8; len];
buf.read_exact(&mut bytes)?;
std::string::String::from_utf8(bytes[..len - 1].to_vec())
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?
};
Ok(Self {
stamp,
id,
})
}

pub fn encoded_size(&self) -> usize {
let mut size = 0usize;
size += self.stamp.encoded_size();
size += 4 + self.id.len() + 1;
size
}

}
102 changes: 102 additions & 0 deletions generated/rust_lcm_msgs/src/actionlib_msgs/goal_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Auto-generated by lcm-rust-gen. DO NOT EDIT.

use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{self, Read, Write, Cursor};
use std::sync::OnceLock;

#[derive(Debug, Clone, Default, PartialEq)]
pub struct GoalStatus {
pub goal_id: crate::actionlib_msgs::GoalID,
pub status: u8,
pub text: std::string::String,
}

impl GoalStatus {
pub const HASH: i64 = 0xC0B4E95FEBDCD994u64 as i64;
pub const NAME: &str = "actionlib_msgs.GoalStatus";

pub const PENDING: i8 = 0;
pub const ACTIVE: i8 = 1;
pub const PREEMPTED: i8 = 2;
pub const SUCCEEDED: i8 = 3;
pub const ABORTED: i8 = 4;
pub const REJECTED: i8 = 5;
pub const PREEMPTING: i8 = 6;
pub const RECALLING: i8 = 7;
pub const RECALLED: i8 = 8;
pub const LOST: i8 = 9;

fn packed_fingerprint() -> u64 {
static CACHE: OnceLock<u64> = OnceLock::new();
*CACHE.get_or_init(|| Self::hash_recursive(&mut Vec::new()))
}

pub(crate) fn hash_recursive(parents: &mut Vec<u64>) -> u64 {
let self_hash = Self::HASH as u64;
if parents.contains(&self_hash) {
return 0;
}
parents.push(self_hash);
let mut tmphash = self_hash as u64;
tmphash = tmphash.wrapping_add(crate::actionlib_msgs::GoalID::hash_recursive(parents));
parents.pop();
// rotate left by 1
tmphash << 1 | tmphash >> 63
}

pub fn encode(&self) -> Vec<u8> {
let mut buf = Vec::with_capacity(8 + self.encoded_size());
buf.write_u64::<BigEndian>(Self::packed_fingerprint()).unwrap();
self.encode_one(&mut buf).unwrap();
buf
}

pub fn decode(data: &[u8]) -> io::Result<Self> {
let mut cursor = Cursor::new(data);
let hash = cursor.read_u64::<BigEndian>()?;
let expected = Self::packed_fingerprint();
if hash != expected {
return Err(io::Error::new(io::ErrorKind::InvalidData,
format!("Hash mismatch: expected {:016x}, got {:016x}", expected, hash)));
}
Self::decode_one(&mut cursor)
}

pub fn encode_one<W: Write>(&self, buf: &mut W) -> io::Result<()> {
self.goal_id.encode_one(buf)?;
buf.write_u8(self.status)?;
{
let bytes = self.text.as_bytes();
buf.write_u32::<BigEndian>((bytes.len() + 1) as u32)?;
buf.write_all(bytes)?;
buf.write_u8(0)?;
}
Ok(())
}

pub fn decode_one<R: Read>(buf: &mut R) -> io::Result<Self> {
let goal_id = crate::actionlib_msgs::GoalID::decode_one(buf)?;
let status = buf.read_u8()?;
let text = {
let len = buf.read_u32::<BigEndian>()? as usize;
let mut bytes = vec![0u8; len];
buf.read_exact(&mut bytes)?;
std::string::String::from_utf8(bytes[..len - 1].to_vec())
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?
};
Ok(Self {
goal_id,
status,
text,
})
}

pub fn encoded_size(&self) -> usize {
let mut size = 0usize;
size += self.goal_id.encoded_size();
size += 1;
size += 4 + self.text.len() + 1;
size
}

}
90 changes: 90 additions & 0 deletions generated/rust_lcm_msgs/src/actionlib_msgs/goal_status_array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Auto-generated by lcm-rust-gen. DO NOT EDIT.

use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use std::io::{self, Read, Write, Cursor};
use std::sync::OnceLock;

#[derive(Debug, Clone, Default, PartialEq)]
pub struct GoalStatusArray {
pub header: crate::std_msgs::Header,
pub status_list: Vec<crate::actionlib_msgs::GoalStatus>,
}

impl GoalStatusArray {
pub const HASH: i64 = 0x0F5C35B2E7EED0FAu64 as i64;
pub const NAME: &str = "actionlib_msgs.GoalStatusArray";

fn packed_fingerprint() -> u64 {
static CACHE: OnceLock<u64> = OnceLock::new();
*CACHE.get_or_init(|| Self::hash_recursive(&mut Vec::new()))
}

pub(crate) fn hash_recursive(parents: &mut Vec<u64>) -> u64 {
let self_hash = Self::HASH as u64;
if parents.contains(&self_hash) {
return 0;
}
parents.push(self_hash);
let mut tmphash = self_hash as u64;
tmphash = tmphash.wrapping_add(crate::std_msgs::Header::hash_recursive(parents));
tmphash = tmphash.wrapping_add(crate::actionlib_msgs::GoalStatus::hash_recursive(parents));
parents.pop();
// rotate left by 1
tmphash << 1 | tmphash >> 63
}

pub fn encode(&self) -> Vec<u8> {
let mut buf = Vec::with_capacity(8 + self.encoded_size());
buf.write_u64::<BigEndian>(Self::packed_fingerprint()).unwrap();
self.encode_one(&mut buf).unwrap();
buf
}

pub fn decode(data: &[u8]) -> io::Result<Self> {
let mut cursor = Cursor::new(data);
let hash = cursor.read_u64::<BigEndian>()?;
let expected = Self::packed_fingerprint();
if hash != expected {
return Err(io::Error::new(io::ErrorKind::InvalidData,
format!("Hash mismatch: expected {:016x}, got {:016x}", expected, hash)));
}
Self::decode_one(&mut cursor)
}

pub fn encode_one<W: Write>(&self, buf: &mut W) -> io::Result<()> {
buf.write_i32::<BigEndian>(self.status_list.len() as i32)?;
self.header.encode_one(buf)?;
for v0 in self.status_list.iter() {
v0.encode_one(buf)?;
}
Ok(())
}

pub fn decode_one<R: Read>(buf: &mut R) -> io::Result<Self> {
let status_list_length = buf.read_i32::<BigEndian>()? as usize;
let header = crate::std_msgs::Header::decode_one(buf)?;
let status_list = {
let mut v = Vec::with_capacity(status_list_length);
for _ in 0..status_list_length {
let _elem_0 = crate::actionlib_msgs::GoalStatus::decode_one(buf)?;
v.push(_elem_0);
}
v
};
Ok(Self {
header,
status_list,
})
}

pub fn encoded_size(&self) -> usize {
let mut size = 0usize;
size += 4;
size += self.header.encoded_size();
for v0 in self.status_list.iter() {
size += v0.encoded_size();
}
size
}

}
10 changes: 10 additions & 0 deletions generated/rust_lcm_msgs/src/actionlib_msgs/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Auto-generated by lcm-rust-gen. DO NOT EDIT.

mod goal_id;
pub use goal_id::GoalID;

mod goal_status;
pub use goal_status::GoalStatus;

mod goal_status_array;
pub use goal_status_array::GoalStatusArray;
Loading
Loading