How does firebase calculate the number of bytes in a Firebase Cloud Message

117 views
Skip to first unread message

Nils ANDRÉ-CHANG

unread,
May 29, 2023, 3:57:58 PM5/29/23
to Firebase Google Group
Hello,

Firebase cloud messaging has a 4000 bytes limit in the size of its messages. However, I am unable to figure out what firebase uses to calculate the length of its messages (And therefore how I would go about checking before sending a message whether it would be accepted or rejected).

In the following example, the Notification object is 3997 bytes and adding any other byte to it causes an error: https://gist.github.com/NilsIrl/71b7234a1910195a447f050a54c11dfc#file-just-body

But now if I also add the title attribute to the notification object, the following is 3980 bytes and adding any other byte causes an error: https://gist.github.com/NilsIrl/71b7234a1910195a447f050a54c11dfc#file-body-and-title.

The way I calculate the number of bytes is by counting the length of the minified serialized JSON object from '{' to '}'. That being said, I have tried adding whitespace and it does not make a difference, so that length is definetly not the over-the-wire JSON object length.

Also note that when both the body and the title are included it seems like if I add and remove an equal number of bytes from either of those attributes the length stays the same. But adding a byte to any of those attribute without balancing it out by removing a byte from the other attribute causes an error when subsequently sending the message.

Thanks,
Nils

PS This was originally posted on Stack Overflow but I was suggested to ask on here instead: https://stackoverflow.com/q/76344159/11748992
Reply all
Reply to author
Forward
0 new messages