Crate mpack [−] [src]
Experimental new MessagePack implementation for Rust.
This crate provides an alternative MessagePack implementation
to mneumann/rust-msgpack.
This implementation foregoes usage of rustc-serialize
(at least
until a new approach stabilizes) in favor of operating directly on
std::io::Read
and std::io::Write
.
Better serialization sugar is planned, but for now, here's how you would open up a connection and send a value to it:
use std::net::TcpStream; use mpack::{Value, write_value}; let mut conn = TcpStream::connect("127.0.0.1:8081").unwrap(); // write some values write_value(&mut conn, Value::Int32(3)).unwrap(); write_value(&mut conn, Value::String("hello world".to_string())).unwrap();
Reading values is just as easy:
use std::net::TcpStream; use mpack::{Value, Reader}; let mut conn = TcpStream::connect("127.0.0.1:8081").unwrap(); let mut reader = Reader::new(conn); match reader.read_value().unwrap() { Value::Int32(x) => assert_eq!(x, 3), _ => panic!("received unexpected value"), } match reader.read_value().unwrap() { Value::String(str) => println!("{}", str), _ => panic!("received unexpected value"), }
Modules
rpc |
Structs
Reader |
Wraps a reader instance with a place to store the last byte that was read. This simulates pushing that byte back on to the reader if it wasn't recognized. |
Enums
ReadError |
An error encountered while trying to read a value. |
Value |
A value that can be sent by |
WriteError |
An error encountered while trying to write a value. |
Traits
IntoValue |
A trait for types that can be written via MessagePack. This is mostly a convenience to avoid having to wrap them yourself each time. |
Functions
write |
Convenience wrapper for |
write_ext |
Write any value as an Extended type. |
write_value |
Write a message in MessagePack format for the given value. |