]> git.ipfire.org Git - thirdparty/squid.git/blame - src/StoreIOBuffer.h
Source Format Enforcement (#963)
[thirdparty/squid.git] / src / StoreIOBuffer.h
CommitLineData
c8be6d7b 1/*
bf95c10a 2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
c8be6d7b 3 *
bbc27441
AJ
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
c8be6d7b 7 */
8
2512d159 9#ifndef SQUID_STOREIOBUFFER_H
10#define SQUID_STOREIOBUFFER_H
11
21dfc374 12#include "base/Range.h"
d0df2779 13#include "MemBuf.h"
c8be6d7b 14
62e76326 15class StoreIOBuffer
16{
17
528b2c61 18public:
967a359a 19 StoreIOBuffer():length(0), offset (0), data (NULL) {flags.error = 0;}
62e76326 20
47f6e231 21 StoreIOBuffer(size_t aLength, int64_t anOffset, char *someData) :
f53969cc 22 length (aLength), offset (anOffset), data (someData) {
63326655 23 flags.error = 0;
62e76326 24 }
25
d0df2779 26 /* Create a StoreIOBuffer from a MemBuf and offset */
27 /* NOTE that MemBuf still "owns" the pointers, StoreIOBuffer is just borrowing them */
47f6e231 28 StoreIOBuffer(MemBuf *aMemBuf, int64_t anOffset) :
f53969cc
SM
29 length(aMemBuf->contentSize()),
30 offset (anOffset),
31 data(aMemBuf->content()) {
d0df2779 32 flags.error = 0;
33 }
34
0ad2b63b 35 StoreIOBuffer(MemBuf *aMemBuf, int64_t anOffset, size_t anLength) :
f53969cc
SM
36 length(anLength),
37 offset (anOffset),
38 data(aMemBuf->content()) {
0ad2b63b
CT
39 flags.error = 0;
40 }
41
26ac0430 42 Range<int64_t> range() const {
47f6e231 43 return Range<int64_t>(offset, offset + length);
2512d159 44 }
45
26ac0430
AJ
46 void dump() const {
47 if (fwrite(data, length, 1, stderr)) {}
48 if (fwrite("\n", 1, 1, stderr)) {}
d0df2779 49 }
50
26ac0430 51 struct {
3d0ac046
HN
52 unsigned error:1;
53 } flags;
c8be6d7b 54 size_t length;
47f6e231 55 int64_t offset;
c8be6d7b 56 char *data;
57};
58
8822ebee
AR
59inline
60std::ostream &
61operator <<(std::ostream &os, const StoreIOBuffer &b)
62{
63 return os << "ioBuf(@" << b.offset << ", len=" << b.length << ", " <<
d9fc6862 64 (void*)b.data << (b.flags.error ? ", ERR" : "") << ')';
8822ebee
AR
65}
66
2512d159 67#endif /* SQUID_STOREIOBUFFER_H */
f53969cc 68