spacetime start

This commit is contained in:
james 2025-10-21 17:55:39 +10:30
commit 6c5900e79a
No known key found for this signature in database
GPG Key ID: E1FFBA228F4CAD87
3 changed files with 119 additions and 0 deletions

23
.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
/target
### Rust template
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

12
Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "jvm-rs"
version = "0.1.0"
edition = "2024"
[dependencies]
spacetimedb-sdk = { git = "https://github.com/infernap12/SpacetimeDB", branch = "class_de" }
#spacetimedb-core = { git = "https://github.com/infernap12/SpacetimeDB", branch = "class_de" }
#spacetimedb-lib = { git = "https://github.com/infernap12/SpacetimeDB", branch = "class_de" }
#spacetimedb-sats = { git = "https://github.com/infernap12/SpacetimeDB", branch = "class_de" }
#spacetimedb-client-api-messages = { git = "https://github.com/infernap12/SpacetimeDB", branch = "class_de" }
#bindings = { git = "https://github.com/infernap12/bitcraft-bindings", branch = "class_de" }

84
src/main.rs Normal file
View File

@ -0,0 +1,84 @@
mod primatives;
use std::fs;
use std::fs::File;
use std::io::Read;
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
use spacetimedb_sdk::__codegen::__lib::SpacetimeType;
use spacetimedb_sdk::__codegen::__sats::bsatn;
use deku_derive
fn main() {
let mut class_file = File::open("./data/main.class").unwrap();
let mut bytes = Vec::new();
class_file.read_to_end(&mut bytes).unwrap();
let cf = bsatn::from_slice::<ClassFile>(&*bytes).unwrap();
println!("{:?}", cf);
}
#[deku(magic="")]
pub struct ClassFile {
pub magic: u32,
pub minor_version: u16,
pub major_version: u16,
pub constant_pool: Vec<CpInfo>, // Note: count is pool.len() + 1
pub access_flags: u16,
pub this_class: u16,
pub super_class: u16,
pub interfaces: Vec<u16>,
pub fields: Vec<FieldInfo>,
pub methods: Vec<MethodInfo>,
pub attributes: Vec<AttributeInfo>,
}
// Placeholder types - you'd need to define these based on the JVM spec
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub enum CpInfo {
NULL, // i think this is needed?
Utf8(&'static str),
NULLTWO, // needed again i think?
Integer(i32),
Float(f32),
Long(i64),
Double(f64),
Class(u16),
String(u16),
FieldRef,
MethodRef(u16, u16),
InterfaceMethodRef,
NameAndType,
NULLTHIRTEEN,
NULLFOURTEEN,
MethodHandle,
MethodType,
NULLSEVENTEEN,
InvokeDynamic,
Module,
Package
}
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub struct FieldInfo {
// Field structure
}
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub struct MethodInfo {
// Method structure
}
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
pub struct AttributeInfo {
// Attribute structure
}
pub struct ConstantUtf8Info {
length: u16,
bytes: [u8],
vec: Vec<str>
}