Android-cuttlefish cvd tool
write_exact.h
Go to the documentation of this file.
1//
2// Copyright (C) 2026 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#pragma once
17
18#include <stdint.h>
19
20#include <string>
21#include <vector>
22
23#include "absl/strings/string_view.h"
24
28
29namespace cuttlefish {
30
31Result<void, int> WriteExact(Writer&, const void* buf, size_t size);
32Result<void, int> WriteExact(Writer&,
33 const char* buf); // Assumes null termination
34Result<void, int> WriteExact(Writer&, const std::string&);
35Result<void, int> WriteExact(Writer&, const std::vector<char>&);
36Result<void, int> WriteExact(Writer&, const std::vector<uint8_t>&);
37Result<void, int> WriteExact(Writer&, absl::string_view);
38
39template <typename T>
41 const char* const data_char = reinterpret_cast<const char*>(&data);
42 return WriteExact(writer, data_char, sizeof(data));
43}
44
45} // namespace cuttlefish
Definition: writer.h:25
uint32_t size
Definition: io.h:2
char data[Size]
Definition: incremental_server.cpp:1
Definition: alloc_driver.h:21
Result< void, int > WriteExact(Writer &writer, const void *buf, size_t size)
Definition: write_exact.cc:34
Result< void, int > WriteExactBinary(Writer &writer, const T &data)
Definition: write_exact.h:40
tl::expected< T, StackTraceError< E > > Result
Definition: result_type.h:30