VPN Link Serde
A comprehensive Rust library for parsing and serializing VPN proxy protocol links. Supports VMess, VLess, Shadowsocks, Trojan, and Hysteria2 protocols with full parameter support.
Features
- ✅ Parse protocol links into structured Rust types
- ✅ Serialize structured types back into protocol links
- ✅ Full protocol support for all variants and parameters
- ✅ Comprehensive error handling with detailed error messages
- ✅ Serde support for serialization/deserialization
- ✅ Well-documented with examples
- ✅ Zero dependencies on external parsing libraries (only uses standard Rust crates)
Supported Protocols
- VMess (
vmess://) - V1 and V2 formats - VLess (
vless://) - Full parameter support including Reality, XTLS, and TLS - Shadowsocks (
ss://) - Base64 and SIP002 formats - Trojan (
trojan://) - Full TLS and XTLS support - Hysteria2 (
hysteria2://) - Complete configuration support
各协议的链接格式、解析规则与组成规范见 doc/protocols.md,并与 SIP002、Project V、XTLS、Trojan、Hysteria2 官方文档交叉对照。
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Basic Example
use Protocol;
// Parse any protocol link
let protocol = parse?;
// Generate link from parsed protocol
let link = protocol.to_link?;
Protocol-Specific Parsing
use ;
// Parse VMess link
let vmess = parse?;
println!;
println!;
// Parse VLess link
let vless = parse?;
println!;
println!;
// Parse Shadowsocks link
let ss = parse?;
println!;
println!;
// Parse Trojan link
let trojan = parse?;
println!;
println!;
// Parse Hysteria2 link
let h2 = parse?;
println!;
println!;
Using the Protocol Enum
use Protocol;
// Automatically detect protocol type
let protocol = parse?;
match protocol
// Generate link
let link = protocol.to_link?;
Serialization/Deserialization
All configuration structures implement Serialize and Deserialize:
use VMess;
use serde_json;
let vmess = parse?;
// Serialize to JSON
let json = to_string?;
// Deserialize from JSON
let config: VMessV2 = from_str?;
Error Handling
The library provides comprehensive error handling:
use ;
match parse
Protocol Details
VMess
Supports both V1 and V2 formats. V1 format links are automatically converted to V2 format when parsed.
use VMess;
// V2 format (recommended)
let vmess = parse?;
VLess
Full support for all VLess parameters including Reality, XTLS, and TLS:
use VLess;
let vless = parse?;
Shadowsocks
Supports both base64-encoded and SIP002 formats:
use Shadowsocks;
// SIP002 format (recommended)
let ss = parse?;
Trojan
Full TLS and XTLS support:
use Trojan;
let trojan = parse?;
Hysteria2
Complete configuration support:
use Hysteria2;
let h2 = parse?;
Contributing
Contributions are welcome. Please read CONTRIBUTING.md for code standards and the pull request process. By participating, you agree to uphold our Code of Conduct.
License
Licensed under either of
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Changelog
See CHANGELOG.md for details.