Skip to content

Commit de1f538

Browse files
burivuhvicpopov
authored andcommitted
change compressed param to enum
1 parent dc5362e commit de1f538

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

snippets/c_api/iterate_events.cc

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
const size_t kCompressedUidLength = 32;
4040
const size_t kUidLength = 38;
4141

42+
43+
enum UidFormat
44+
{
45+
RAW, PYLONG
46+
};
47+
4248
// Public struct used in Python.
4349
struct UserInfo
4450
{
@@ -95,13 +101,23 @@ struct UserInfo
95101

96102

97103
// Throw away useless characters and convert to char array (fixed size - no null-termination needed).
98-
void setUid(std::string const & uid, bool compress) noexcept(false)
104+
void setUid(std::string const & uid, uint8_t format) noexcept(false)
99105
{
100-
std::string cUid = uid;
101-
if(compress)
106+
std::string cUid;
107+
switch (format)
102108
{
103-
cUid = this->compressUid(uid);
104-
}
109+
case RAW:
110+
{
111+
cUid = uid;
112+
break;
113+
}
114+
case PYLONG:
115+
{
116+
cUid = this->compressUid(uid);
117+
break;
118+
}
119+
};
120+
105121
std::memcpy(this->raw_uid, cUid.c_str(), sizeof(char) * cUid.size());
106122
}
107123

@@ -155,12 +171,12 @@ NOTE: We need a C interface, so prepare yourself for C-style structures in the p
155171
this function (called from a Python code with a ctypes wrapper) and
156172
callback function (actual Python function - also a ctypes wrapper).
157173
*/
158-
EXPORT void Iterate(TCallback callback, char const ** eventNames, int numEventNames, int eventsLimit, bool compress_uid)
174+
EXPORT void Iterate(TCallback callback, char const ** eventNames, int numEventNames, int eventsLimit, uint8_t uid_format)
159175
{
160176
std::set<std::string> processKeys(eventNames, eventNames + numEventNames);
161177

162178
alohalytics::Processor(
163-
[&callback, &processKeys, &compress_uid](AlohalyticsIdServerEvent const * idEvent, AlohalyticsKeyEvent const * event)
179+
[&callback, &processKeys, &uid_format](AlohalyticsIdServerEvent const * idEvent, AlohalyticsKeyEvent const * event)
164180
{
165181
if (!processKeys.empty() && !processKeys.count(event->key))
166182
return;
@@ -174,7 +190,7 @@ EXPORT void Iterate(TCallback callback, char const ** eventNames, int numEventNa
174190

175191
try
176192
{
177-
userInfo.setUid(idEvent->id, compress_uid);
193+
userInfo.setUid(idEvent->id, uid_format);
178194
}
179195
catch (std::logic_error const & e)
180196
{

snippets/pyaloha/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__="0.1.1"
1+
__version__="0.1.2"

snippets/pyaloha/ccode.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ def __dumpdict__(self):
166166
) # key, event_time, user_info, data, data_len
167167

168168

169-
def iterate_events(stream_processor, events_limit, compress_uid=True):
169+
class UidFormat(object):
170+
RAW = 0
171+
PYLONG = 1
172+
173+
174+
def iterate_events(stream_processor, events_limit,
175+
uid_format=UidFormat.PYLONG):
170176
base_path = os.path.dirname(os.path.abspath(__file__))
171177
c_module = ctypes.cdll.LoadLibrary(
172178
os.path.join(base_path, 'iterate_events.so')
@@ -177,11 +183,11 @@ def iterate_events(stream_processor, events_limit, compress_uid=True):
177183
keylist_type = ctypes.c_char_p * len(use_keys)
178184

179185
callback = CCALLBACK
180-
if compress_uid is True:
186+
if uid_format is UidFormat.PYLONG:
181187
callback = COMPRESSED_UID_CCALLBACK
182188

183189
c_module.Iterate.argtypes = [
184-
callback, keylist_type, ctypes.c_int, ctypes.c_int, ctypes.c_bool
190+
callback, keylist_type, ctypes.c_int, ctypes.c_int, ctypes.c_byte
185191
]
186192
c_module.Iterate(
187193
callback(
@@ -190,5 +196,5 @@ def iterate_events(stream_processor, events_limit, compress_uid=True):
190196
keylist_type(*use_keys),
191197
len(use_keys),
192198
events_limit,
193-
compress_uid
199+
uid_format
194200
)

0 commit comments

Comments
 (0)