2019-11-15 02:29:39 +00:00
|
|
|
// Copyright 2019 The Pigweed Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
2019-11-26 22:13:38 +00:00
|
|
|
// use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
// the License at
|
2019-11-15 02:29:39 +00:00
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
2019-11-26 22:13:38 +00:00
|
|
|
// License for the specific language governing permissions and limitations under
|
|
|
|
// the License.
|
2019-11-15 02:29:39 +00:00
|
|
|
|
|
|
|
#include "pw_dumb_io/dumb_io.h"
|
|
|
|
|
|
|
|
namespace pw::dumb_io {
|
|
|
|
|
2019-11-18 23:05:53 +00:00
|
|
|
StatusWithSize ReadBytes(span<std::byte> dest) {
|
2019-11-15 02:29:39 +00:00
|
|
|
for (size_t i = 0; i < dest.size_bytes(); ++i) {
|
2019-11-18 23:05:53 +00:00
|
|
|
Status result = ReadByte(&dest[i]);
|
2019-11-15 02:29:39 +00:00
|
|
|
if (!result.ok()) {
|
|
|
|
return StatusWithSize(result, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return StatusWithSize(dest.size_bytes());
|
|
|
|
}
|
|
|
|
|
2019-11-18 23:05:53 +00:00
|
|
|
StatusWithSize WriteBytes(span<const std::byte> src) {
|
2019-11-15 02:29:39 +00:00
|
|
|
for (size_t i = 0; i < src.size_bytes(); ++i) {
|
2019-11-18 23:05:53 +00:00
|
|
|
Status result = WriteByte(src[i]);
|
2019-11-15 02:29:39 +00:00
|
|
|
if (!result.ok()) {
|
|
|
|
return StatusWithSize(result, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return StatusWithSize(src.size_bytes());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace pw::dumb_io
|