| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quic_data_writer.h" | 5 #include "net/quic/quic_data_writer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 152 |
| 153 void QuicDataWriter::WritePadding() { | 153 void QuicDataWriter::WritePadding() { |
| 154 DCHECK_LE(length_, capacity_); | 154 DCHECK_LE(length_, capacity_); |
| 155 if (length_ > capacity_) { | 155 if (length_ > capacity_) { |
| 156 return; | 156 return; |
| 157 } | 157 } |
| 158 memset(buffer_ + length_, 0x00, capacity_ - length_); | 158 memset(buffer_ + length_, 0x00, capacity_ - length_); |
| 159 length_ = capacity_; | 159 length_ = capacity_; |
| 160 } | 160 } |
| 161 | 161 |
| 162 bool QuicDataWriter::WriteUInt8ToOffset(uint8 value, size_t offset) { | |
| 163 if (offset >= capacity_) { | |
| 164 LOG(DFATAL) << "offset: " << offset << " >= capacity: " << capacity_; | |
| 165 return false; | |
| 166 } | |
| 167 size_t latched_length = length_; | |
| 168 length_ = offset; | |
| 169 bool success = WriteUInt8(value); | |
| 170 DCHECK_LE(length_, latched_length); | |
| 171 length_ = latched_length; | |
| 172 return success; | |
| 173 } | |
| 174 | |
| 175 bool QuicDataWriter::WriteUInt32ToOffset(uint32 value, size_t offset) { | |
| 176 DCHECK_LT(offset, capacity_); | |
| 177 size_t latched_length = length_; | |
| 178 length_ = offset; | |
| 179 bool success = WriteUInt32(value); | |
| 180 DCHECK_LE(length_, latched_length); | |
| 181 length_ = latched_length; | |
| 182 return success; | |
| 183 } | |
| 184 | |
| 185 bool QuicDataWriter::WriteUInt48ToOffset(uint64 value, size_t offset) { | |
| 186 DCHECK_LT(offset, capacity_); | |
| 187 size_t latched_length = length_; | |
| 188 length_ = offset; | |
| 189 bool success = WriteUInt48(value); | |
| 190 DCHECK_LE(length_, latched_length); | |
| 191 length_ = latched_length; | |
| 192 return success; | |
| 193 } | |
| 194 | 162 |
| 195 } // namespace net | 163 } // namespace net |
| OLD | NEW |