All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.clarussecure.proxy.protocol.plugins.pgsql.message.writer.PgsqlCloseMessageWriter Maven / Gradle / Ivy

The newest version!
package eu.clarussecure.proxy.protocol.plugins.pgsql.message.writer;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;

import eu.clarussecure.proxy.protocol.plugins.pgsql.message.PgsqlCloseMessage;
import io.netty.buffer.ByteBuf;

public class PgsqlCloseMessageWriter implements PgsqlMessageWriter {

    @Override
    public int contentSize(PgsqlCloseMessage msg) {
        // Get content size
        int size = Byte.BYTES;
        size += msg.getName().clen();
        return size;
    }

    @Override
    public Map offsets(PgsqlCloseMessage msg) {
        // Compute header size
        int headerSize = msg.getHeaderSize();
        // Compute buffer offsets
        int offset = headerSize;
        offset += Byte.BYTES;
        Map offsets = Collections.singletonMap(offset, msg.getName().getByteBuf());
        return offsets;
    }

    @Override
    public void writeContent(PgsqlCloseMessage msg, ByteBuf buffer) throws IOException {
        // Write code
        buffer.writeByte(msg.getCode());
        // Write name
        ByteBuf value = msg.getName().getByteBuf();
        writeBytes(buffer, value);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy