2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 * Copyright (C) 2014 Cloudius Systems, Ltd.
24 #include <seastar/core/deleter.hh>
25 #include <seastar/core/temporary_buffer.hh>
26 #include <seastar/net/packet.hh>
27 #include <seastar/core/sstring.hh>
30 #include <seastar/util/std-compat.hh>
34 template <typename CharType>
35 class scattered_message {
37 using fragment = net::fragment;
38 using packet = net::packet;
39 using char_type = CharType;
42 scattered_message() {}
43 scattered_message(scattered_message&&) = default;
44 scattered_message(const scattered_message&) = delete;
46 void append_static(const char_type* buf, size_t size) {
48 _p = packet(std::move(_p), fragment{(char_type*)buf, size}, deleter());
53 void append_static(const char_type(&s)[N]) {
54 append_static(s, N - 1);
57 void append_static(const char_type* s) {
58 append_static(s, strlen(s));
61 template <typename size_type, size_type max_size>
62 void append_static(const basic_sstring<char_type, size_type, max_size>& s) {
63 append_static(s.begin(), s.size());
66 void append_static(const std::string_view& s) {
67 append_static(s.data(), s.size());
70 void append(std::string_view v) {
72 _p = packet(std::move(_p), temporary_buffer<char>::copy_of(v));
76 template <typename size_type, size_type max_size>
77 void append(basic_sstring<char_type, size_type, max_size> s) {
79 _p = packet(std::move(_p), std::move(s).release());
83 template <typename size_type, size_type max_size, typename Callback>
84 void append(const basic_sstring<char_type, size_type, max_size>& s, Callback callback) {
86 _p = packet(std::move(_p), fragment{s.begin(), s.size()}, make_deleter(std::move(callback)));
90 void reserve(int n_frags) {
98 template <typename Callback>
99 void on_delete(Callback callback) {
100 _p = packet(std::move(_p), make_deleter(std::move(callback)));
103 operator bool() const {