Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
Add const qualifier to the first argument of Write method. (#38)
Browse files Browse the repository at this point in the history
The pointer to data doesn't need to be changed. Making it const so it
can accept pointer casted from std::string.
  • Loading branch information
jianjunz authored Sep 29, 2021
1 parent 56ab441 commit 995f58b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class OWT_EXPORT WebTransportStreamInterface {
virtual void SetVisitor(Visitor* visitor) = 0;
// Write or buffer data. Returns the length of data written or buffered.
// Current implementation always returns 0 or `length`.
virtual size_t Write(uint8_t* data, size_t length) = 0;
virtual size_t Write(const uint8_t* data, size_t length) = 0;
// Reads at most `length` bytes into `data` and returns the number of bytes
// actually read.
virtual size_t Read(uint8_t* data, size_t length) = 0;
Expand Down
8 changes: 4 additions & 4 deletions web_transport/sdk/impl/web_transport_stream_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ uint32_t WebTransportStreamImpl::Id() const {
return stream_->GetStreamId();
}

size_t WebTransportStreamImpl::Write(uint8_t* data, size_t length) {
size_t WebTransportStreamImpl::Write(const uint8_t* data, size_t length) {
DCHECK_EQ(sizeof(uint8_t), sizeof(char));
CHECK(io_runner_);
if (io_runner_->BelongsToCurrentThread()) {
Expand All @@ -71,11 +71,11 @@ size_t WebTransportStreamImpl::Write(uint8_t* data, size_t length) {
io_runner_->PostTask(
FROM_HERE,
base::BindOnce(
[](WebTransportStreamImpl* stream, uint8_t* data, size_t& length,
[](WebTransportStreamImpl* stream, const uint8_t* data, size_t& length,
bool& result, base::WaitableEvent* event) {
if (stream->stream_->CanWrite()) {
result = stream->stream_->Write(
absl::string_view(reinterpret_cast<char*>(data), length));
result = stream->stream_->Write(absl::string_view(
reinterpret_cast<const char*>(data), length));
} else {
result = false;
}
Expand Down
2 changes: 1 addition & 1 deletion web_transport/sdk/impl/web_transport_stream_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class WebTransportStreamImpl : public WebTransportStreamInterface,
void SetVisitor(
owt::quic::WebTransportStreamInterface::Visitor* visitor) override;
uint32_t Id() const override;
size_t Write(uint8_t* data, size_t length) override;
size_t Write(const uint8_t* data, size_t length) override;
size_t Read(uint8_t* data, size_t length) override;
size_t ReadableBytes() const override;
void Close() override;
Expand Down

0 comments on commit 995f58b

Please sign in to comment.