Esempio n. 1
0
        public void WriteMessage(NatsOperation operation, IBufferWriter <byte> output)
        {
            var writer = new NatsWriter(output);

            switch (operation.OpId)
            {
            case NatsOperationId.PING:
                writer.WriteString("PING\r\n");
                break;

            case NatsOperationId.PONG:
                writer.WriteString("PONG\r\n");
                break;

            case NatsOperationId.PUB:
                WritePub(ref writer, (PubOperation)operation.Op);
                break;

            case NatsOperationId.SUB:
                WriteSub(ref writer, (SubOperation)operation.Op);
                break;

            case NatsOperationId.CONNECT:
                WriteConnect(ref writer, (ConnectOperation)operation.Op);
                break;
            }
            writer.Commit();
        }
Esempio n. 2
0
 private static void WriteSub(ref NatsWriter writer, SubOperation op)
 {
     writer.WriteString($"SUB {op.Subject}");
     if (!string.IsNullOrEmpty(op.QueueGroup))
     {
         writer.WriteString(" ");
         writer.WriteString(op.QueueGroup);
     }
     writer.WriteString(" ");
     writer.WriteString(op.Sid);
     writer.Write(CRLF);
 }
Esempio n. 3
0
 private static void WritePub(ref NatsWriter writer, PubOperation op)
 {
     writer.WriteString($"PUB {op.Subject} ");
     if (!string.IsNullOrEmpty(op.ReplyTo))
     {
         writer.WriteString(op.ReplyTo);
         writer.WriteString(" ");
     }
     writer.WriteInt(op.Data.Length);
     writer.Write(CRLF);
     writer.Write(op.Data.Span);
     writer.Write(CRLF);
 }
Esempio n. 4
0
 private static void WriteConnect(ref NatsWriter writer, ConnectOperation op)
 {
     writer.WriteString($"CONNECT ");
     writer.WriteJson(op);
     writer.Write(CRLF);
 }