VOOZH about

URL: https://codereview.chromium.org/11125002/diff/11031/net/quic/quic_data_reader.cc

⇱ net/quic/quic_data_reader.cc - Issue 11125002: Add QuicFramer and friends. - Code Review


Side by Side Diff

Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Keyboard Shortcuts

File
u :up to issue
j / k :jump to file after / before current file
J / K :jump to next file with a comment after / before current file
Side-by-side diff
i :toggle intra-line diffs
e :expand all comments
c :collapse all comments
s :toggle showing all comments
n / p :next / previous diff chunk or comment
N / P :next / previous comment
<Up> / <Down> :next / previous line
Issue
u :up to list of issues
j / k :jump to patch after / before current patch
o / <Enter> :open current patch in side-by-side view
i :open current patch in unified diff view
Issue List
j / k :jump to issue after / before current issue
o / <Enter> :open current issue
👁 Image
Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Issues Search
    My Issues | Starred     Open | Closed | All

Side by Side Diff: net/quic/quic_data_reader.cc

👁 Image
Issue 11125002: Add QuicFramer and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: narrowing in Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« net/quic/quic_data_reader.h ('K') | « net/quic/quic_data_reader.h ('k') | net/quic/quic_data_writer.h » ('j') | net/quic/quic_data_writer.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
// Copyright (c) 2012 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 "net/quic/quic_data_reader.h"
using base::StringPiece;
namespace net {
QuicDataReader::QuicDataReader(const char* data, const size_t len)
: data_(data),
len_(len),
pos_(0) {
}
bool QuicDataReader::ReadUInt16(uint16* result) {
// Make sure that we have the whole uint16.
if (!CanRead(2)) {
jar (doing other things) 2012/10/14 23:04:38 nit: probably better is to use: CanRead(sizeof(*re
Ryan Hamilton 2012/10/15 21:22:08 Added TODO. Will address in a follow on CL once t
OnFailure();
return false;
}
// Read into result.
*result = *reinterpret_cast<const uint16*>(data_ + pos_);
// Iterate.
pos_ += 2;
return true;
}
bool QuicDataReader::ReadUInt32(uint32* result) {
// Make sure that we have the whole uint32.
if (!CanRead(4)) {
OnFailure();
return false;
}
// Read into result.
*result = *reinterpret_cast<const uint32*>(data_ + pos_);
// Iterate.
pos_ += 4;
return true;
}
bool QuicDataReader::ReadUInt48(uint64* result) {
// Make sure that we have the whole uint48.
jar (doing other things) 2012/10/14 23:04:38 nit: you don't need lines 51-54, since the other r
Ryan Hamilton 2012/10/15 21:22:08 Done.
if (!CanRead(6)) {
OnFailure();
return false;
}
uint32 lo;
if (!ReadUInt32(&lo)) {
return false;
}
uint16 hi;
if (!ReadUInt16(&hi)) {
return false;
}
*result = hi;
*result <<= 32;
*result += lo;
return true;
}
bool QuicDataReader::ReadUInt64(uint64* result) {
// Make sure that we have the whole uint64.
if (!CanRead(8)) {
OnFailure();
return false;
}
// Read into result.
LOG(INFO) << "here";
jar (doing other things) 2012/10/14 23:04:38 nit: DLOG?
Ryan Hamilton 2012/10/15 21:22:08 Part of my on-going debugging. will remove.
*result = *reinterpret_cast<const uint64*>(data_ + pos_);
LOG(INFO) << "here";
// Iterate.
pos_ += 8;
return true;
}
bool QuicDataReader::ReadUInt128(uint128* result) {
uint64 high_hash;
uint64 low_hash;
if (!ReadUInt64(&low_hash)) {
return false;
}
if (!ReadUInt64(&high_hash)) {
return false;
}
*result = uint128(high_hash, low_hash);
return true;
}
bool QuicDataReader::ReadStringPiece16(StringPiece* result) {
// Read resultant length.
uint16 result_len;
if (!ReadUInt16(&result_len)) {
// OnFailure() already called.
return false;
}
return ReadStringPiece(result, result_len);
}
bool QuicDataReader::ReadBytes(void* result, size_t size) {
// Make sure that we have enough data to read.
if (!CanRead(size)) {
OnFailure();
return false;
}
// Read into result.
memcpy(result, data_ + pos_, size);
// Iterate.
pos_ += size;
return true;
}
bool QuicDataReader::ReadStringPiece(StringPiece* result, size_t size) {
// Make sure that we have enough data to read.
if (!CanRead(size)) {
OnFailure();
return false;
}
// Set result.
result->set(data_ + pos_, size);
// Iterate.
pos_ += size;
return true;
}
StringPiece QuicDataReader::PeekRemainingPayload() {
return StringPiece(data_ + pos_, len_ - pos_);
}
StringPiece QuicDataReader::ReadRemainingPayload() {
StringPiece payload = PeekRemainingPayload();
pos_ = len_;
return payload;
}
bool QuicDataReader::IsDoneReading() const {
return len_ == pos_;
}
size_t QuicDataReader::BytesRemaining() const {
return len_ - pos_;
}
bool QuicDataReader::CanRead(size_t bytes) const {
return bytes <= (len_ - pos_);
}
void QuicDataReader::OnFailure() {
// Set our iterator to the end of the buffer so that further reads fail
// immediately.
pos_ = len_;
}
} // namespace net
OLDNEW
« net/quic/quic_data_reader.h ('K') | « net/quic/quic_data_reader.h ('k') | net/quic/quic_data_writer.h » ('j') | net/quic/quic_data_writer.h » ('J')
👁 Powered by Google App Engine
This is Rietveld 408576698