0

I am trying to write a client library for NATS.io. According to the protocol here, \n\r is used to delimiting commands, payload, etc.

INFO {"server_id":"1ec445b504f4edfb4cf7927c707dd717","version":"0.6.6","go":"go1.4.2","host":"0.0.0.0","port":4222,"auth_required":false,"ssl_required":false,"max_payload":1048576}

My question is what if the payload contains \r\n? I couldn't find any information about how to escape \r\n. Should one read INFO until a valid JSON is received and not look for \r\n as delimiter?

Thanks for your time!

Ravi Teja Gudapati
  • 2,809
  • 2
  • 13
  • 16

1 Answers1

0

A subscribe message MSG always contains the length of the payload bytes. docu

Example

MSG FOO.BAR 9 11\r\nHello World\r\n

The payload are the 11 bytes after the first\r\n ---> Hello World

Example with \r\n in the payload

MSG FOO.BAR 9 11\r\nHello W\r\nld\r\n

The payload are the 11 bytes after the first\r\n ---> Hello W\r\nld

Markus R
  • 541
  • 1
  • 4
  • 6