The binary mask

Why using a binary mask?

It is used a bitmask in order to know which preferences the user has chosen. If you set one device per bit, when you have to check the option set by the user, you will only need to compare that option with the device mask.

For now, the Push Api only support 3 kind of target devices (emails, smartphones and chrome) so it is using 3 bits. In this case, it would be easy to know with an integer which option the user have set. The problem is, the more devices the Push Api supports, the more complexity to know in which devices the user wants to receive the Push.

Here are some examples in order to understand it:

  • With 2 devices you can remember the 4 integers of the preferences and you can know what preferences have set the user. In this case, the masks used are 01 and 10.
MaskIntegerTarget
000none
011email
102smartphone
113all devices
  • With 4 devices (a, b, c, d) there are 15 different options to be set and it would be harder to remember the integers, the easiest option you have is to set a list of constants in order to know the meaning of each number. Using a bitmap, you only have to remember the masks and the comparison with the option should be easier:
MaskIntegerTarget
00000none
00011a
00102b
01004c
10008d
01015only c and a
.........
110113only d, c and
.........
111115all devices

Current bitmask

Here is the actual bitmask that Push Api is using:

TargetMaskInteger
None0000
Email0011
Smartphones0102
Chrome1004
All devices1117