// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/numerics/safe_conversions.h" #include "base/stl_util.h" #include "device/serial/buffer.h" #include "net/base/io_buffer.h" namespace device { ReadOnlyBuffer::~ReadOnlyBuffer() { } WritableBuffer::~WritableBuffer() { } SendBuffer::SendBuffer( const std::vector& data, const base::Callback& callback) : data_(data), callback_(callback) {} SendBuffer::~SendBuffer() {} const char* SendBuffer::GetData() { return vector_as_array(&data_); } uint32_t SendBuffer::GetSize() { return base::checked_cast(data_.size()); } void SendBuffer::Done(uint32_t bytes_read) { callback_.Run(bytes_read, device::serial::SEND_ERROR_NONE); } void SendBuffer::DoneWithError(uint32_t bytes_read, int32_t error) { callback_.Run(bytes_read, static_cast(error)); } ReceiveBuffer::ReceiveBuffer( scoped_refptr buffer, uint32_t size, const base::Callback& callback) : buffer_(buffer), size_(size), callback_(callback) {} ReceiveBuffer::~ReceiveBuffer() {} char* ReceiveBuffer::GetData() { return buffer_->data(); } uint32_t ReceiveBuffer::GetSize() { return size_; } void ReceiveBuffer::Done(uint32_t bytes_written) { callback_.Run(bytes_written, device::serial::RECEIVE_ERROR_NONE); } void ReceiveBuffer::DoneWithError(uint32_t bytes_written, int32_t error) { callback_.Run(bytes_written, static_cast(error)); } } // namespace device