Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dag_get does not decode gracefully #109

Open
mrd0ll4r opened this issue Sep 20, 2022 · 0 comments
Open

dag_get does not decode gracefully #109

mrd0ll4r opened this issue Sep 20, 2022 · 0 comments

Comments

@mrd0ll4r
Copy link
Contributor

I'm trying to move from object_links (or object_get) to dag_get, since the former are deprecated.

dag_get currently returns Bytes. I selected DagCodec::Json for the encoding, and the returned value is indeed JSON, but cannot be parsed as DagGetResponse. I'm not sure if this type is even intended for this use case, but I figured, from the name...

Request code:

let object_links_resp_raw = client
            .dag_get_with_options(DagGet {
                path: cid,
                codec: Some(DagCodec::Json),
            })
            .map_ok(|chunk| chunk.to_vec())
            .try_concat()
            .await
            .context("unable to object links")?;
println!("{:?}",String::from_utf8(object_links_resp_raw.clone()));
let object_links_resp = serde_json::from_slice::<DagGetResponse>(&object_links_resp_raw)
            .context("unable to decode response")?;

which gives me this JSON:

"{\"Data\":{\"/\":{\"bytes\":\"CAUSFQEABAAAAAAAAAEAAAgAAAAAAAAQACgiMIAC\"}},\"Links\":[{\"Hash\":{\"/\":\"QmPQVLHXAcDLvdf6ni24YWgGwitVTwtpiFaKkMfzZKquUB\"},\"Name\":\"0C-\",\"Tsize\":237360},{\"Hash\":{\"/\":\"QmNYBYYjwtCYXdA2KC68rX8RqXBu9ajBM6Gi8CBrXjvk1j\"},\"Name\":\"43I\",\"Tsize\":4432
3016540},{\"Hash\":{\"/\":\"QmehSxmTPRCr85Xjgzjut6uWQihoTfqg9VVihJ892bmZCp\"},\"Name\":\"58wiki\",\"Tsize\":613715579624},{\"Hash\":{\"/\":\"QmaeP3RagknCH4gozhE6VfCzTZRU7U2tgEEfs8QMoexEeG\"},\"Name\":\"92M\",\"Tsize\":826},{\"Hash\":{\"/\":\"QmdgiZFqdzUGa7vAFycnA5Xv2mbcdHSsPQHsMyhpuzm9xb\"},\"
Name\":\"A0index.html\",\"Tsize\":165}]}"

pretty:

{
  "Data": {
    "/": {
      "bytes": "CAUSFQEABAAAAAAAAAEAAAgAAAAAAAAQACgiMIAC"
    }
  },
  "Links": [
    {
      "Hash": {
        "/": "QmPQVLHXAcDLvdf6ni24YWgGwitVTwtpiFaKkMfzZKquUB"
      },
      "Name": "0C-",
      "Tsize": 237360
    },
    {
      "Hash": {
        "/": "QmNYBYYjwtCYXdA2KC68rX8RqXBu9ajBM6Gi8CBrXjvk1j"
      },
      "Name": "43I",
      "Tsize": 44323016540
    },
    {
      "Hash": {
        "/": "QmehSxmTPRCr85Xjgzjut6uWQihoTfqg9VVihJ892bmZCp"
      },
      "Name": "58wiki",
      "Tsize": 613715579624
    },
    {
      "Hash": {
        "/": "QmaeP3RagknCH4gozhE6VfCzTZRU7U2tgEEfs8QMoexEeG"
      },
      "Name": "92M",
      "Tsize": 826
    },
    {
      "Hash": {
        "/": "QmdgiZFqdzUGa7vAFycnA5Xv2mbcdHSsPQHsMyhpuzm9xb"
      },
      "Name": "A0index.html",
      "Tsize": 165
    }
  ]
}

which does not fit DagGetResponse:

pub struct DagGetResponse {
    pub data: Option<String>,

    #[serde(deserialize_with = "serde::deserialize_vec")]
    pub links: Vec<DagIpfsHeader>,
}

Field names are PascalCase, data is ... something, but not a String.

I'm not sure if the format changed at some point, since there is a test case for a different (old?) format...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant