Ipfs pubsub (pub / sub) howto send and interpret messages

From node B adding files to IPFS, I would like to transmit order to node A to pin it.
I am trying to use pubsub in order to do that.

  • NODE A is listening to CHANNEL, waiting for new PIN event: ipfs pubsub sub CHANNEL
  • NODE B after adding new file : ipfs pubsub pub CHANNEL PIN:QmNew_CID

My NODE A is receiving string, but I need a mean to interpret it…
I am using ipfs pubsub sub CHANNEL | while read -r -n 50 line
but every message must have the same length… Any bad communication will break it

Is there a way to send NewLine in pubsub?
If not, how could I split received messages another way?

I found I may use a special character to cut lines:
ipfs pubsub sub CHANNEL | tr “%” "\n"

You can also write use the --enc=json flag to get the raw json output. Note: the peer ID and the data are base64 encoded.