qp2p/
utils.rs

1// Copyright 2019 MaidSafe.net limited.
2//
3// This SAFE Network Software is licensed to you under the MIT license <LICENSE-MIT
4// http://opensource.org/licenses/MIT> or the Modified BSD license <LICENSE-BSD
5// https://opensource.org/licenses/BSD-3-Clause>, at your option. This file may not be copied,
6// modified, or distributed except according to those terms. Please review the Licences for the
7// specific language governing permissions and limitations relating to use of the SAFE Network
8// Software.
9
10/// Convert binary data to a diplay-able format
11#[inline]
12pub(crate) fn bin_data_format(data: &[u8]) -> String {
13    let len = data.len();
14    if len < 8 {
15        return format!("[ {data:?} ]");
16    }
17
18    format!(
19        "[ {:02x} {:02x} {:02x} {:02x}..{:02x} {:02x} {:02x} {:02x} ]",
20        data[0],
21        data[1],
22        data[2],
23        data[3],
24        data[len - 4],
25        data[len - 3],
26        data[len - 2],
27        data[len - 1]
28    )
29}