Skip to content

Commit 23e93aa

Browse files
committed
Add WriteString
Bug: b/495556334
1 parent cb8b209 commit 23e93aa

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

base/cvd/cuttlefish/io/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ cf_cc_library(
372372
hdrs = ["string.h"],
373373
deps = [
374374
"//cuttlefish/io",
375+
"//cuttlefish/io:write_exact",
375376
"//cuttlefish/result:expect",
376377
"//cuttlefish/result:result_type",
377378
],

base/cvd/cuttlefish/io/string.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <string>
2222

2323
#include "cuttlefish/io/io.h"
24+
#include "cuttlefish/io/write_exact.h"
2425
#include "cuttlefish/result/expect.h"
2526
#include "cuttlefish/result/result_type.h"
2627

@@ -37,4 +38,9 @@ Result<std::string> ReadToString(Reader& reader, size_t buffer_size) {
3738
return out.str();
3839
}
3940

41+
Result<void> WriteString(Writer& writer, std::string_view str) {
42+
CF_EXPECT(WriteExact(writer, str.data(), str.size()));
43+
return {};
44+
}
45+
4046
} // namespace cuttlefish

base/cvd/cuttlefish/io/string.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515

1616
#pragma once
1717

18-
#include <stdint.h>
18+
#include <stddef.h>
1919

2020
#include <string>
21+
#include <string_view>
2122

2223
#include "cuttlefish/io/io.h"
2324
#include "cuttlefish/result/result_type.h"
2425

2526
namespace cuttlefish {
2627

2728
Result<std::string> ReadToString(Reader&, size_t buffer_size = 1 << 16);
29+
Result<void> WriteString(Writer&, std::string_view);
2830

2931
} // namespace cuttlefish

0 commit comments

Comments
 (0)