Giter Site home page Giter Site logo

Comments (2)

irexiz avatar irexiz commented on July 19, 2024 1

encode and decode have changed to encode_slice and decode_slice since 1e6d843

The following changes to the example work for me:

use bytes::BytesMut;
use mqttrs::*;

fn main() {
    // Allocate write buffer.
    let mut buf = [0u8; 1024];

    // Encode an MQTT Connect packet.
    let pkt = Packet::Connect(Connect {
        protocol: Protocol::MQTT311,
        keep_alive: 30,
        client_id: "doc_client".into(),
        clean_session: true,
        last_will: None,
        username: None,
        password: None,
    });
    let encoded = encode_slice(&pkt, &mut buf);
    assert!(encoded.is_ok());
    let mut buf = BytesMut::from(&buf[..encoded.unwrap()]);

    assert_eq!(&buf[14..], "doc_client".as_bytes());

    // Decode one packet. The buffer will advance to the next packet.
    assert_eq!(Ok(Some(pkt)), decode_slice(&mut buf));

    // Example decode failures.
    let mut incomplete = buf.split_to(10);
    assert_eq!(Ok(None), decode_slice(&mut incomplete));
    let mut garbage = BytesMut::from(&[0u8, 0, 0, 0] as &[u8]);
    assert_eq!(Err(Error::InvalidHeader), decode_slice(&mut garbage));
}

I suggest updating README.md with this, if the repository owner is ok with this

from mqttrs.

irexiz avatar irexiz commented on July 19, 2024

In addition, I'll be forking the repository to try and work in some MQTTv5 features as I have a need for some of them (mainly Message Expiry and Maximum Packet Size)

from mqttrs.

Related Issues (20)

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.