diff options
Diffstat (limited to 'net/spdy/spdy_frame_builder.cc')
-rw-r--r-- | net/spdy/spdy_frame_builder.cc | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/net/spdy/spdy_frame_builder.cc b/net/spdy/spdy_frame_builder.cc index a7a291e..1ff94f2 100644 --- a/net/spdy/spdy_frame_builder.cc +++ b/net/spdy/spdy_frame_builder.cc @@ -9,10 +9,49 @@ namespace net { -SpdyFrameBuilder::SpdyFrameBuilder(size_t size) +namespace { + +// Creates a FlagsAndLength. +FlagsAndLength CreateFlagsAndLength(SpdyControlFlags flags, size_t length) { + DCHECK_EQ(0u, length & ~static_cast<size_t>(kLengthMask)); + FlagsAndLength flags_length; + flags_length.length_ = htonl(static_cast<uint32>(length)); + DCHECK_EQ(0, flags & ~kControlFlagsMask); + flags_length.flags_[0] = flags; + return flags_length; +} + +} // namespace + +SpdyFrameBuilder::SpdyFrameBuilder(SpdyControlType type, + SpdyControlFlags flags, + int spdy_version, + size_t size) + : buffer_(new char[size]), + capacity_(size), + length_(0) { + FlagsAndLength flags_length = CreateFlagsAndLength( + flags, size - SpdyFrame::kHeaderSize); + WriteUInt16(kControlFlagMask | spdy_version); + WriteUInt16(type); + WriteBytes(&flags_length, sizeof(flags_length)); +} + +SpdyFrameBuilder::SpdyFrameBuilder(SpdyStreamId stream_id, + SpdyDataFlags flags, + size_t size) : buffer_(new char[size]), capacity_(size), length_(0) { + DCHECK_EQ(0u, stream_id & ~kStreamIdMask); + WriteUInt32(stream_id); + size_t length = size - SpdyFrame::kHeaderSize; + DCHECK_EQ(0u, length & ~static_cast<size_t>(kLengthMask)); + FlagsAndLength flags_length; + flags_length.length_ = htonl(length); + DCHECK_EQ(0, flags & ~kDataFlagsMask); + flags_length.flags_[0] = flags; + WriteBytes(&flags_length, sizeof(flags_length)); } SpdyFrameBuilder::~SpdyFrameBuilder() { |