aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/data/memory.cpp
blob: 7a10f4eb2d71ca8af5188e1bdd0619ca43083b6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "memory.h"
#include <vespa/vespalib/util/stringfmt.h>

namespace vespalib {

vespalib::string
Memory::make_string() const
{
    return vespalib::string(data, size);
}

std::ostream &operator<<(std::ostream &os, const Memory &memory) {
    uint32_t written = 0;
    uint32_t hexCount = 25;
    os << "size: " << memory.size << "(bytes)" << std::endl;
    for (size_t i = 0; i < memory.size; ++i, ++written) {
        if (written > hexCount) {
            os << std::endl;
            written = 0;
        }
        os << vespalib::make_string("0x%02x ", memory.data[i] & 0xff);
    }
    if (written > 0) {
        os << std::endl;
    }
    return os;
}

} // namespace vespalib