| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_SERVER_WEB_SOCKET_FRAME_H_ |
| 6 #define NET_SERVER_WEB_SOCKET_FRAME_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 |
| 11 #include <vector> |
| 12 |
| 13 namespace net { |
| 14 |
| 15 class WebSocketFrame { |
| 16 static const unsigned char kFinalBit; |
| 17 static const unsigned char kReserved1Bit; |
| 18 static const unsigned char kReserved2Bit; |
| 19 static const unsigned char kReserved3Bit; |
| 20 static const unsigned char kOpCodeMask; |
| 21 static const unsigned char kMaskBit; |
| 22 static const unsigned char kPayloadLengthMask; |
| 23 |
| 24 static const size_t kMaxSingleBytePayloadLength; |
| 25 static const size_t kTwoBytePayloadLengthField; |
| 26 static const size_t kEightBytePayloadLengthField; |
| 27 static const size_t kMaskingKeyWidthInBytes; |
| 28 |
| 29 public: |
| 30 // Hybi-10 opcodes. |
| 31 typedef unsigned int OpCode; |
| 32 static const OpCode kOpCodeContinuation; |
| 33 static const OpCode kOpCodeText; |
| 34 static const OpCode kOpCodeBinary; |
| 35 static const OpCode kOpCodeClose; |
| 36 static const OpCode kOpCodePing; |
| 37 static const OpCode kOpCodePong; |
| 38 |
| 39 enum ParseResult { |
| 40 FrameOK, |
| 41 FrameIncomplete, |
| 42 FrameError |
| 43 }; |
| 44 |
| 45 OpCode op_code_; |
| 46 bool final_; |
| 47 bool reserved1_; |
| 48 bool reserved2_; |
| 49 bool reserved3_; |
| 50 bool masked_; |
| 51 const char* payload_; |
| 52 size_t payload_length_; |
| 53 const char* frame_end_; |
| 54 |
| 55 bool isNonControlOpCode() const { |
| 56 return op_code_ == kOpCodeContinuation || |
| 57 op_code_ == kOpCodeText || |
| 58 op_code_ == kOpCodeBinary; |
| 59 } |
| 60 bool isControlOpCode() const { |
| 61 return op_code_ == kOpCodeClose || |
| 62 op_code_ == kOpCodePing || |
| 63 op_code_ == kOpCodePong; |
| 64 } |
| 65 bool isReservedOpCode() const { |
| 66 return !isNonControlOpCode() && !isControlOpCode(); |
| 67 } |
| 68 |
| 69 ParseResult DecodeFrame(const char* data, size_t data_length); |
| 70 std::vector<char> EncodeFrame(OpCode op_code, |
| 71 const char* data, |
| 72 size_t data_length); |
| 73 }; |
| 74 |
| 75 } // namespace net |
| 76 |
| 77 #endif // NET_SERVER_WEB_SOCKET_FRAME_H_ |
| OLD | NEW |