blob: 70cd0073962c9f7ada24146ed1c7a2c61f47a665 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "slice.h"
#include <iomanip>
#include <sstream>
namespace overnet {
std::ostream& operator<<(std::ostream& out, const Slice& slice) {
bool first = true;
std::ostringstream temp;
for (auto b : slice) {
if (!first)
temp << ' ';
temp << std::hex << std::setfill('0') << std::setw(2)
<< static_cast<unsigned>(b);
first = false;
}
if (!first)
temp << ' ';
temp << '"';
for (auto b : slice) {
const auto c = static_cast<char>(b);
if (isprint(c)) {
temp << c;
} else {
temp << '.';
}
}
temp << '"';
return out << '[' << temp.str() << ']';
}
std::ostream& operator<<(std::ostream& out, const Chunk& chunk) {
return out << "@" << chunk.offset << chunk.slice;
}
} // namespace overnet