This question was originally referring to Google Cloud Messaging (GCM), but now it also applies to the new Firebase Cloud Messaging (FCM) that replaces GCM.
I would like to know how to calculate the size of a GCM payload when it contains a "notification" dictionary.
I have been trying the Google Cloud Messaging service for Android. Some parts of the documentation say you can send up to 4KB of data, and here it says "A notification message can have a maximum of 2kb payload".
Doing some tests I could send messages with the "data" payload filled with 4KB of data and the server accepted them without error as expected.
However, using the "notification" payload I found that I could send messages with more than 2KB of data and the server did not return error. I expected such messages would be too big.
I found that the "notification" payload shares the allowed 4KB with the "data" payload, but not in the same way. In the "data" payload, you can calculate the size by adding the size of the keys and values. The "notification" payload takes up more space than the size of the keys and values it contains.
How can I calculate in advance the size of a payload when it contains the "notification" dictionary?