// Path: src/main/java/com/github/pgasync/io/Decoder.java
// public interface Decoder<T extends Message> {
// 
//     /**
//      * @return Protocol message id
//      */
//     byte getMessageId();
// 
//     /**
//      * @return Decoded message
//      */
//     T read(ByteBuffer buffer, Charset encoding);
// 
// }
// 
// Path: src/main/java/com/github/pgasync/message/backend/NotificationResponse.java
// public class NotificationResponse implements Message {
// 
//     private final int backend;
//     private final String channel;
//     private final String payload;
// 
//     public NotificationResponse(int backend, String channel, String payload) {
//         this.backend = backend;
//         this.channel = channel;
//         this.payload = payload;
//     }
// 
//     public String getChannel() {
//         return channel;
//     }
// 
//     public String getPayload() {
//         return payload;
//     }
// }
// 
// Path: src/main/java/com/github/pgasync/io/IO.java
// public class IO {
// 
//     public static String getCString(ByteBuffer buffer, Charset charset) {
//         ByteArrayOutputStream readBuffer = new ByteArrayOutputStream(255);
//         for (int c = buffer.get(); c != 0; c = buffer.get()) {
//             readBuffer.write(c);
//         }
//         return new String(readBuffer.toByteArray(), charset);
//     }
// 
//     public static void putCString(ByteBuffer buffer, String value, Charset charset) {
//         if (!value.isEmpty()) {
//             buffer.put(value.getBytes(charset));
//         }
//         buffer.put((byte) 0);
//     }
// 
// }


import com.github.pgasync.io.Decoder;
import com.github.pgasync.message.backend.NotificationResponse;
import com.github.pgasync.io.IO;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
package com.github.pgasync.io.backend;



/**
 * See <a href="https://www.postgresql.org/docs/11/protocol-message-formats.html">Postgres message formats</a>
 *
 * <pre>
 * NotificationResponse (B)
 *  Byte1('A')
 *      Identifies the message as a notification response.
 *  Int32
 *      Length of message contents in bytes, including self.
 *  Int32
 *      The process ID of the notifying backend process.
 *  String
 *      The name of the channel that the notify has been raised on.
 *  String
 *      The "payload" string passed from the notifying process.
 * </pre>
 *
 * @author Antti Laisi
 */
public class NotificationResponseDecoder implements Decoder<NotificationResponse> {

    @Override
    public NotificationResponse read(ByteBuffer buffer, Charset encoding) {
// Path: src/main/java/com/github/pgasync/io/Decoder.java
// public interface Decoder<T extends Message> {
// 
//     /**
//      * @return Protocol message id
//      */
//     byte getMessageId();
// 
//     /**
//      * @return Decoded message
//      */
//     T read(ByteBuffer buffer, Charset encoding);
// 
// }
// 
// Path: src/main/java/com/github/pgasync/message/backend/NotificationResponse.java
// public class NotificationResponse implements Message {
// 
//     private final int backend;
//     private final String channel;
//     private final String payload;
// 
//     public NotificationResponse(int backend, String channel, String payload) {
//         this.backend = backend;
//         this.channel = channel;
//         this.payload = payload;
//     }
// 
//     public String getChannel() {
//         return channel;
//     }
// 
//     public String getPayload() {
//         return payload;
//     }
// }
// 
// Path: src/main/java/com/github/pgasync/io/IO.java
// public class IO {
// 
//     public static String getCString(ByteBuffer buffer, Charset charset) {
//         ByteArrayOutputStream readBuffer = new ByteArrayOutputStream(255);
//         for (int c = buffer.get(); c != 0; c = buffer.get()) {
//             readBuffer.write(c);
//         }
//         return new String(readBuffer.toByteArray(), charset);
//     }
// 
//     public static void putCString(ByteBuffer buffer, String value, Charset charset) {
//         if (!value.isEmpty()) {
//             buffer.put(value.getBytes(charset));
//         }
//         buffer.put((byte) 0);
//     }
// 
// }


// Path: src/main/java/com/github/pgasync/io/backend/NotificationResponseDecoder.java
import com.github.pgasync.io.Decoder;
import com.github.pgasync.message.backend.NotificationResponse;
import com.github.pgasync.io.IO;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;

package com.github.pgasync.io.backend;



/**
 * See <a href="https://www.postgresql.org/docs/11/protocol-message-formats.html">Postgres message formats</a>
 *
 * <pre>
 * NotificationResponse (B)
 *  Byte1('A')
 *      Identifies the message as a notification response.
 *  Int32
 *      Length of message contents in bytes, including self.
 *  Int32
 *      The process ID of the notifying backend process.
 *  String
 *      The name of the channel that the notify has been raised on.
 *  String
 *      The "payload" string passed from the notifying process.
 * </pre>
 *
 * @author Antti Laisi
 */
public class NotificationResponseDecoder implements Decoder<NotificationResponse> {

    @Override
    public NotificationResponse read(ByteBuffer buffer, Charset encoding) {
        return new NotificationResponse(buffer.getInt(), IO.getCString(buffer, encoding), IO.getCString(buffer, encoding));