0

I'm writing a Symfony's Bundle to manage AWS SNS notifications sent by AWS SES.

I'm representing a Bounce object and for the moment I'm using constants:

/**
 * A Bounce Entity.
 *
 * @see http://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-contents.html#bounce-object
 */
class Bounce
{
    const TYPE_PERMANENT            = 'Permanent';
    const TYPE_PERM_GENERAL         = 'General';
    const TYPE_PERM_NOEMAIL         = 'NoEmail';
    const TYPE_PERM_SUPPRESSED      = 'Suppressed';

    const TYPE_TRANSIENT            = 'Transient';
    const TYPE_TRANS_GENERAL        = 'General';
    const TYPE_TRANS_BOXFULL        = 'MailboxFull';
    const TYPE_TRANS_TOOLARGE       = 'MessageTooLarge';
    const TYPE_TRANS_CONTREJECTED   = 'ContentRejected';
    const TYPE_TRANS_ATTACHREJECTED = 'AttachmentRejected';

    const TYPE_UNDETERMINED         = 'Undetermined';
    ...

Now, as those value will be written to the database, using strings increases a lot the space I've to use to save the notifications so I took at bitmasks but I've never used them

I've read something about bitmasks here on StackOverflow but I cannot apply to this concrete scenario what I read.

How can I use bitmasks to represent these constants? Is there a way, using bitmasks, to also "validate" the type and sub type of notification?

Aerendir
  • 6,152
  • 9
  • 55
  • 108
  • Do you understand what a bitmask is and how to declare one? – deceze Jul 27 '16 at 09:48
  • What do you mean asking me this? A bitmask is a value of 32 or 64 bits that stores true/false values... But why are you asking me this? My knowing stops here because I've read a lot of things but I've never dealt whit them and so I'm not sure how to apply the concepts to the concrete case. Can you help me? – Aerendir Jul 27 '16 at 09:55
  • I'm trying to suss out whether you need a basic explanation of how to operate with bitmasks, or whether you need specific help to apply this to your current situation. – deceze Jul 27 '16 at 09:56
  • I don't know well what I need. I know that bitmask may be used to do this kind of thing but this is the very first time I try, so a guidance may help me. – Aerendir Jul 27 '16 at 09:57
  • I need something like a starting point... :) – Aerendir Jul 27 '16 at 09:58
  • BTW, a bitmask is useful when *combinations* of values are needed; e.g. a bounce reason could be both "permanent" *and* "general". Is that the case? Or is each reason mutually exclusive? Then you're just looking at an *enum*, not a bitmask. – deceze Jul 27 '16 at 12:52
  • No, they are mutually exclusive. What do you mean by an `enum`? A simple integer with each status identified by an integer? – Aerendir Jul 27 '16 at 17:58
  • Mmm... I've took at this solution (for sure, simpler!) but I had hoped this were the right scenario to go deeper into the bitmask topic... Ok, it'll be the next time! :) Thank you for your guidance! – Aerendir Jul 28 '16 at 08:46

0 Answers0