Comments (9)
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.
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.
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.
{
"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.
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.
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.
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.
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.
Test it but I'm pretty sure it's the topic the message was send on.
from rust-ipfs-api.
Related Issues (20)
- When I use documents and examples, I find it can't help me HOT 2
- File Seeks With client.cat HOT 7
- Connection fails with rustls HOT 1
- repo gc HOT 1
- `dag_get` does not decode gracefully
- `object_links` fails for objects with no links
- `get` vs `cat`, `get` possibly returns TAR
- Question - What's the Maintenance / Deprecation Status? HOT 7
- Invalid byte while expecting start of value: 0xa3
- The `/api/v0/swarm/connect` command is not implemented
- Dependency error on cargo doc / cargo run HOT 1
- cat with a timeout can truncate responses
- HTTPError: file argument'value-file' is required
- Override endpoint using environmental variable or local file
- Connection Pooling is Disabled by Default for the Hyper Implementation
- Latest kubo Removes ProtocolVersion Field in id Response
- How to connect ipfs-api with public gateway? HOT 1
- A critical bug in IpfsClient.id() HOT 2
- Replace Deprecated /api/v0/dht endpoints by /api/v0/routing
- type inside `async` block must be known in this context HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-ipfs-api.