msgtrans 1.0.4

Support for a variety of communication protocols such as TCP / QUIC / WebSocket, easy to create server and client network library.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# Contributing to MsgTrans

We appreciate your interest in contributing to MsgTrans! This document outlines the guidelines and processes for contributing to this modern multi-protocol communication framework.

## ๐ŸŒŸ Project Vision

MsgTrans aims to make multi-protocol communication simple, efficient, and reliable. Our core principles are:

- **Simplicity**: Elegant APIs that hide complexity
- **Performance**: Lock-free, zero-copy, high-throughput design
- **Reliability**: Type-safe, well-tested, production-ready code
- **Extensibility**: Clean architecture supporting custom protocols
- **Developer Experience**: Excellent documentation and examples

## ๐Ÿš€ Getting Started

### Prerequisites

- **Rust**: 1.80+ (stable toolchain)
- **Git**: For version control
- **IDE**: VSCode with rust-analyzer or similar

### Development Setup

1. **Fork and Clone**
   ```bash
   git clone https://github.com/zoujiaqing/msgtrans.git
   cd msgtrans-rust
   ```

2. **Install Dependencies**
   ```bash
   cargo build
   ```

3. **Run Tests**
   ```bash
   cargo test --all-features
   ```

4. **Run Examples**
   ```bash
   cargo run --example echo_server
   cargo run --example echo_client_tcp
   ```

## ๐Ÿ“‹ Types of Contributions

### ๐Ÿ› Bug Reports
- Use GitHub Issues with the "bug" label
- Include minimal reproduction steps
- Provide environment details (OS, Rust version)
- Include relevant logs and error messages

### โœจ Feature Requests
- Use GitHub Issues with the "enhancement" label
- Explain the use case and problem it solves
- Consider backward compatibility
- Discuss API design implications

### ๐Ÿ“š Documentation
- README improvements
- API documentation (rustdoc)
- Examples and tutorials
- Architecture documentation

### ๐Ÿ”ง Code Contributions
- Bug fixes
- Performance improvements
- New protocol adapters
- Testing improvements

## ๐Ÿ’ป Development Guidelines

### Code Style

**Language Standards**
- All code, comments, and documentation must be in **English**
- No emoji symbols in source code (use text tags like `[PERF]` if needed)
- No "Phase" keywords or development evolution comments
- Professional, technical language throughout

**Rust Standards**
- Follow standard Rust conventions (`cargo fmt`)
- Use `cargo clippy` for linting
- Prefer explicit types when it improves clarity
- Use meaningful variable and function names

**Architecture Patterns**
- Builder pattern for configuration
- Event-driven design
- Protocol-agnostic abstractions
- Zero-copy where possible

### Code Organization

```
src/
โ”œโ”€โ”€ lib.rs              # Public API exports
โ”œโ”€โ”€ error.rs            # Error types and handling
โ”œโ”€โ”€ event.rs            # Event system definitions
โ”œโ”€โ”€ packet.rs           # Packet serialization
โ”œโ”€โ”€ connection.rs       # Connection abstractions
โ”œโ”€โ”€ transport/          # Transport layer
โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”œโ”€โ”€ server.rs
โ”‚   โ”œโ”€โ”€ client.rs
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ adapters/           # Protocol adapters
โ”‚   โ”œโ”€โ”€ tcp.rs
โ”‚   โ”œโ”€โ”€ websocket.rs
โ”‚   โ”œโ”€โ”€ quic.rs
โ”‚   โ””โ”€โ”€ ...
โ””โ”€โ”€ protocol/           # Protocol configurations
    โ””โ”€โ”€ ...
```

### Performance Requirements

- **Lock-free**: Use atomic operations and lock-free data structures
- **Zero-copy**: Minimize data copying with `Arc<[u8]>` and similar
- **Async-first**: All I/O must be asynchronous
- **Memory efficient**: Reuse buffers, avoid unnecessary allocations

### Testing Standards

**Unit Tests**
```rust
#[cfg(test)]
mod tests {
    use super::*;

    #[tokio::test]
    async fn test_tcp_connection_lifecycle() {
        // Test implementation
    }
}
```

**Integration Tests**
- Place in `tests/` directory
- Test real protocol scenarios
- Include performance benchmarks

**Documentation Tests**
- All public APIs must have doc tests
- Examples should be runnable
- Include error handling examples

## ๐Ÿ“ Commit Guidelines

### Commit Message Format

```
<type>(<scope>): <description>

[optional body]

[optional footer]
```

**Types:**
- `feat`: New feature
- `fix`: Bug fix
- `docs`: Documentation changes
- `style`: Code style changes (formatting, etc.)
- `refactor`: Code refactoring
- `perf`: Performance improvements
- `test`: Adding or updating tests
- `chore`: Build process or auxiliary tool changes

**Examples:**
```
feat(transport): add QUIC protocol adapter

Implement QUIC protocol support with:
- Connection establishment and management
- Stream multiplexing
- TLS 1.3 integration

Closes #123
```

```
fix(tcp): resolve connection leak in error handling

Fix memory leak when TCP connections fail during handshake.
Ensure proper cleanup of file descriptors and allocated buffers.

Fixes #456
```

## ๐Ÿ”„ Pull Request Process

### Before Submitting

1. **Create Feature Branch**
   ```bash
   git checkout -b feature/awesome-new-feature
   ```

2. **Write Tests**
   - Unit tests for new functionality
   - Integration tests for complex features
   - Benchmark tests for performance claims

3. **Update Documentation**
   - Rustdoc for public APIs
   - README if adding new features
   - Examples demonstrating usage

4. **Run Quality Checks**
   ```bash
   cargo fmt
   cargo clippy --all-targets --all-features
   cargo test --all-features
   cargo doc --no-deps
   ```

### Pull Request Template

```markdown
## Summary
Brief description of changes

## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Performance improvement
- [ ] Documentation update
- [ ] Refactoring

## Testing
- [ ] Unit tests pass
- [ ] Integration tests pass
- [ ] Manual testing completed
- [ ] Performance benchmarks (if applicable)

## Documentation
- [ ] Code is documented
- [ ] Examples updated
- [ ] README updated (if needed)

## Checklist
- [ ] Code follows project standards
- [ ] All English language used
- [ ] No emoji symbols in source code
- [ ] Commits follow conventional format
- [ ] Tests added for new functionality
```

### Review Process

1. **Automated Checks**: CI must pass
2. **Code Review**: At least one maintainer approval
3. **Testing**: Comprehensive test coverage
4. **Documentation**: Complete API documentation

## ๐Ÿงช Testing

### Running Tests

```bash
# All tests
cargo test --all-features

# Specific module
cargo test transport::tests

# Integration tests
cargo test --test integration

# With output
cargo test -- --nocapture
```

### Performance Testing

```bash
# Benchmarks
cargo bench

# Memory profiling
cargo run --example memory_profile
```

### Coverage

```bash
# Install coverage tool
cargo install cargo-tarpaulin

# Generate coverage report
cargo tarpaulin --all-features --out Html
```

## ๐Ÿ“š Documentation Standards

### API Documentation

```rust
/// Establishes a connection using the specified protocol configuration.
/// 
/// This method performs the complete connection lifecycle including:
/// - Protocol negotiation
/// - Authentication (if required)
/// - Channel establishment
/// 
/// # Arguments
/// 
/// * `config` - Protocol-specific configuration
/// 
/// # Returns
/// 
/// Returns a `Result` containing the established connection or an error.
/// 
/// # Errors
/// 
/// This method will return an error if:
/// - Network connectivity fails
/// - Protocol negotiation fails
/// - Authentication is rejected
/// 
/// # Examples
/// 
/// ```rust
/// use msgtrans::{protocol::TcpClientConfig, tokio};
/// 
/// let config = TcpClientConfig::new("127.0.0.1:8080")?;
/// let client = TransportClientBuilder::new()
///     .with_protocol(config)
///     .build()
///     .await?;
/// ```
pub async fn connect(&mut self) -> Result<(), TransportError> {
    // Implementation
}
```

### Example Standards

- **Complete**: Runnable examples
- **Practical**: Real-world use cases
- **Documented**: Inline comments explaining key concepts
- **Error Handling**: Proper error management

## ๐Ÿ—๏ธ Adding New Protocol Support

### Implementation Checklist

1. **Create Protocol Adapter**
   ```rust
   pub struct MyProtocolAdapter {
       // Implementation
   }
   
   #[async_trait]
   impl ProtocolAdapter for MyProtocolAdapter {
       // Required methods
   }
   ```

2. **Configuration Types**
   ```rust
   pub struct MyProtocolServerConfig {
       // Configuration fields
   }
   
   impl ServerConfig for MyProtocolServerConfig {
       // Implementation
   }
   ```

3. **Error Handling**
   - Protocol-specific error types
   - Proper error propagation
   - Graceful degradation

4. **Testing Suite**
   - Unit tests for adapter logic
   - Integration tests with real connections
   - Performance benchmarks

5. **Documentation**
   - API documentation
   - Usage examples
   - Protocol-specific guides

## ๐Ÿšซ Code of Conduct

### Our Standards

- **Respectful**: Treat all contributors with respect
- **Inclusive**: Welcome diverse perspectives and backgrounds
- **Constructive**: Provide helpful, actionable feedback
- **Professional**: Maintain professional communication
- **Collaborative**: Work together toward common goals

### Unacceptable Behavior

- Harassment or discrimination
- Trolling or inflammatory comments
- Personal attacks
- Spam or off-topic content
- Violation of privacy

### Enforcement

Issues can be reported to the maintainers. All reports will be handled confidentially and appropriately.

## ๐Ÿ“ž Getting Help

### Communication Channels

- **GitHub Issues**: Bug reports and feature requests
- **GitHub Discussions**: General questions and community discussion
- **Email**: Direct contact with maintainers

### Resources

- **Documentation**: Check rustdoc and README first
- **Examples**: Review example code in `examples/`
- **Tests**: Look at existing tests for patterns

## ๐Ÿท๏ธ Release Process

### Versioning

We follow [Semantic Versioning](https://semver.org/):
- **MAJOR**: Breaking API changes
- **MINOR**: New features (backward compatible)
- **PATCH**: Bug fixes (backward compatible)

### Release Checklist

- [ ] All tests pass
- [ ] Documentation updated
- [ ] CHANGELOG.md updated
- [ ] Version bumped in Cargo.toml
- [ ] Git tag created
- [ ] Published to crates.io

## ๐Ÿ™ Recognition

Contributors are recognized in several ways:
- **Git history**: All contributions are preserved
- **Release notes**: Major contributions highlighted
- **README**: Core contributors listed

Thank you for contributing to MsgTrans! ๐Ÿš€

---

**Questions?** Open an issue or start a discussion. We're here to help!