Git Product home page Git Product logo

tokio-serde's Introduction

Tokio Serialize / Deserialize

Utilities needed to easily implement a Tokio transport using serde for serialization and deserialization of frame values.

Documentation

Usage

To use tokio-serde, first add this to your Cargo.toml:

[dependencies]
tokio-serde = "0.8"

Next, add this to your crate:

use tokio_serde::{Serializer, Deserializer, Framed};

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in iovec by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

tokio-serde's People

Contributors

bazaah avatar bkchr avatar carllerche avatar dblouis avatar foldu avatar lberrymage avatar tikue avatar urhengulas avatar vorot93 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tokio-serde's Issues

getting unresolved import `tokio_serde::formats`

hi,
Can't seem to be able to use it my code.

I did import tokio-serde = "0.8.0" in my dependencies, maybe I'm missing something ?

Though when i put use tokio_serde::SymmetricallyFramed in code for example it does recognize it.

Ran into some very sinister behaviour using SymmetricallyFramed

Using the lib on a length_delimited like this:

image

caused data to accumulate (buffer up), and when I would close the sending connection it would flush the buffered values somehow, causing lag, this was really hard to locate.

image

rewriting the functionality like (which is functionality wise identical), removed the lag and the "buffering". Any idea what causes this "buffering" to happen?

Fails on large software

I have a large client-server software where the messages are encoded and decoded through bincode and may contain a bunch of strings, integers, floats, etc.

I recently tried to move to tokio which simplifies and fixes portability bugs (random os error 35 on macOS for example). To move the code I've used tokio-serde to support deserializing the packets serialize through bincode. Unfortunately, every-time a packet contains a bunch of strings tokio-serde errors with "frame size too big".

Is there any workaround to this bug?

Using into_split() with FramedWrite and FramedRead

Thanks for this library, really appreciate it. Its saving me a lot of time.

I was wondering if https://docs.rs/tokio/1.0.2/tokio/net/struct.TcpStream.html#method.into_split would ever get any support?

I want to read and write from the same stream, I kinda needed to do something hacky to achieve this, is there any alternative to this?

let stream1 = stream.into_std().unwrap();
let stream2 = stream1.try_clone().unwrap();

let stream1_ = TcpStream::from_std(stream1).unwrap();
let stream2_ = TcpStream::from_std(stream2).unwrap();

let length_delimited = FramedWrite::new(stream1_, LengthDelimitedCodec::new());
let length_delimited_ = FramedRead::new(stream2_, LengthDelimitedCodec::new());

Bytes remaining after deserialization using bincode

Hi, just tried tokio-serde and I might be doing it wrong.

Client is modified to look like:

#[tokio::main]
pub async fn main() {
    let socket = TcpStream::connect("127.0.0.1:17653").await.unwrap();
    let length_delimited = FramedWrite::new(socket, LengthDelimitedCodec::new());
    let mut serialized = tokio_serde::SymmetricallyFramed::new(length_delimited, SymmetricalBincode::default());

    let thing = tokio_serde::Thing { val: 123 };
    let some_data = bincode_crate::serialize(&thing).unwrap();

    serialized
        .send(some_data)
        .await
        .unwrap()
}

Server is now:

#[tokio::main]
pub async fn main() {
    let mut listener = TcpListener::bind("127.0.0.1:17653").await.unwrap();
    println!("listening on {:?}", listener.local_addr());

    while let Some(socket) = listener.try_next().await.unwrap() {
        let length_delimited = FramedRead::new(socket, LengthDelimitedCodec::new());

        let mut deserialized = tokio_serde::SymmetricallyFramed::new(
            length_delimited,
            SymmetricalBincode::<Thing>::default(),
        );

        tokio::spawn(async move {
            while let Some(msg) = deserialized.try_next().await.unwrap() {
                println!("GOT: {:?}", msg);
            }
        });
    }
}

And thing is simply:

#[derive(Debug, Serialize, Deserialize)]
pub struct Thing {
    pub val: usize,
}

Client sends successfully, but server panics:

called Result::unwrap() on an Err value: Custom { kind: InvalidData, error: Custom("Slice had bytes remaining after deserialization") }

I see that the bincode options default to rejecting extra bytes, which I would assume is a good thing.
Have I just missed something?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.