Skip to content

skyne98/binary-playground

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Binary Playground

A Rust workspace for experimenting with binary operations, bit manipulation, and low-level data representations.

Project Structure

This project is organized as a Rust workspace with the following structure:

binary-playground/
├── Cargo.toml          # Workspace configuration
├── cli/                # CLI application crate
│   ├── Cargo.toml
│   └── src/
│       └── main.rs
└── experiments/        # Library crate containing all experiments
    ├── Cargo.toml
    └── src/
        └── lib.rs

Quick Start

Build the project

cargo build

List all available experiments

cargo run --bin binary-playground list

Run a specific experiment

cargo run --bin binary-playground run <experiment-name> [args...]

Available Experiments

1. Bit Operations (bit-ops)

Experiments with bit manipulation operations like AND, OR, XOR, NOT, and bit shifting.

Examples:

# Show binary representation and bit statistics
cargo run --bin binary-playground run bit-ops 42

# Perform XOR operation
cargo run --bin binary-playground run bit-ops 42 xor 15

# Bit shifting
cargo run --bin binary-playground run bit-ops 8 shift-left 2

# Bitwise AND
cargo run --bin binary-playground run bit-ops 255 and 15

2. Binary Arithmetic (binary-math)

Experiments with binary arithmetic operations and number representations.

Examples:

# Show different representations of a number
cargo run --bin binary-playground run binary-math -42

# Perform arithmetic with overflow detection
cargo run --bin binary-playground run binary-math 255 add 1
cargo run --bin binary-playground run binary-math 100 mul 200

3. Byte Manipulation (bytes)

Experiments with byte arrays, endianness, and data serialization.

Examples:

# Convert number to little-endian bytes
cargo run --bin binary-playground run bytes 1234 le

# Convert number to big-endian bytes
cargo run --bin binary-playground run bytes 1234 be

# Interpret byte sequence as number
cargo run --bin binary-playground run bytes bytes 210,4,0,0

Adding New Experiments

To add a new experiment, follow these steps:

1. Create a new module in experiments/src/lib.rs

pub mod my_experiment {
    use super::*;
    
    pub struct MyExperiment;
    
    impl Experiment for MyExperiment {
        fn name(&self) -> &'static str {
            "my-experiment"
        }
        
        fn description(&self) -> &'static str {
            "Description of what this experiment does"
        }
        
        fn usage(&self) -> &'static str {
            "<arg1> [arg2] [optional-flag]"
        }
        
        fn run(&self, args: &[String]) -> Result<()> {
            // Your experiment implementation here
            println!("Running my experiment with args: {:?}", args);
            Ok(())
        }
    }
}

2. Register the experiment in ExperimentRegistry::new()

impl ExperimentRegistry {
    pub fn new() -> Self {
        let mut registry = Self {
            experiments: HashMap::new(),
        };
        
        // Register all available experiments
        registry.register(Box::new(bit_operations::BitOperationsExperiment));
        registry.register(Box::new(binary_arithmetic::BinaryArithmeticExperiment));
        registry.register(Box::new(byte_manipulation::ByteManipulationExperiment));
        registry.register(Box::new(my_experiment::MyExperiment)); // Add this line
        
        registry
    }
}

3. Build and test

cargo build
cargo run --bin binary-playground list
cargo run --bin binary-playground run my-experiment

Development Workflow

Running in Development

# Quick iteration during development
cargo run --bin binary-playground run <experiment> [args]

# Build and run optimized version
cargo build --release
./target/release/binary-playground run <experiment> [args]

Adding Dependencies

Add dependencies to the appropriate crate:

  • For CLI-specific dependencies: Edit cli/Cargo.toml
  • For experiment dependencies: Edit experiments/Cargo.toml
  • For workspace-wide dependencies: Edit the root Cargo.toml workspace section

Testing

# Run all tests
cargo test

# Run tests for a specific crate
cargo test -p experiments
cargo test -p binary-playground-cli

Architecture

This project follows Rust best practices for workspace organization:

  • Separation of Concerns: CLI logic is separate from experiment implementations
  • Trait-based Extensibility: All experiments implement the Experiment trait
  • Registry Pattern: Experiments are automatically discoverable through the registry
  • Workspace Dependencies: Shared dependencies are managed at the workspace level
  • Library-first Design: Core functionality is in a library crate, CLI is just a thin wrapper

The Experiment trait provides a standard interface that makes it easy to:

  • Add new experiments without modifying existing code
  • Automatically generate help text and usage information
  • Maintain consistent error handling across all experiments
  • Enable easy testing of individual experiments

Contributing

When adding new experiments:

  1. Follow the existing code style and patterns
  2. Include comprehensive usage examples in your experiment's help text
  3. Handle errors gracefully using anyhow::Result
  4. Add tests for your experiment logic
  5. Update this README with examples of your new experiment

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages