/Users/deen/code/yugabyte-db/src/yb/common/key_encoder.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | |
33 | | #ifndef YB_COMMON_KEY_ENCODER_H |
34 | | #define YB_COMMON_KEY_ENCODER_H |
35 | | |
36 | | #include <arpa/inet.h> |
37 | | |
38 | | #ifndef __aarch64__ |
39 | | #include <nmmintrin.h> |
40 | | #endif |
41 | | |
42 | | #include <string.h> |
43 | | |
44 | | #include <climits> |
45 | | |
46 | | #include "yb/common/types.h" |
47 | | #include "yb/gutil/endian.h" |
48 | | #include "yb/gutil/macros.h" |
49 | | #include "yb/gutil/mathlimits.h" |
50 | | #include "yb/gutil/strings/memutil.h" |
51 | | #include "yb/gutil/type_traits.h" |
52 | | #include "yb/util/memory/arena.h" |
53 | | #include "yb/util/status.h" |
54 | | |
55 | | // The SSE-based encoding is not yet working. Don't define this! |
56 | | #undef KEY_ENCODER_USE_SSE |
57 | | |
58 | | namespace yb { |
59 | | |
60 | | template<DataType Type, typename Buffer, class Enable = void> |
61 | | struct KeyEncoderTraits { |
62 | | }; |
63 | | |
64 | | // This complicated-looking template magic defines a specialization of the |
65 | | // KeyEncoderTraits struct for any integral type. This avoids a bunch of |
66 | | // code duplication for all of our different size/signed-ness variants. |
67 | | template<DataType Type, typename Buffer> |
68 | | struct KeyEncoderTraits<Type, |
69 | | Buffer, |
70 | | typename base::enable_if< |
71 | | base::is_integral< |
72 | | typename DataTypeTraits<Type>::cpp_type |
73 | | >::value |
74 | | >::type |
75 | | > { |
76 | | static const DataType key_type = Type; |
77 | | |
78 | | private: |
79 | | typedef typename DataTypeTraits<Type>::cpp_type cpp_type; |
80 | | typedef typename MathLimits<cpp_type>::UnsignedType unsigned_cpp_type; |
81 | | |
82 | 0 | static unsigned_cpp_type SwapEndian(unsigned_cpp_type x) { |
83 | 0 | switch (sizeof(x)) { |
84 | 0 | case 1: return x; |
85 | 0 | case 2: return BigEndian::FromHost16(x); |
86 | 0 | case 4: return BigEndian::FromHost32(*reinterpret_cast<uint32*>(&x)); |
87 | 0 | case 8: return BigEndian::FromHost64(*reinterpret_cast<uint64*>(&x)); |
88 | 0 | default: LOG(FATAL) << "bad type: " << x; |
89 | 0 | } |
90 | 0 | return 0; |
91 | 0 | } Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)100, yb::faststring, void>::SwapEndian(unsigned char) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)1, yb::faststring, void>::SwapEndian(unsigned char) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)101, yb::faststring, void>::SwapEndian(unsigned short) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)2, yb::faststring, void>::SwapEndian(unsigned short) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)102, yb::faststring, void>::SwapEndian(unsigned int) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)3, yb::faststring, void>::SwapEndian(unsigned int) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)103, yb::faststring, void>::SwapEndian(unsigned long long) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)4, yb::faststring, void>::SwapEndian(unsigned long long) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)7, yb::faststring, void>::SwapEndian(float) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)8, yb::faststring, void>::SwapEndian(double) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)100, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::SwapEndian(unsigned char) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)1, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::SwapEndian(unsigned char) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)101, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::SwapEndian(unsigned short) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)2, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::SwapEndian(unsigned short) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)102, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::SwapEndian(unsigned int) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)3, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::SwapEndian(unsigned int) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)103, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::SwapEndian(unsigned long long) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)4, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::SwapEndian(unsigned long long) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)7, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::SwapEndian(float) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)8, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::SwapEndian(double) |
92 | | |
93 | | public: |
94 | | static void Encode(cpp_type key, Buffer* dst) { |
95 | | Encode(&key, dst); |
96 | | } |
97 | | |
98 | 0 | static void Encode(const void* key_ptr, Buffer* dst) { |
99 | 0 | unsigned_cpp_type key_unsigned; |
100 | 0 | memcpy(&key_unsigned, key_ptr, sizeof(key_unsigned)); |
101 | | // To encode signed integers, swap the MSB. |
102 | 0 | if (MathLimits<cpp_type>::kIsSigned) { |
103 | 0 | switch (sizeof(key_unsigned)) { |
104 | | // Since integral types now include floats and doubles, we need to always cast to |
105 | | // the appropriate intx_t before doing any bitwise operations. Cases for 1 and 2 |
106 | | // are to make the compiler happy. |
107 | 0 | case 1: { |
108 | 0 | int8_t& key = reinterpret_cast<int8_t&> (key_unsigned); |
109 | 0 | key ^= 1UL << (sizeof(key_unsigned) * CHAR_BIT - 1); |
110 | 0 | break; |
111 | 0 | } |
112 | 0 | case 2: { |
113 | 0 | int16_t& key = reinterpret_cast<int16_t&> (key_unsigned); |
114 | 0 | key ^= 1UL << (sizeof(key_unsigned) * CHAR_BIT - 1); |
115 | 0 | break; |
116 | 0 | } |
117 | 0 | case 4: { |
118 | 0 | int32_t& key = reinterpret_cast<int32_t&> (key_unsigned); |
119 | 0 | key ^= 1UL << (sizeof(key_unsigned) * CHAR_BIT - 1); |
120 | 0 | break; |
121 | 0 | } |
122 | 0 | case 8: { |
123 | 0 | int64_t& key = reinterpret_cast<int64_t&> (key_unsigned); |
124 | 0 | key ^= 1UL << (sizeof(key_unsigned) * CHAR_BIT - 1); |
125 | 0 | break; |
126 | 0 | } |
127 | 0 | default: { |
128 | 0 | LOG(FATAL) << "bad type " << key_unsigned; |
129 | 0 | } |
130 | 0 | } |
131 | 0 | } |
132 | 0 | key_unsigned = SwapEndian(key_unsigned); |
133 | 0 | dst->append(reinterpret_cast<const char*>(&key_unsigned), sizeof(key_unsigned)); |
134 | 0 | } Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)100, yb::faststring, void>::Encode(void const*, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)1, yb::faststring, void>::Encode(void const*, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)101, yb::faststring, void>::Encode(void const*, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)2, yb::faststring, void>::Encode(void const*, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)102, yb::faststring, void>::Encode(void const*, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)3, yb::faststring, void>::Encode(void const*, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)103, yb::faststring, void>::Encode(void const*, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)4, yb::faststring, void>::Encode(void const*, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)7, yb::faststring, void>::Encode(void const*, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)8, yb::faststring, void>::Encode(void const*, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)100, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::Encode(void const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)1, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::Encode(void const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)101, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::Encode(void const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)2, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::Encode(void const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)102, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::Encode(void const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)3, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::Encode(void const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)103, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::Encode(void const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)4, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::Encode(void const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)7, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::Encode(void const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)8, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::Encode(void const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) |
135 | | |
136 | 0 | static void EncodeWithSeparators(const void* key, bool is_last, Buffer* dst) { |
137 | 0 | Encode(key, dst); |
138 | 0 | } Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)100, yb::faststring, void>::EncodeWithSeparators(void const*, bool, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)1, yb::faststring, void>::EncodeWithSeparators(void const*, bool, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)101, yb::faststring, void>::EncodeWithSeparators(void const*, bool, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)2, yb::faststring, void>::EncodeWithSeparators(void const*, bool, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)102, yb::faststring, void>::EncodeWithSeparators(void const*, bool, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)3, yb::faststring, void>::EncodeWithSeparators(void const*, bool, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)103, yb::faststring, void>::EncodeWithSeparators(void const*, bool, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)4, yb::faststring, void>::EncodeWithSeparators(void const*, bool, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)7, yb::faststring, void>::EncodeWithSeparators(void const*, bool, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)8, yb::faststring, void>::EncodeWithSeparators(void const*, bool, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)100, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeWithSeparators(void const*, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)1, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeWithSeparators(void const*, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)101, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeWithSeparators(void const*, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)2, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeWithSeparators(void const*, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)102, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeWithSeparators(void const*, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)3, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeWithSeparators(void const*, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)103, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeWithSeparators(void const*, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)4, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeWithSeparators(void const*, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)7, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeWithSeparators(void const*, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)8, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeWithSeparators(void const*, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) |
139 | | |
140 | | static CHECKED_STATUS DecodeKeyPortion(Slice* encoded_key, |
141 | | bool is_last, |
142 | | Arena* arena, |
143 | 0 | uint8_t* cell_ptr) { |
144 | 0 | if (PREDICT_FALSE(encoded_key->size() < sizeof(cpp_type))) { |
145 | 0 | return STATUS(InvalidArgument, "key too short", encoded_key->ToDebugString()); |
146 | 0 | } |
147 | | |
148 | 0 | unsigned_cpp_type val; |
149 | 0 | memcpy(&val, encoded_key->data(), sizeof(cpp_type)); |
150 | 0 | val = SwapEndian(val); |
151 | 0 | if (MathLimits<cpp_type>::kIsSigned) { |
152 | 0 | switch (sizeof(val)) { |
153 | 0 | case 1: { |
154 | 0 | int8_t& key = reinterpret_cast<int8_t&> (val); |
155 | 0 | key ^= 1UL << (sizeof(key) * CHAR_BIT - 1); |
156 | 0 | break; |
157 | 0 | } |
158 | 0 | case 2: { |
159 | 0 | int16_t& key = reinterpret_cast<int16_t&> (val); |
160 | 0 | key ^= 1UL << (sizeof(key) * CHAR_BIT - 1); |
161 | 0 | break; |
162 | 0 | } |
163 | 0 | case 4: { |
164 | 0 | int32_t& key = reinterpret_cast<int32_t&> (val); |
165 | 0 | key ^= 1UL << (sizeof(key) * CHAR_BIT - 1); |
166 | 0 | break; |
167 | 0 | } |
168 | 0 | case 8: { |
169 | 0 | int64_t& key = reinterpret_cast<int64_t&> (val); |
170 | 0 | key ^= 1UL << (sizeof(key) * CHAR_BIT - 1); |
171 | 0 | break; |
172 | 0 | } |
173 | 0 | default: { |
174 | 0 | LOG(FATAL) << "bad type " << val; |
175 | 0 | } |
176 | 0 | } |
177 | 0 | } |
178 | 0 | memcpy(cell_ptr, &val, sizeof(val)); |
179 | 0 | encoded_key->remove_prefix(sizeof(cpp_type)); |
180 | 0 | return Status::OK(); |
181 | 0 | } Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)100, yb::faststring, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)1, yb::faststring, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)101, yb::faststring, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)2, yb::faststring, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)102, yb::faststring, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)3, yb::faststring, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)103, yb::faststring, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)4, yb::faststring, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)7, yb::faststring, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)8, yb::faststring, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)100, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)1, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)101, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)2, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)102, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)3, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)103, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)4, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)7, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)8, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) |
182 | | }; |
183 | | |
184 | | template<typename Buffer> |
185 | | struct KeyEncoderTraits<BINARY, Buffer> { |
186 | | |
187 | | static const DataType key_type = BINARY; |
188 | | |
189 | 0 | static void Encode(const void* key, Buffer* dst) { |
190 | 0 | Encode(*reinterpret_cast<const Slice*>(key), dst); |
191 | 0 | } Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)9, yb::faststring, void>::Encode(void const*, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)9, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::Encode(void const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) |
192 | | |
193 | | // simple slice encoding that just adds to the buffer |
194 | 0 | inline static void Encode(const Slice& s, Buffer* dst) { |
195 | 0 | dst->append(reinterpret_cast<const char*>(s.data()), s.size()); |
196 | 0 | } Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)9, yb::faststring, void>::Encode(yb::Slice const&, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)9, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::Encode(yb::Slice const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) |
197 | 0 | static void EncodeWithSeparators(const void* key, bool is_last, Buffer* dst) { |
198 | 0 | EncodeWithSeparators(*reinterpret_cast<const Slice*>(key), is_last, dst); |
199 | 0 | } Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)9, yb::faststring, void>::EncodeWithSeparators(void const*, bool, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)9, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeWithSeparators(void const*, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) |
200 | | |
201 | | // slice encoding that uses a separator to retain lexicographic |
202 | | // comparability. |
203 | | // |
204 | | // This implementation is heavily optimized for the case where the input |
205 | | // slice has no '\0' bytes. We assume this is common in most user-generated |
206 | | // compound keys. |
207 | 0 | inline static void EncodeWithSeparators(const Slice& s, bool is_last, Buffer* dst) { |
208 | 0 | if (is_last) { |
209 | 0 | dst->append(reinterpret_cast<const char*>(s.data()), s.size()); |
210 | 0 | } else { |
211 | | // If we're a middle component of a composite key, we need to add a \x00 |
212 | | // at the end in order to separate this component from the next one. However, |
213 | | // if we just did that, we'd have issues where a key that actually has |
214 | | // \x00 in it would compare wrong, so we have to instead add \x00\x00, and |
215 | | // encode \x00 as \x00\x01. |
216 | 0 | auto old_size = dst->size(); |
217 | 0 | dst->resize(old_size + s.size() * 2 + 2); |
218 | |
|
219 | 0 | const uint8_t* srcp = s.data(); |
220 | 0 | uint8_t* dstp = reinterpret_cast<uint8_t*>(&(*dst)[old_size]); |
221 | 0 | auto len = s.size(); |
222 | 0 | auto rem = len; |
223 | |
|
224 | 0 | while (rem >= 16) { |
225 | 0 | if (!SSEEncodeChunk<16>(&srcp, &dstp)) { |
226 | 0 | goto slow_path; |
227 | 0 | } |
228 | 0 | rem -= 16; |
229 | 0 | } |
230 | 0 | while (rem >= 8) { |
231 | 0 | if (!SSEEncodeChunk<8>(&srcp, &dstp)) { |
232 | 0 | goto slow_path; |
233 | 0 | } |
234 | 0 | rem -= 8; |
235 | 0 | } |
236 | | // Roll back to operate in 8 bytes at a time. |
237 | 0 | if (len > 8 && rem > 0) { |
238 | 0 | dstp -= 8 - rem; |
239 | 0 | srcp -= 8 - rem; |
240 | 0 | if (!SSEEncodeChunk<8>(&srcp, &dstp)) { |
241 | | // TODO: optimize for the case where the input slice has '\0' |
242 | | // bytes. (e.g. move the pointer to the first zero byte.) |
243 | 0 | dstp += 8 - rem; |
244 | 0 | srcp += 8 - rem; |
245 | 0 | goto slow_path; |
246 | 0 | } |
247 | 0 | rem = 0; |
248 | 0 | goto done; |
249 | 0 | } |
250 | | |
251 | 0 | slow_path: |
252 | 0 | EncodeChunkLoop(&srcp, &dstp, rem); |
253 | |
|
254 | 0 | done: |
255 | 0 | *dstp++ = 0; |
256 | 0 | *dstp++ = 0; |
257 | 0 | dst->resize(dstp - reinterpret_cast<uint8_t*>(&(*dst)[0])); |
258 | 0 | } |
259 | 0 | } Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)9, yb::faststring, void>::EncodeWithSeparators(yb::Slice const&, bool, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)9, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeWithSeparators(yb::Slice const&, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) |
260 | | |
261 | | static CHECKED_STATUS DecodeKeyPortion(Slice* encoded_key, |
262 | | bool is_last, |
263 | | Arena* arena, |
264 | 0 | uint8_t* cell_ptr) { |
265 | 0 | if (is_last) { |
266 | 0 | Slice* dst_slice = reinterpret_cast<Slice *>(cell_ptr); |
267 | 0 | if (PREDICT_FALSE(!arena->RelocateSlice(*encoded_key, dst_slice))) { |
268 | 0 | return STATUS(RuntimeError, "OOM"); |
269 | 0 | } |
270 | 0 | encoded_key->remove_prefix(encoded_key->size()); |
271 | 0 | return Status::OK(); |
272 | 0 | } |
273 | | |
274 | 0 | uint8_t* separator = static_cast<uint8_t*>(memmem(encoded_key->data(), encoded_key->size(), |
275 | 0 | "\0\0", 2)); |
276 | 0 | if (PREDICT_FALSE(separator == NULL)) { |
277 | 0 | return STATUS(InvalidArgument, "Missing separator after composite key string component", |
278 | 0 | encoded_key->ToDebugString()); |
279 | 0 | } |
280 | | |
281 | 0 | uint8_t* src = encoded_key->mutable_data(); |
282 | 0 | auto max_len = separator - src; |
283 | 0 | uint8_t* dst_start = static_cast<uint8_t*>(arena->AllocateBytes(max_len)); |
284 | 0 | uint8_t* dst = dst_start; |
285 | |
|
286 | 0 | for (int i = 0; i < max_len; i++) { |
287 | 0 | if (i >= 1 && src[i - 1] == '\0' && src[i] == '\1') { |
288 | 0 | continue; |
289 | 0 | } |
290 | 0 | *dst++ = src[i]; |
291 | 0 | } |
292 | |
|
293 | 0 | auto real_len = dst - dst_start; |
294 | 0 | Slice slice(dst_start, real_len); |
295 | 0 | memcpy(cell_ptr, &slice, sizeof(Slice)); |
296 | 0 | encoded_key->remove_prefix(max_len + 2); |
297 | 0 | return Status::OK(); |
298 | 0 | } Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)9, yb::faststring, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)9, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) |
299 | | |
300 | | private: |
301 | | // Encode a chunk of 'len' bytes from '*srcp' into '*dstp', incrementing |
302 | | // the pointers upon return. |
303 | | // |
304 | | // This uses SSE2 operations to operate in 8 or 16 bytes at a time, fast-pathing |
305 | | // the case where there are no '\x00' bytes in the source. |
306 | | // |
307 | | // Returns true if the chunk was successfully processed, false if there was one |
308 | | // or more '\0' bytes requiring the slow path. |
309 | | // |
310 | | // REQUIRES: len == 16 or 8 |
311 | | template<int LEN> |
312 | 0 | static bool SSEEncodeChunk(const uint8_t** srcp, uint8_t** dstp) { |
313 | 0 | #ifdef __aarch64__ |
314 | 0 | return false; |
315 | | #else |
316 | | COMPILE_ASSERT(LEN == 16 || LEN == 8, invalid_length); |
317 | | __m128i data; |
318 | | if (LEN == 16) { |
319 | | // Load 16 bytes (unaligned) into the XMM register. |
320 | | data = _mm_loadu_si128(reinterpret_cast<const __m128i*>(*srcp)); |
321 | | } else if (LEN == 8) { |
322 | | // Load 8 bytes (unaligned) into the XMM register |
323 | | data = reinterpret_cast<__m128i>(_mm_load_sd(reinterpret_cast<const double*>(*srcp))); |
324 | | } |
325 | | // Compare each byte of the input with '\0'. This results in a vector |
326 | | // where each byte is either \x00 or \xFF, depending on whether the |
327 | | // input had a '\x00' in the corresponding position. |
328 | | __m128i zeros = reinterpret_cast<__m128i>(_mm_setzero_pd()); |
329 | | __m128i zero_bytes = _mm_cmpeq_epi8(data, zeros); |
330 | | |
331 | | // Check whether the resulting vector is all-zero. |
332 | | bool all_zeros; |
333 | | if (LEN == 16) { |
334 | | all_zeros = _mm_testz_si128(zero_bytes, zero_bytes); |
335 | | } else { // LEN == 8 |
336 | | all_zeros = _mm_cvtsi128_si64(zero_bytes) == 0; |
337 | | } |
338 | | |
339 | | // If it's all zero, we can just store the entire chunk. |
340 | | if (PREDICT_FALSE(!all_zeros)) { |
341 | | return false; |
342 | | } |
343 | | |
344 | | if (LEN == 16) { |
345 | | _mm_storeu_si128(reinterpret_cast<__m128i*>(*dstp), data); |
346 | | } else { |
347 | | _mm_storel_epi64(reinterpret_cast<__m128i*>(*dstp), data); // movq m64, xmm |
348 | | } |
349 | | *dstp += LEN; |
350 | | *srcp += LEN; |
351 | | return true; |
352 | | #endif |
353 | 0 | } Unexecuted instantiation: bool yb::KeyEncoderTraits<(yb::DataType)9, yb::faststring, void>::SSEEncodeChunk<16>(unsigned char const**, unsigned char**) Unexecuted instantiation: bool yb::KeyEncoderTraits<(yb::DataType)9, yb::faststring, void>::SSEEncodeChunk<8>(unsigned char const**, unsigned char**) Unexecuted instantiation: bool yb::KeyEncoderTraits<(yb::DataType)9, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::SSEEncodeChunk<16>(unsigned char const**, unsigned char**) Unexecuted instantiation: bool yb::KeyEncoderTraits<(yb::DataType)9, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::SSEEncodeChunk<8>(unsigned char const**, unsigned char**) |
354 | | |
355 | | // Non-SSE loop which encodes 'len' bytes from 'srcp' into 'dst'. |
356 | 0 | static void EncodeChunkLoop(const uint8_t** srcp, uint8_t** dstp, size_t len) { |
357 | 0 | while (len > 0) { |
358 | 0 | --len; |
359 | 0 | if (PREDICT_FALSE(**srcp == '\0')) { |
360 | 0 | *(*dstp)++ = 0; |
361 | 0 | *(*dstp)++ = 1; |
362 | 0 | } else { |
363 | 0 | *(*dstp)++ = **srcp; |
364 | 0 | } |
365 | 0 | (*srcp)++; |
366 | 0 | } |
367 | 0 | } Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)9, yb::faststring, void>::EncodeChunkLoop(unsigned char const**, unsigned char**, unsigned long) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)9, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeChunkLoop(unsigned char const**, unsigned char**, unsigned long) |
368 | | }; |
369 | | |
370 | | template<typename Buffer> |
371 | | struct KeyEncoderTraits<BOOL, Buffer> { |
372 | | |
373 | | static const DataType key_type = BOOL; |
374 | | |
375 | 0 | static void Encode(const void* key, Buffer* dst) { |
376 | 0 | dst->push_back(*reinterpret_cast<const bool*>(key) ? 1 : 0); |
377 | 0 | } Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)6, yb::faststring, void>::Encode(void const*, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)6, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::Encode(void const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) |
378 | | |
379 | 0 | static void EncodeWithSeparators(const void* key, bool is_last, Buffer* dst) { |
380 | 0 | Encode(key, dst); |
381 | 0 | } Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)6, yb::faststring, void>::EncodeWithSeparators(void const*, bool, yb::faststring*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)6, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::EncodeWithSeparators(void const*, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*) |
382 | | |
383 | | static CHECKED_STATUS DecodeKeyPortion(Slice* encoded_key, |
384 | | bool is_last, |
385 | | Arena* arena, |
386 | 0 | uint8_t* cell_ptr) { |
387 | 0 | if (PREDICT_FALSE(encoded_key->size() < sizeof(char))) { |
388 | 0 | return STATUS(InvalidArgument, "key too short", encoded_key->ToDebugString()); |
389 | 0 | } |
390 | | |
391 | 0 | *cell_ptr = *encoded_key->data(); |
392 | 0 | encoded_key->remove_prefix(sizeof(char)); |
393 | 0 | return Status::OK(); |
394 | 0 | } Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)6, yb::faststring, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) Unexecuted instantiation: yb::KeyEncoderTraits<(yb::DataType)6, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::DecodeKeyPortion(yb::Slice*, bool, yb::internal::ArenaBase<yb::internal::ArenaTraits>*, unsigned char*) |
395 | | }; |
396 | | |
397 | | // Forward declaration is necessary for friend declaration in KeyEncoder. |
398 | | template<typename Buffer> |
399 | | class EncoderResolver; |
400 | | |
401 | | // The runtime version of the key encoder |
402 | | template <typename Buffer> |
403 | | class KeyEncoder { |
404 | | public: |
405 | | template<typename EncoderTraitsClass> |
406 | | explicit KeyEncoder(EncoderTraitsClass t) |
407 | | : encode_func_(EncoderTraitsClass::Encode), |
408 | | encode_with_separators_func_(EncoderTraitsClass::EncodeWithSeparators), |
409 | 123k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { |
410 | 123k | } yb::KeyEncoder<yb::faststring>::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)6, yb::faststring, void> >(yb::KeyEncoderTraits<(yb::DataType)6, yb::faststring, void>) Line | Count | Source | 409 | 2.30k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 2.30k | } |
yb::KeyEncoder<yb::faststring>::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)100, yb::faststring, void> >(yb::KeyEncoderTraits<(yb::DataType)100, yb::faststring, void>) Line | Count | Source | 409 | 2.30k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 2.30k | } |
yb::KeyEncoder<yb::faststring>::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)1, yb::faststring, void> >(yb::KeyEncoderTraits<(yb::DataType)1, yb::faststring, void>) Line | Count | Source | 409 | 2.30k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 2.30k | } |
yb::KeyEncoder<yb::faststring>::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)101, yb::faststring, void> >(yb::KeyEncoderTraits<(yb::DataType)101, yb::faststring, void>) Line | Count | Source | 409 | 2.30k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 2.30k | } |
yb::KeyEncoder<yb::faststring>::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)2, yb::faststring, void> >(yb::KeyEncoderTraits<(yb::DataType)2, yb::faststring, void>) Line | Count | Source | 409 | 2.30k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 2.30k | } |
yb::KeyEncoder<yb::faststring>::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)102, yb::faststring, void> >(yb::KeyEncoderTraits<(yb::DataType)102, yb::faststring, void>) Line | Count | Source | 409 | 2.30k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 2.30k | } |
yb::KeyEncoder<yb::faststring>::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)3, yb::faststring, void> >(yb::KeyEncoderTraits<(yb::DataType)3, yb::faststring, void>) Line | Count | Source | 409 | 2.30k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 2.30k | } |
yb::KeyEncoder<yb::faststring>::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)103, yb::faststring, void> >(yb::KeyEncoderTraits<(yb::DataType)103, yb::faststring, void>) Line | Count | Source | 409 | 2.30k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 2.30k | } |
yb::KeyEncoder<yb::faststring>::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)4, yb::faststring, void> >(yb::KeyEncoderTraits<(yb::DataType)4, yb::faststring, void>) Line | Count | Source | 409 | 2.30k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 2.30k | } |
yb::KeyEncoder<yb::faststring>::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)9, yb::faststring, void> >(yb::KeyEncoderTraits<(yb::DataType)9, yb::faststring, void>) Line | Count | Source | 409 | 2.30k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 2.30k | } |
yb::KeyEncoder<yb::faststring>::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)7, yb::faststring, void> >(yb::KeyEncoderTraits<(yb::DataType)7, yb::faststring, void>) Line | Count | Source | 409 | 2.30k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 2.30k | } |
yb::KeyEncoder<yb::faststring>::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)8, yb::faststring, void> >(yb::KeyEncoderTraits<(yb::DataType)8, yb::faststring, void>) Line | Count | Source | 409 | 2.30k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 2.30k | } |
yb::KeyEncoder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)6, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void> >(yb::KeyEncoderTraits<(yb::DataType)6, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>) Line | Count | Source | 409 | 8.01k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 8.01k | } |
yb::KeyEncoder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)100, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void> >(yb::KeyEncoderTraits<(yb::DataType)100, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>) Line | Count | Source | 409 | 8.01k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 8.01k | } |
yb::KeyEncoder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)1, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void> >(yb::KeyEncoderTraits<(yb::DataType)1, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>) Line | Count | Source | 409 | 8.01k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 8.01k | } |
yb::KeyEncoder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)101, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void> >(yb::KeyEncoderTraits<(yb::DataType)101, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>) Line | Count | Source | 409 | 8.01k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 8.01k | } |
yb::KeyEncoder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)2, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void> >(yb::KeyEncoderTraits<(yb::DataType)2, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>) Line | Count | Source | 409 | 8.01k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 8.01k | } |
yb::KeyEncoder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)102, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void> >(yb::KeyEncoderTraits<(yb::DataType)102, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>) Line | Count | Source | 409 | 8.01k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 8.01k | } |
yb::KeyEncoder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)3, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void> >(yb::KeyEncoderTraits<(yb::DataType)3, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>) Line | Count | Source | 409 | 8.01k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 8.01k | } |
yb::KeyEncoder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)103, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void> >(yb::KeyEncoderTraits<(yb::DataType)103, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>) Line | Count | Source | 409 | 8.01k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 8.01k | } |
yb::KeyEncoder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)4, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void> >(yb::KeyEncoderTraits<(yb::DataType)4, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>) Line | Count | Source | 409 | 8.01k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 8.01k | } |
yb::KeyEncoder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)9, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void> >(yb::KeyEncoderTraits<(yb::DataType)9, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>) Line | Count | Source | 409 | 8.01k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 8.01k | } |
yb::KeyEncoder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)7, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void> >(yb::KeyEncoderTraits<(yb::DataType)7, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>) Line | Count | Source | 409 | 8.01k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 8.01k | } |
yb::KeyEncoder<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::KeyEncoder<yb::KeyEncoderTraits<(yb::DataType)8, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void> >(yb::KeyEncoderTraits<(yb::DataType)8, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>) Line | Count | Source | 409 | 8.01k | decode_key_portion_func_(EncoderTraitsClass::DecodeKeyPortion) { | 410 | 8.01k | } |
|
411 | | |
412 | | // Encodes the provided key to the provided buffer |
413 | 0 | void Encode(const void* key, Buffer* dst) const { |
414 | 0 | encode_func_(key, dst); |
415 | 0 | } |
416 | | |
417 | | // Special encoding for composite keys. |
418 | 0 | void Encode(const void* key, bool is_last, Buffer* dst) const { |
419 | 0 | encode_with_separators_func_(key, is_last, dst); |
420 | 0 | } |
421 | | |
422 | | void ResetAndEncode(const void* key, Buffer* dst) const { |
423 | | dst->clear(); |
424 | | Encode(key, dst); |
425 | | } |
426 | | |
427 | | // Decode the next component out of the composite key pointed to by '*encoded_key' |
428 | | // into *cell_ptr. |
429 | | // After decoding encoded_key is advanced forward such that it contains the remainder |
430 | | // of the composite key. |
431 | | // 'is_last' should be true when we expect that this component is the last (or only) component |
432 | | // of the composite key. |
433 | | // Any indirect data (eg strings) are allocated out of 'arena'. |
434 | | CHECKED_STATUS Decode(Slice* encoded_key, |
435 | | bool is_last, |
436 | | Arena* arena, |
437 | 0 | uint8_t* cell_ptr) const { |
438 | 0 | return decode_key_portion_func_(encoded_key, is_last, arena, cell_ptr); |
439 | 0 | } |
440 | | |
441 | | private: |
442 | | typedef void (*EncodeFunc)(const void* key, Buffer* dst); |
443 | | const EncodeFunc encode_func_; |
444 | | typedef void (*EncodeWithSeparatorsFunc)(const void* key, bool is_last, Buffer* dst); |
445 | | const EncodeWithSeparatorsFunc encode_with_separators_func_; |
446 | | |
447 | | typedef Status (*DecodeKeyPortionFunc)(Slice* enc_key, bool is_last, |
448 | | Arena* arena, uint8_t* cell_ptr); |
449 | | const DecodeKeyPortionFunc decode_key_portion_func_; |
450 | | |
451 | | private: |
452 | | DISALLOW_COPY_AND_ASSIGN(KeyEncoder); |
453 | | }; |
454 | | |
455 | | template <typename Buffer> |
456 | | extern const KeyEncoder<Buffer>& GetKeyEncoder(const TypeInfo* typeinfo); |
457 | | |
458 | | extern bool IsTypeAllowableInKey(const TypeInfo* typeinfo); |
459 | | |
460 | | } // namespace yb |
461 | | |
462 | | #endif // YB_COMMON_KEY_ENCODER_H |