Giter VIP home page Giter VIP logo

Comments (9)

SionoiS avatar SionoiS commented on June 22, 2024 2

I don't know... I think base64 is part of the format of the request, maybe the library should decode it.

The docs tell us that it should be base64.

In reality it's base64 with padding. I used multibase crate with Base64Pad as setting.

+1 for having the lib decode it, it's a little confusing right now.

from rust-ipfs-api.

SionoiS avatar SionoiS commented on June 22, 2024 2

I use this for the from field

let encoded = match response.from.as_ref()?;

let decoded = Base::decode(&Base::Base64Pad, encoded).expect("Decoding sender failed");

let cid = Cid::try_from(decoded).expect("CID from decoded sender failed");

and this for message

let encoded = response.data.as_ref()?;

let decoded = Base::decode(&Base::Base64Pad, encoded).expect("Decoding message failed");

let msg_str = match str::from_utf8(&decoded) {
        Ok(data) => data,
        Err(_) => {
            eprintln!("Chat message invalid UTF-8");
            return None;
        }
};

I hope it helps!

from rust-ipfs-api.

jcaesar avatar jcaesar commented on June 22, 2024

I guess this is in base64 because the answer is returned in JSON, and that can't handle arbitrary binary data?

from rust-ipfs-api.

SionoiS avatar SionoiS commented on June 22, 2024
{
  "data": "<base64-string>",
  "from": "<base64-string>",
  "seqno": "<base64-string>",
  "topicIDs": [
    "<string>"
  ]
}

edit: I'm blind...

I tried decoding the data value with multibase and it failed so IDK...

Also, notice the = sign at the end, no multibase base have that char in their alphabet.

from rust-ipfs-api.

SionoiS avatar SionoiS commented on June 22, 2024

Ok I was wrong there's no bug...

I decoded the string but had to add a 'm' at the start to signify to multibase that it was base64 string.

from rust-ipfs-api.

jcaesar avatar jcaesar commented on June 22, 2024

I don't know... I think base64 is part of the format of the request, maybe the library should decode it.

from rust-ipfs-api.

Tails avatar Tails commented on June 22, 2024

I had trouble here too, as did this StackOverflow poster. I was confused too. I started trying to decode the 'from' field but it kept failing. Until I realized that the decoded 'from' result is actually binary, and that the 'data' and 'seqno' were fine. This worked for me:

String::from_utf8(multibase::decode(format!("M{}", s)).unwrap().1)

from rust-ipfs-api.

Tails avatar Tails commented on June 22, 2024

Does anyone know what the topicIds variable contains? Is it the topic ids when subscribing to a wildcard? Or is it the topic ids that a peer is subscribed to in total?

from rust-ipfs-api.

SionoiS avatar SionoiS commented on June 22, 2024

Test it but I'm pretty sure it's the topic the message was send on.

from rust-ipfs-api.

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.