blob: 26b9f620ed2cf9a06aec4b1bda1d81239f347dc8 [file] [log] [blame]
Armando Montanez68de0712019-11-14 18:29:39 -08001// Copyright 2019 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
Wyatt Hepler1a960942019-11-26 14:13:38 -08004// use this file except in compliance with the License. You may obtain a copy of
5// the License at
Armando Montanez68de0712019-11-14 18:29:39 -08006//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Wyatt Hepler1a960942019-11-26 14:13:38 -080012// License for the specific language governing permissions and limitations under
13// the License.
Armando Montanez68de0712019-11-14 18:29:39 -080014
15#include "pw_dumb_io/dumb_io.h"
16
17namespace pw::dumb_io {
18
Armando Montanez759ff772019-11-18 15:05:53 -080019StatusWithSize ReadBytes(span<std::byte> dest) {
Armando Montanez68de0712019-11-14 18:29:39 -080020 for (size_t i = 0; i < dest.size_bytes(); ++i) {
Armando Montanez759ff772019-11-18 15:05:53 -080021 Status result = ReadByte(&dest[i]);
Armando Montanez68de0712019-11-14 18:29:39 -080022 if (!result.ok()) {
23 return StatusWithSize(result, i);
24 }
25 }
26 return StatusWithSize(dest.size_bytes());
27}
28
Armando Montanez759ff772019-11-18 15:05:53 -080029StatusWithSize WriteBytes(span<const std::byte> src) {
Armando Montanez68de0712019-11-14 18:29:39 -080030 for (size_t i = 0; i < src.size_bytes(); ++i) {
Armando Montanez759ff772019-11-18 15:05:53 -080031 Status result = WriteByte(src[i]);
Armando Montanez68de0712019-11-14 18:29:39 -080032 if (!result.ok()) {
33 return StatusWithSize(result, i);
34 }
35 }
36 return StatusWithSize(src.size_bytes());
37}
38
39} // namespace pw::dumb_io