/work/snappy_ep-prefix/src/snappy_ep/snappy-sinksource.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2011 Google Inc. All Rights Reserved. |
2 | | // |
3 | | // Redistribution and use in source and binary forms, with or without |
4 | | // modification, are permitted provided that the following conditions are |
5 | | // met: |
6 | | // |
7 | | // * Redistributions of source code must retain the above copyright |
8 | | // notice, this list of conditions and the following disclaimer. |
9 | | // * Redistributions in binary form must reproduce the above |
10 | | // copyright notice, this list of conditions and the following disclaimer |
11 | | // in the documentation and/or other materials provided with the |
12 | | // distribution. |
13 | | // * Neither the name of Google Inc. nor the names of its |
14 | | // contributors may be used to endorse or promote products derived from |
15 | | // this software without specific prior written permission. |
16 | | // |
17 | | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
18 | | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
19 | | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
20 | | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
21 | | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
22 | | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
23 | | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 | | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | | |
29 | | #include <stddef.h> |
30 | | #include <cstring> |
31 | | |
32 | | #include "snappy-sinksource.h" |
33 | | |
34 | | namespace snappy { |
35 | | |
36 | 3.42k | Source::~Source() = default; |
37 | | |
38 | 0 | Sink::~Sink() = default; |
39 | | |
40 | 0 | char* Sink::GetAppendBuffer(size_t length, char* scratch) { |
41 | | // TODO: Switch to [[maybe_unused]] when we can assume C++17. |
42 | 0 | (void)length; |
43 | |
|
44 | 0 | return scratch; |
45 | 0 | } |
46 | | |
47 | | char* Sink::GetAppendBufferVariable( |
48 | | size_t min_size, size_t desired_size_hint, char* scratch, |
49 | 0 | size_t scratch_size, size_t* allocated_size) { |
50 | | // TODO: Switch to [[maybe_unused]] when we can assume C++17. |
51 | 0 | (void)min_size; |
52 | 0 | (void)desired_size_hint; |
53 | |
|
54 | 0 | *allocated_size = scratch_size; |
55 | 0 | return scratch; |
56 | 0 | } |
57 | | |
58 | | void Sink::AppendAndTakeOwnership( |
59 | | char* bytes, size_t n, |
60 | | void (*deleter)(void*, const char*, size_t), |
61 | 0 | void *deleter_arg) { |
62 | 0 | Append(bytes, n); |
63 | 0 | (*deleter)(deleter_arg, bytes, n); |
64 | 0 | } |
65 | | |
66 | | ByteArraySource::~ByteArraySource() = default; |
67 | | |
68 | 3.42k | size_t ByteArraySource::Available() const { return left_; } |
69 | | |
70 | 10.2k | const char* ByteArraySource::Peek(size_t* len) { |
71 | 10.2k | *len = left_; |
72 | 10.2k | return ptr_; |
73 | 10.2k | } |
74 | | |
75 | 14.2k | void ByteArraySource::Skip(size_t n) { |
76 | 14.2k | left_ -= n; |
77 | 14.2k | ptr_ += n; |
78 | 14.2k | } |
79 | | |
80 | | UncheckedByteArraySink::~UncheckedByteArraySink() { } |
81 | | |
82 | 0 | void UncheckedByteArraySink::Append(const char* data, size_t n) { |
83 | | // Do no copying if the caller filled in the result of GetAppendBuffer() |
84 | 0 | if (data != dest_) { |
85 | 0 | std::memcpy(dest_, data, n); |
86 | 0 | } |
87 | 0 | dest_ += n; |
88 | 0 | } |
89 | | |
90 | 0 | char* UncheckedByteArraySink::GetAppendBuffer(size_t len, char* scratch) { |
91 | | // TODO: Switch to [[maybe_unused]] when we can assume C++17. |
92 | 0 | (void)len; |
93 | 0 | (void)scratch; |
94 | |
|
95 | 0 | return dest_; |
96 | 0 | } |
97 | | |
98 | | void UncheckedByteArraySink::AppendAndTakeOwnership( |
99 | | char* bytes, size_t n, |
100 | | void (*deleter)(void*, const char*, size_t), |
101 | 0 | void *deleter_arg) { |
102 | 0 | if (bytes != dest_) { |
103 | 0 | std::memcpy(dest_, bytes, n); |
104 | 0 | (*deleter)(deleter_arg, bytes, n); |
105 | 0 | } |
106 | 0 | dest_ += n; |
107 | 0 | } |
108 | | |
109 | | char* UncheckedByteArraySink::GetAppendBufferVariable( |
110 | | size_t min_size, size_t desired_size_hint, char* scratch, |
111 | 0 | size_t scratch_size, size_t* allocated_size) { |
112 | | // TODO: Switch to [[maybe_unused]] when we can assume C++17. |
113 | 0 | (void)min_size; |
114 | 0 | (void)scratch; |
115 | 0 | (void)scratch_size; |
116 | |
|
117 | 0 | *allocated_size = desired_size_hint; |
118 | 0 | return dest_; |
119 | 0 | } |
120 | | |
121 | | } // namespace snappy |