forked from anqin/trident
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpc_request_parser.h
More file actions
59 lines (44 loc) · 1.62 KB
/
rpc_request_parser.h
File metadata and controls
59 lines (44 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) 2014 The Trident Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Author: Zuoyan Qin (qinzuoyan@gmail.com)
#ifndef _TRIDENT_RPC_REQUEST_PARSER_H_
#define _TRIDENT_RPC_REQUEST_PARSER_H_
#include <trident/rpc_request.h>
#include <vector>
namespace trident {
class RpcRequestParser;
typedef trident::shared_ptr<RpcRequestParser> RpcRequestParserPtr;
class RpcRequestParser
{
public:
RpcRequestParser() {}
virtual ~RpcRequestParser(){}
// Get the parser name.
virtual const char* Name() = 0;
// Reset the parser to init status.
virtual void Reset() = 0;
// Check if the parser identifies the magic string.
virtual bool CheckMagicString(const char* magic_string) = 0;
// Parse received data.
//
// @param buf buffer start address (must be a tran buf)
// @param data_size data size
// @param offset the offset between real data and buffer start address
// @param bytes_consumed bytes used by this request
//
// @retval 1 request data ready
// @retval 0 there are more bytes to be read
// @retval -1 parse request fail
virtual int Parse(const char* buf, int data_size, int offset, int* bytes_consumed) = 0;
// Get the parsed request data.
//
// Preconditions:
// * Parse() returns 1
virtual RpcRequestPtr GetRequest() = 0;
public:
// Get all registered parsers.
static void RegisteredParsers(std::vector<RpcRequestParserPtr>* parsers);
}; // class RpcRequestParser
} // namespace trident
#endif // _TRIDENT_RPC_REQUEST_PARSER_H_