class Bind extends PGMessage {

    public static Bind loadFromPacket(byte[] packet) {
        PGProto proto = new PGProto(packet, 5);
        Bind bind = new Bind();
        bind.setPortal(proto.readNullStr());
        bind.setStatement(proto.readNullStr());
        int paramFormatIdCount = proto.readInt16();
        int[] paramFormatIds = new int[paramFormatIdCount];
        for (int i = 0; i < paramFormatIdCount; i++) {
            paramFormatIds[i] = proto.readInt16();
        }
        bind.setParamFormatIds(paramFormatIds);
        int paramCount = proto.readInt16();
        Param[] params = new Param[paramCount];
        for (int i = 0; i < paramCount; i++) {
            Param param = new Param();
            int paramLen = proto.readInt32();
            if (paramLen >= 0) {
                param.setParamVals(proto.readBytes(paramLen));
            }
            params[i] = param;
        }
        bind.setParams(params);
        int resultFormatCount = proto.readInt16();
        int[] resultFormatVals = new int[resultFormatCount];
        for (int i = 0; i < resultFormatCount; i++) {
            resultFormatVals[i] = proto.readInt16();
        }
        bind.setResultFormat(new ResultFormat(resultFormatVals));
        return bind;
    }

}