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/spdy/spdy_frame_builder.h" | 5 #include "net/spdy/spdy_frame_builder.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "net/spdy/spdy_bug_tracker.h" | 10 #include "net/spdy/spdy_bug_tracker.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // Don't check for length limits here because this may be larger than the | 58 // Don't check for length limits here because this may be larger than the |
59 // actual frame length. | 59 // actual frame length. |
60 success &= WriteUInt24(capacity_ - offset_ - kFrameHeaderSize); | 60 success &= WriteUInt24(capacity_ - offset_ - kFrameHeaderSize); |
61 success &= WriteUInt8(SerializeFrameType(type)); | 61 success &= WriteUInt8(SerializeFrameType(type)); |
62 success &= WriteUInt8(flags); | 62 success &= WriteUInt8(flags); |
63 success &= WriteUInt32(stream_id); | 63 success &= WriteUInt32(stream_id); |
64 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length_); | 64 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length_); |
65 return success; | 65 return success; |
66 } | 66 } |
67 | 67 |
| 68 bool SpdyFrameBuilder::BeginNewFrame(const SpdyFramer& framer, |
| 69 SpdyFrameType type, |
| 70 uint8_t flags, |
| 71 SpdyStreamId stream_id, |
| 72 size_t length) { |
| 73 DCHECK(IsValidFrameType(SerializeFrameType(type))); |
| 74 DCHECK_EQ(0u, stream_id & ~kStreamIdMask); |
| 75 bool success = true; |
| 76 SPDY_BUG_IF(framer.GetFrameMaximumSize() < length_) |
| 77 << "Frame length " << length_ |
| 78 << " is longer than the maximum allowed length."; |
| 79 |
| 80 offset_ += length_; |
| 81 length_ = 0; |
| 82 |
| 83 success &= WriteUInt24(length); |
| 84 success &= WriteUInt8(SerializeFrameType(type)); |
| 85 success &= WriteUInt8(flags); |
| 86 success &= WriteUInt32(stream_id); |
| 87 DCHECK_EQ(framer.GetDataFrameMinimumSize(), length_); |
| 88 return success; |
| 89 } |
| 90 |
68 bool SpdyFrameBuilder::WriteStringPiece16(const base::StringPiece& value) { | 91 bool SpdyFrameBuilder::WriteStringPiece16(const base::StringPiece& value) { |
69 if (value.size() > 0xffff) { | 92 if (value.size() > 0xffff) { |
70 DCHECK(false) << "Tried to write string with length > 16bit."; | 93 DCHECK(false) << "Tried to write string with length > 16bit."; |
71 return false; | 94 return false; |
72 } | 95 } |
73 | 96 |
74 if (!WriteUInt16(static_cast<uint16_t>(value.size()))) { | 97 if (!WriteUInt16(static_cast<uint16_t>(value.size()))) { |
75 return false; | 98 return false; |
76 } | 99 } |
77 | 100 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 155 |
133 if (offset_ + length_ + length > capacity_) { | 156 if (offset_ + length_ + length > capacity_) { |
134 DCHECK(false); | 157 DCHECK(false); |
135 return false; | 158 return false; |
136 } | 159 } |
137 | 160 |
138 return true; | 161 return true; |
139 } | 162 } |
140 | 163 |
141 } // namespace net | 164 } // namespace net |
OLD | NEW |