Skip to content

Conversation

@hinto-janai
Copy link
Member

@hinto-janai hinto-janai commented Jun 6, 2025

What

  • Adds cuprate_epee_encoding::debug behind feature debug
  • Adds code to map T: EpeeObject into debug::EpeeObject which can be formatted with serde_json

Why

To allow sanely debugging binary RPC. This can be used for panic formatting in cuprate-test-rpc as well.

@github-actions github-actions bot added A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. A-workspace Area: Changes to a root workspace file or general repo file. A-net Area: Related to networking. labels Jun 6, 2025
Comment on lines +33 to +39
impl Display for EpeeObject {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(
&serde_json::to_string_pretty(&Map::<String, serde_json::Value>::from(self)).unwrap(),
)
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fn main() {
    #[rustfmt::skip]
    let get_blocks_bin_response_default = [
        // header
        0x01, 0x11, 0x01, 0x01, 0x01, 0x01, 0x02, 0x01, 0x01,
        // entry count
        0x14,
        // "start_height": 0
        0x0c, b's', b't', b'a', b'r', b't', b'_', b'h', b'e', b'i', b'g', b'h', b't',
        0x05, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
        // "current_height": 0
        0x0e, b'c', b'u', b'r', b'r', b'e', b'n', b't', b'_', b'h', b'e', b'i', b'g', b'h', b't',
        0x05, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
        // "credits": 0
        0x07, b'c', b'r', b'e', b'd', b'i', b't', b's',
        0x05, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
        // "status": "OK"
        0x06, b's', b't', b'a', b't', b'u', b's', b'\n',
        0x08, b'O', b'K',
        // "untrusted": false
        b'\t', b'u', b'n', b't', b'r', b'u', b's', b't', b'e', b'd',
        0x0b, 0x0
    ];

    let mut bytes =
        cuprate_epee_encoding::to_bytes(cuprate_rpc_types::bin::GetBlocksResponse::default())
            .unwrap();

    assert_eq!(get_blocks_bin_response_default, *bytes);

    println!(
        "{}",
        cuprate_epee_encoding::debug::EpeeObject::new(&mut bytes).unwrap()
    )
}
{
  "credits": 0,
  "current_height": 0,
  "start_height": 0,
  "status": "OK",
  "untrusted": false
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-dependency Area: Related to dependencies, or changes to a Cargo.{toml,lock} file. A-net Area: Related to networking. A-workspace Area: Changes to a root workspace file or general repo file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants