/Users/deen/code/yugabyte-db/src/yb/yql/redis/redisserver/redis_encoding.h
Line | Count | Source |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | #ifndef YB_YQL_REDIS_REDISSERVER_REDIS_ENCODING_H |
14 | | #define YB_YQL_REDIS_REDISSERVER_REDIS_ENCODING_H |
15 | | |
16 | | #include <string> |
17 | | |
18 | | #include <boost/preprocessor/seq/for_each.hpp> |
19 | | |
20 | | namespace google { |
21 | | namespace protobuf { |
22 | | template <typename Element> class RepeatedPtrField; |
23 | | } |
24 | | } |
25 | | |
26 | | namespace yb { |
27 | | |
28 | | class RefCntBuffer; |
29 | | |
30 | | namespace redisserver { |
31 | | |
32 | | extern const std::string kNilResponse; |
33 | | extern const std::string kOkResponse; |
34 | | extern const std::string kInfoResponse; |
35 | | |
36 | | // Integer: |
37 | | // Encode the given input string as a integer string (eg "123"). Integer(s) are formatted as |
38 | | // :<Integer>\r\n |
39 | | // For more info: http://redis.io/topics/protocol |
40 | | |
41 | | // SimpleString: |
42 | | // Encode the given input string as a simple string. Simple string(s) are formatted as |
43 | | // +<string>\r\n |
44 | | // For more info: http://redis.io/topics/protocol |
45 | | |
46 | | // Error: |
47 | | // Encode the given message string as an error message. Error messages(s) are formatted as |
48 | | // -<message>\r\n |
49 | | // For more info: http://redis.io/topics/protocol |
50 | | |
51 | | // BulkString: |
52 | | // Encode the given input string as a bulk string. Bulk string(s) are formatted as |
53 | | // $<length>\r\n<string data>\r\n |
54 | | // For more info: http://redis.io/topics/protocol |
55 | | |
56 | | // Array: |
57 | | // Encode the vector of encoded elementes into a multi-bulk-array. Bulk array(s) are formatted as |
58 | | // *<num-elements>\r\n<encoded data terminating in \r\n> ... <encoded data terminating in \r\n> |
59 | | // For more info: http://redis.io/topics/protocol |
60 | | |
61 | | #define REDIS_PRIMITIVES \ |
62 | | ((Integer, const std::string&)) \ |
63 | | ((Integer, int64_t)) \ |
64 | | ((SimpleString, const std::string&)) \ |
65 | | ((BulkString, const std::string&)) \ |
66 | | ((Error, const std::string&)) \ |
67 | | ((Array, const google::protobuf::RepeatedPtrField<std::string>&)) \ |
68 | | ((Array, const std::initializer_list<std::string>&)) \ |
69 | | ((Encoded, const std::string&)) \ |
70 | | ((EncodedArray, const google::protobuf::RepeatedPtrField<std::string>&)) \ |
71 | | /**/ |
72 | | |
73 | | #define DO_REDIS_PRIMITIVES_FORWARD(name, type) \ |
74 | | RefCntBuffer BOOST_PP_CAT(EncodeAs, name)(type input); \ |
75 | | size_t BOOST_PP_CAT(Serialize, name)(type input, size_t size); \ |
76 | | uint8_t* BOOST_PP_CAT(Serialize, name)(type input, uint8_t* pos); |
77 | | |
78 | | #define REDIS_PRIMITIVES_FORWARD(r, data, elem) DO_REDIS_PRIMITIVES_FORWARD elem |
79 | | |
80 | | BOOST_PP_SEQ_FOR_EACH(REDIS_PRIMITIVES_FORWARD, ~, REDIS_PRIMITIVES) |
81 | | |
82 | | template <typename Container> |
83 | 2.47k | std::string EncodeAsArrayOfEncodedElements(const Container& encoded_elements) { |
84 | 2.47k | return StrCat("*", encoded_elements.size(), "\r\n", JoinStrings(encoded_elements, "")); |
85 | 2.47k | } Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::redisserver::EncodeAsArrayOfEncodedElements<std::initializer_list<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(std::initializer_list<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > const&) std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > yb::redisserver::EncodeAsArrayOfEncodedElements<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > >(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) Line | Count | Source | 83 | 2.47k | std::string EncodeAsArrayOfEncodedElements(const Container& encoded_elements) { | 84 | 2.47k | return StrCat("*", encoded_elements.size(), "\r\n", JoinStrings(encoded_elements, "")); | 85 | 2.47k | } |
|
86 | | |
87 | | } // namespace redisserver |
88 | | } // namespace yb |
89 | | |
90 | | #endif // YB_YQL_REDIS_REDISSERVER_REDIS_ENCODING_H |